-
[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?
-
.
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 == 0 || laserdate == 1 || 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.
-
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?
-
.
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.
-
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.
-
.
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.
-
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
|