This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-06-10 13:28:35

DrSuper
Scratcher
Registered: 2008-06-10
Posts: 37

SOS for IF Statement with a Long List of ORed Values

I would like to write an IF statement with a long list of ORed values e.g
If Something = 1 or 2 or ...or 1023
Is there an easy way of doing this? I have tried nested OR statements  but this becomes very slow after a few ORs and scrolling to the right is no fun. I nearly a list of hundred values each time.

Offline

 

#2 2008-06-10 13:55:03

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: SOS for IF Statement with a Long List of ORed Values

You could simply have the if statements sequentially, without needing "Or", by having the triggered action be a broadcast.

If X=1
- Broadcast "Doaction
- Stop Script
If X=2
- Broadcast "Doaction
- Stop Script
If X=3
- Broadcast "Doaction
- Stop Script

You could also cover multiple values with one statement.  For example, this one will trigger for 1,2,3,4,5,6,7,8 and 9.

If x>0 and X<10
- Do action


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2008-06-10 16:01:00

DrSuper
Scratcher
Registered: 2008-06-10
Posts: 37

Re: SOS for IF Statement with a Long List of ORed Values

Thanks Mayham but i was hoping for an IN statement like in SQL
If Something IN (1,2,3..) (May be they will add this at some point.
My problem is that I have hundred a 1023 values grouped into some 34 groups and the numbers are not sequential either so I can not use the second suggestion.
I have also tried the non nested route and by grouping them by 5 etc. not to repeat the couple of lines every time. Even with a 130 or so in the processing is slowing down and I am afraid I might choke it with the 1023 if conditions nested or not..

Offline

 

#4 2008-06-11 17:37:51

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: SOS for IF Statement with a Long List of ORed Values

I'm intrigued - what exactly is this project doing with all these variables?


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#5 2008-06-11 21:59:10

DrSuper
Scratcher
Registered: 2008-06-10
Posts: 37

Re: SOS for IF Statement with a Long List of ORed Values

Dear Mayham,
Check out http://www.galaxy.gmu.edu/~drsuper/product.html#I I had a version of this game written fro me in VB and since last week that I discovered Scratch I am doing it now in Scratch my self. Essentially I have identified each state of the Super Board by 1 and 0 so I have 1023 states and I need to tell the board to go from each state to a next state (I know the full strategy) The game was published by Creative Publications but it is discontinued;=<

When I put over 300 if statements in the Stages Scratch chokes but I have distributed them over the ten board triangle now and it seems to hold up. I am not done yet.
I looked at your work and it looks great. I got to learn to do animations.

My ambition is to develop a full curriculum in games for elementary and middle school Math in Scratch and for OLPC.
Regards
Behrouz Aghevli
a.k.a. Dr. Super
baghevli2@worldbank.org

Offline

 

Board footer