Reset level
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
I'm making a game, with some levels.
Now when one level is finished, it follows this code: gotoAndStop(2);
Then it gets at frame two, but then the sound of the previous level and all the movieclips are still there, how can I reset them, or anything? (It's a lot of work to removeMovieClip them all..)
- ThePeasant
-
ThePeasant
- Member since: Aug. 30, 2007
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 3/23/09 01:05 PM, dudejonne wrote: I'm making a game, with some levels.
Now when one level is finished, it follows this code: gotoAndStop(2);
Then it gets at frame two, but then the sound of the previous level and all the movieclips are still there, how can I reset them, or anything? (It's a lot of work to removeMovieClip them all..)
Depending on what you want to delete, you can use a for loop. If you need to get rid of everything then you can use this
for(var i in _root){
_root[i].swapDepths(789);
_root[i].removeMovieClip();
}
To stop sounds, use stopAllSounds();
Obviously both of these need to be run before you initiate stuff for the second level
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
Thanks! Thats somuch easier! :)
So something like:
[code]
if(levelfinish==true) {
for(var i in _root){
_root[i].swapDepths(789);
_root[i].removeMovieClip();
}
stopAllSounds();
gotoAndStop(2)
}
[/code]
Will do it? This is AS2 rights? ( with that 'var i in' stuff )
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 3/23/09 01:18 PM, dudejonne wrote: Will do it? This is AS2 rights? ( with that 'var i in' stuff )
Yes. For the record the HTML you may use in a message is listed to the left of the text box (<a>, <strong>, <em>, <ins>, <code>).
Also, in an if statement you never need to use true or false, because the if statement is only checking for true or false anyway. If I have a variable named "hi" that is Boolean (true/false) and that is set to true the following code:
if(hi){
// do stuff
}
Will be the same as:
if(hi==true){
// do stuff
}
because hi is true on it's own. Likewise to check for "false" you use the ! operator like so:
if(!hi){
// do stuff if hi is false
}
So, when you're checking something like.. if score = 10, the following statement will be used:
if(score==10)
Because the statement "score==10" returns true if score = 10. It's kinda hard to explain statements and how they work, even though it's quite simple.
Sup, bitches :)
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
I get it. I know it, but I forget to use it. Thanks ppl :)
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
Does this also removes the variables that are used or declared on that frame?
- TheSongSalad
-
TheSongSalad
- Member since: Jan. 17, 2009
- Offline.
-
- Forum Stats
- Member
- Level 19
- Audiophile
At 3/24/09 01:20 PM, dudejonne wrote: Does this also removes the variables that are used or declared on that frame?
no, it wouldn't do that.
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
Hmm then there's an other problem..
If I declare a variable, like in this case: var score = 0;
And then in the next frame I have as code: scorefield.text = score;
That should work right?
- TheSongSalad
-
TheSongSalad
- Member since: Jan. 17, 2009
- Offline.
-
- Forum Stats
- Member
- Level 19
- Audiophile
yeah. or you could just make the text box dynamic and have its var be score.
- dudejonne
-
dudejonne
- Member since: Sep. 13, 2008
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
It ís a dynamic textfield with instance name thing scorefield.
scorefield.text= score;
Wow, I did a major discovery :D
On a previous frame I also had a textbox with name scorefield, so this one doesn't works :p
Now its named scorefield2 andit works.
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 3/24/09 02:33 PM, dudejonne wrote: It ís a dynamic textfield with instance name thing scorefield.
scorefield.text= score;
Wow, I did a major discovery :D
On a previous frame I also had a textbox with name scorefield, so this one doesn't works :p
Now its named scorefield2 andit works.
It depends where you declare the .text. The var is constantly updated, the .text is a one-off - so if you declare scorefield.text= score; before the dynamic textbox with the instance name scorefield exists, it won't show the text you send (once it DOES exist)


