dcsimg
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: variable == 0 gotoAndPlay not working

  1. #1
    Banned
    Join Date
    Sep 2005
    Posts
    2

    variable == 0 gotoAndPlay not working

    Hi im making my first flash game and i have two major part of code which I need to figure out
    this being the first one

    what i need it that when the variable money (for intance) reaches 0 or below for the timeline to advance to another frame
    If(_root.money == 0) {
    gotoAndPlay(2); or gotoAndPlay("gameover");
    }

    but its not working =(

    I think it might be because of the way I ahve my variables declared but, it could be any number of things as i said this is my first time programing a game.

    the way my code reads currently is on frame 1, on layer actions



    stop();

    var bad = 0;
    var time = 60;
    var money = 100;

    if(_root.money == 0){
    gotoAndPlay("gameover");
    }

    im gonna include my fla incase you wanna take a look to see exactly what im trying to do.
    Attached Files Attached Files

  2. #2
    absent
    Join Date
    Aug 2000
    Location
    NB, Canada
    Posts
    155
    You might try equal to or less than:

    if (_root.money <= 0){
    gotoAndPlay("gameover");
    }
    - g

  3. #3
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    your piece of code is located on the first frame of the main timeline and is executed only once. when it is executed, "money" has a value of 100. then this script is never executed again (unless you enter the first frame again, which you don't).
    you can do this on the main timeline:

    Code:
    function checkMoney(){
       if (money==0){
           clearInterval(myInterval);
           gotoAndStop(2);
       }
    }
    
    myInterval=setInterval(checkMoney,100);
    thus you have a function that is called every 100 milliseconds, so it can get the latest value of "money"...
    Please sign here

  4. #4
    Banned
    Join Date
    Sep 2005
    Posts
    2
    Thank you! it works! your the man. i hope youll know somethign about my next issue, but im gonna take a stab at it myself first =). it involves duplicate movie clips and changing frame when a number of movie clip intances are on the stage

  5. #5
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    glad to help...
    for checking how many MCs are on stage you could use, for example, either a counter variable or a for...in loop
    Please sign here

  6. #6
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    I don't find a "delete post" option...
    Last edited by theTick; 09-30-2005 at 02:42 AM. Reason: the post that I replied to has been deleted
    Please sign here

  7. #7
    Banned
    Join Date
    Sep 2005
    Posts
    5
    Quote Originally Posted by theTick
    well, psb, if you look at that game once again, you'll realize that "money" actually decreases when you pull the wrong small box on top of the big box.
    dude what are you talking about how is that the "wrong" box?

    I think that your reply is rather confusing...anyway, the problem has been solved already, so what's your point?
    my reply is confusing? all i said was thanks and that i have another problem that i have another problem that i have to deal with. my point is just to throw out the idea of what i was working on and someone might say oh you gonna be dealing with taht so you should check out this thread or that tutorial.

    i still appreciate your help but, i dont really understand your criticism

  8. #8
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    hi goddammf2: I think this is a misunderstanding. this is no criticism of you, instead I reacted on a reply by someone called "psb" who replied in a quite confusing way (plus, he/she obviously hadn't read the thread all way through). it seems that by the time you got back to this thread, psb had already removed his/her reply. so now it might look like I'm critizing you, but this is not the case. since psb has removed the reply, I'll remove mine.
    that reply wasn't at all aimed at you, goddammf2, so no hard feelings, I hope...
    Please sign here

  9. #9
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    sorry guys thats confusion happen because of me. Actually i was trying to reply to the question post by u goddammf2. but I miss the reply posted by "theTick" and removed my post after seeing the answer given by "theTick". hopefully u guys can understand that

  10. #10
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    well, never mind...hope you don't take my rather harsh reply too seriously...
    and now for something completely different: psb, where did you find the button that deletes a post? I can't find one, no matter how close I look at the screen when I edit my post...
    Please sign here

  11. #11
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    well the moment when u post ur reply u will see 2 button in lower left corner 1: edit and 2:quote. press the edit button and next screen will show u different option and among those there is one option "delete message" hope u will get this button this time and yea i mind the way u write back but within few minitues i realise what difference does ur reply makes to me. but now i am fine as u realise urself that u used some harsh word

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center