Dear Colleagues,
I have no idea why my scratch code doesn't work:
For one Sprite, I create a global numerical variable and load it with a random number between 1 and 10.
in the sequence I try to use this variable in a IF instruction (on the same Sprite or on the other) but, unfortunately it doesn't work.
I never run the TRUE condition of the IF...
thank's for any help or idea.
Offline
There is a probably a specific problem with your script. As ErnieParke asked, could you post your scripts. Our responses should be much more helpful if we have concrete code to deal with.
Offline
dimasrm wrote:
Hi, friends!
I put my script below. I appreciate your tips.when gf clicked set [myNumber v] to <pick random (1) to (10)> if <(myNumber) > (5)> say [BIG] else say [little] end
Okay, I think that I see the problem. Was your sprite showing when you ran this code?
Offline
dimasrm wrote:
ya, my sprite was showing...and always say "little" doesn't matter what is the value of myNumber..
This is strange; could you upload your project?
Offline
dimasrm wrote:
ya, my sprite was showing...and always say "little" doesn't matter what is the value of myNumber..
Did you check the value of myNumber, or did you just assume that it wasn't greater than 5?
Offline
dimasrm wrote:
ya, my sprite was showing...and always say "little" doesn't matter what is the value of myNumber..
Have it show the variable, then test. Like awesomeness321 said, you may need to check the variable.
Offline
I changed my code and it worked very well.
I put an If instruction like this:
if <<pick random 1 to 10> GREATER THAN <myNumber>>
and this solved my problem
before I was trying to put the result of <pick random 1 to 10> in a variable and it didn't work.
Thank very much to all...
Now I'm going to finish my project
Offline
But I still don't understand: Why didn't the first approach work? I really want to understand why I cannot generate a global variable and then use it for an if-statement. In particular, I would like to use it across different objects. Any ideas?
Offline
Cactus4u wrote:
But I still don't understand: Why didn't the first approach work? I really want to understand why I cannot generate a global variable and then use it for an if-statement. In particular, I would like to use it across different objects. Any ideas?
Well, I'm also curious at to what might've been causing this. One possibility is that they created two separate variables that look alike, but aren't. Therefore, when they used the variable, they're evaluating the wrong one, giving false results. Also, the other possibility is that something might've occurred during download, messing up a file or two.
Anyway, you should be able to use a global variable in your if statement without any problems. I don't see anything saying otherwise.
With regards,
ErnieParke
Offline
ErnieParke wrote:
Cactus4u wrote:
But I still don't understand: Why didn't the first approach work? I really want to understand why I cannot generate a global variable and then use it for an if-statement. In particular, I would like to use it across different objects. Any ideas?
Well, I'm also curious at to what might've been causing this. One possibility is that they created two separate variables that look alike, but aren't. Therefore, when they used the variable, they're evaluating the wrong one, giving false results. Also, the other possibility is that something might've occurred during download, messing up a file or two.
Anyway, you should be able to use a global variable in your if statement without any problems. I don't see anything saying otherwise.
With regards,
ErnieParke
The most likely reason is that the variable is changed and indexed in multiple sprites.
If you use the variable in more than one place, it may mess up your results.
Offline