Flash8 [RESOLVED] Can my code work?
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [RESOLVED] Can my code work?

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    70

    resolved [RESOLVED] Can my code work?

    So here is my code:
    Code:
    on (release) {
    	if (laserdate == 0) {
    		laserdate += 1;
    		gotoAndPlay("laserchat1")or ("laserchat2") or ("laserchat3") or ("laserchat4") or ("laserchat5");
    	} else if (laserdate == 1) {
    		laserdate += 1;
    		gotoAndPlay("laserchat1")or ("laserchat2") or ("laserchat3") or ("laserchat4") or ("laserchat5");
    	} else if (laserdate == 2) {
    		gotoAndPlay("laserelse");
    	} else if (laserdate == 3) {
    		gotoAndPlay("laserelse");
    	} else if (laserdate == 4) {
    		laserdate += 1;
            gotoAndPlay("laserchat1")or ("laserchat2") or ("laserchat3") or ("laserchat4") or ("laserchat5");
    	} else if (laserdate == 5) {
    		gotoAndPlay("laserelse");
    	}
    }
    Can the 'or' in my code work? What I'm trying to do is have the player go to either of the chat frames. When I tested my code, it didn't go to the chat frames. How can I fix this?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    886
    Hi,

    You can do it like this if you wished, it picks a random number between 1/5 and then goes to that frame accordingly.

    PHP Code:
    on (release) {
        var 
    Jump:Number Math.floor(Math.random() * 5) + 1;
        
    trace(Jump);
        if (
    laserdate == 0)
        {
            
    laserdate += 1;
            
    gotoAndPlay("laserchat" Jump);
        }
        else if (
    laserdate == 1)
        {
            
    laserdate += 1;
            
    gotoAndPlay("laserchat" Jump);
        }
        else if (
    laserdate == 2)
        {
            
    gotoAndPlay("laserelse");
        }
        else if (
    laserdate == 3)
        {
            
    gotoAndPlay("laserelse");
        }
        else if (
    laserdate == 4)
        {
            
    laserdate += 1;
            
    gotoAndPlay("laserchat" Jump);
        }
        else if (
    laserdate == 5)
        {
            
    gotoAndPlay("laserelse");
        }

    I assume you have declared the laserdate variable somewhere , like so ish
    PHP Code:
    var laserdate:Number 0
    or you can shorten the whole lot down like so
    PHP Code:
    on (release) {
        var 
    Jump:Number Math.floor(Math.random() * 5) + 1;
        
    trace(Jump);
        if (
    laserdate == || laserdate == || laserdate == 4)
        {
            
    laserdate += 1;
            
    gotoAndPlay("laserchat" Jump);
        }
        else
        {
            
    gotoAndPlay("laserelse");
        }

    || is the syntax for or ,I believe
    Last edited by fruitbeard; 07-05-2013 at 03:19 PM.

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    70
    Thank you so much! It works, but when I tested my movie the output box displayed the number of the frame I went to. Will this affect my game when I publish it?

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    886
    Hi,

    Glad it worked, which did you use, the long or the short version?

    Anyway, the trace(Jump); will not show up in your published document, you can delete it or comment it out or leave it there, trace is useful for testing and debugging purposes.

  5. #5
    Member
    Join Date
    Jul 2012
    Posts
    70
    I used the longer version. Could you explain how the Jump coding works please? That way in the future I can edit/make my own codes and better understand them.

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    886
    Hi,

    The short one is probably better but never mind.

    var Jump: is a random number between 1 - 5, each time you click, it changes.
    all your key frames are called laserchat + number, apart from laserelse.
    so go to and play laserchat + jump(1-5), laserchat1, laserchat3.

  7. #7
    Member
    Join Date
    Jul 2012
    Posts
    70
    Thanks again!

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

Poll by Flashkit.com