-
1 line of code - which loop to use?
Hi Guys,
Anyone know how say this in actionscript? -
//determine if any 'food' is left in the game. If not display flag to next level.
When randomNumberVariable % (modulus) timesTableVariable stops equaling 0 for any of the 20 spiders in the game set flagNextLevel._visible = true
I can't figure out which loop to use as a for loop hasn't worked so far... Maybe a do while ?
Any help greatly appreciated...
Mark
-
Not a lot of info.. anyway, i can always suggest a for loop.
a for loop should work if they're sequential (spiders0 - spiders1, etc.), a do while would crash flash. Each spider has a randomNumberVariable, named the same? Then use something in these lines:
Code:
for (i=0; i<spidersNumber; i++) {
this["spiders"+i].randomNumberVariable%path.timesTableVariable!=0?flagNextLevel._visible=true:flagNextLevel._visible=false;
}
-
Cheers for the prompt reply...
Right then a little more detail first. This is what I have already that branches depending on whether the number is a multiple of ran or not.
//still within Ladybird_mc.onEnterFrame determine if any 'food' is left in the game. If not display flag to go to next game level.
for (i=1; i<21; i++) {
if (_root['spider'+i].ran%tT==0){
trace('multiple =' + _root['spider'+i].ran)
}else{
trace ('not multiple');
}
What you've just posted looks like it might work but I don't quite understand the following syntax:
this["spiders"+i].randomNumberVariable%path.timesTableVariable!=0?f lagNextLevel._visible=true:flagNextLevel._visible= false;
Can you please clarify this for me as I've been looking in books all day
Thanks mate - brilliant for help so far...
-
ternary code is shorthand for an if/else:
statement1?statement2:statement3;
is like saying :
if (statement1) {
statement2;
} else {
statement3;
}
gparis
-
WOW thanks...
Cheers for this... actionscript has moved on a little since I first started using flash in version 4 but never had time to get proficient...
BTW - I like your tree menu... gonna have fun pulling that fla apart...
All the best...
-
flag displays when eat first spider
Hi again,
What's happening now is that the flag is displaying when you eat the first spider containing a random number that is a multiple of the times table selected. It needs to display when you eat the last one in the game - not the first. The problem being that I don't know how many there are.
Here is the code:
for (i=1; i<21; i++) {
_root['spider'+i].ran%tT!=0?flag._visible = true:flag._visible = false;
}
Thanks for your explanation of ternary code tho - will use this in future...
-
My Mistake - it kind of works...
My mistake... it sort of works although the flag still displays when there are multiples left to be eaten...
It is the closest code I've had so far so cheers.
Needs more testing but cheers...
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|