|
|
|
#1 |
|
Junior Member
Join Date: Oct 2004
Posts: 5
|
Random guessing game - actionscript error
Hi, im new to these forums. I'm making a guessing game - when you press one of three buttons, this script executes:
The problem is that the player always wins. Where is the error? Last edited by jbum; 10-09-2004 at 03:12 PM. |
|
|
|
|
|
#2 |
|
Super Moderator
Join Date: Aug 2000
Location: Montréal
Posts: 13,430
|
Hi,
couple of mistakes in your code, specially the needed double eq. sign in if statement:
gparis
__________________
![]() AS 2.0 Forum Guidelines || Use P H P tags for code samples || Flash LiveDocs || AS 2.0 Language reference (CS4) |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
The problem is your use of a single equals sign in the if statement. There are two similar looking operators
= (assignment) == (equality) When you are testing for equality, such as in an if statement, you need to use the second one (which is two equal signs). Otherwise, it assumes you want to assign the value on the right side to the variable on the left side. Also, you should omit the semicolons after the if statement, they will cause it to execute incorrectly. It's if (cond) statement; or if (cond) { block; } not if (cond); statement; and not if (cond); { block } Here's are some rewrites of your code which simplifies some other things.
Simplification #1. Use the 'else' clause.
Simplification #2. Omit the variable.
Simplification #3. Use the random value to compute the frame number. This is clever, but not particularly easy to understand - I would probably use the previous method.
- Jim |
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Oct 2004
Posts: 5
|
Thank you so much!
You guys really helped a newbie out! |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|