Forum Topic: gotoAndPlay doesnt work.

(162 views • 20 replies)

This topic is 1 page long.

<< < > >>
None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 06:23 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

Okay, I'm using CS3, and I'm trying to make a turn based fight engine. So i have 3 frames, on the first one i have it setting the enemy hp and the player hp. Then on the next frame i have it setting the attack type button invisible and the attack button visible. On the frame i have my enemy and the player, and the attack button. The actions on the attack button are telling it to make the attack options visible on release. Then on the attack option i have it telling the player MC to go to the frame that corresponds to the attack type. After the player attack, it goes to the 3rd frame, which is the enemy's turn. On the frame i have it making a variable with a random value between 0 and 1. On the enemy MC i have it telling it to this.gotoAndPlay("punch"); if the random value is 0, and this.gotoAndPlay("kick"); if the random value is 1. On the enemy i have the frames named "punch" and "kick". The problem is that it doesnt work.

TL;DR. On a frame i have the code

stop();
_root.enematk = random(1);

And on my MC i have

onClipEvent (enterFrame) {
	if(_root.enematk == 0){
		this.gotoAndPlay("punch");
	}
	if(_root.enematk == 1){
		this.gotoAndPlay("kick");
	}
}

Inside my MC i have frames named "punch" and "kick". It just doesnt work though. If i replace the names with the numbers, it still doesnt work. If i replace "gotoAndPlay();" with "play();" it works, but it can only do one attack. Help?

mmm.

BBS Signature

None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 2/26/09 06:34 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,870

random and Math.random generate a random number between 0 and 1, it will never be 0 or 1 exactly (super small chance)

Try rounding the answer

_root.whateveritwas = Math.round(random(1));

Or, just do this

_root.whateveritwas = Math.round(Math.random()*1);

Motto: Continue with what your doing and you will succeed!
Newgrounds: Where all us freaks go.

BBS Signature

None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 06:52 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

At 2/26/09 06:34 PM, BillysProgrammer wrote: random and Math.random generate a random number between 0 and 1, it will never be 0 or 1 exactly (super small chance)

Are you sure? I remember "random(#)" working without rounding the answer.

Try rounding the answer

_root.whateveritwas = Math.round(random(1));

Or, just do this

_root.whateveritwas = Math.round(Math.random()*1);

And it still doesn't work, i tried placing the variable on the frame before, i tried lots of things, and it still doesn't work. =\ if i pm you the FLA would you be able to help? If that isn't too much trouble, of course.

mmm.

BBS Signature

None

LostVoices

Reply To Post Reply & Quote

Posted at: 2/26/09 06:58 PM

LostVoices LIGHT LEVEL 07

Sign-Up: 03/09/06

Posts: 1,889

try this on the frame

stop();
enematk = random(1);

awww


None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 07:00 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

At 2/26/09 06:58 PM, LostVoices wrote: try this on the frame

stop();
enematk = random(1);

That's exactly what i had before, so obviously..it doesn't work.
I don't know why, this makes no sense!

mmm.

BBS Signature

None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 2/26/09 07:01 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,870

Robert, it doesnt

Look it up lol, Ive been doing this for a while, I KNOW :P, cause I have no life and research pointless shit lol Jks (or is it???) lol

Motto: Continue with what your doing and you will succeed!
Newgrounds: Where all us freaks go.

BBS Signature

None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 07:02 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

At 2/26/09 07:01 PM, BillysProgrammer wrote: Robert, it doesnt

Look it up lol, Ive been doing this for a while, I KNOW :P, cause I have no life and research pointless shit lol Jks (or is it???) lol

Yeah it makes sense, i believe you, just, it still doesn't work. =\.

mmm.

BBS Signature

None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 2/26/09 07:06 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,870

Well, make sure that the variable is on the main timeline so it becomes global to the frame. Or, you can post the fla using http://www.spamtheweb.com/ul and I can take a look at it and post what I find (with comments)

Motto: Continue with what your doing and you will succeed!
Newgrounds: Where all us freaks go.

BBS Signature

None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 09:09 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

Thanks for all your help billy, but it still ain't working.

mmm.

BBS Signature

None

XceeD

Reply To Post Reply & Quote

Posted at: 2/26/09 09:14 PM

XceeD NEUTRAL LEVEL 12

Sign-Up: 08/15/06

Posts: 101

I think the problem may be that random(1) always generates 0. Try random(2)?

random(n) returns back a random number in this interval: 0<n


None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 09:17 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

At 2/26/09 09:14 PM, XceeD wrote: I think the problem may be that random(1) always generates 0. Try random(2)?

random(n) returns back a random number in this interval: 0<n

I was thinking this but then i made a text box with the var name "enematk" and it always came out 0 or 1, so that wasn't the problem. And if it was, it would still do something because 0 is for punch and 1 is for kick. Ya see?

mmm.

BBS Signature

None

XceeD

Reply To Post Reply & Quote

Posted at: 2/26/09 09:22 PM

XceeD NEUTRAL LEVEL 12

Sign-Up: 08/15/06

Posts: 101

Well, I just ran a small simulation, and out of 100 times I asked it to do random(1), it came out as 0.

for(i=0;i<100;i++)
{
trace(random(1)==1)
}

Try random(2).

This code got a lot of trues:
for(i=0;i<100;i++)
{
trace(random(2)==1)
}


None

Blain-The-Pain

Reply To Post Reply & Quote

Posted at: 2/26/09 09:22 PM

Blain-The-Pain DARK LEVEL 11

Sign-Up: 09/29/07

Posts: 467

I'm sure this isn't the problem, but just in case, are you sure you're using AS2? You did say you're using CS3, but you didn't specify the Actionscript version.

Good luck finding the answer.

f


None

XceeD

Reply To Post Reply & Quote

Posted at: 2/26/09 09:24 PM

XceeD NEUTRAL LEVEL 12

Sign-Up: 08/15/06

Posts: 101

Woops, sorry for double post... I just read the last line of your last post...

Well, the only thing I can think of is that your frames weren't labelled correctly. Double check labels.


None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 09:28 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

At 2/26/09 09:24 PM, XceeD wrote: Woops, sorry for double post... I just read the last line of your last post...

Well, the only thing I can think of is that your frames weren't labelled correctly. Double check labels.

I tried putting frame numbers instead of lables and blah blah blah it still doesnt work, so im restarting from a blank canvas to see if it was some wierd flash bug.

mmm.

BBS Signature

None

LostVoices

Reply To Post Reply & Quote

Posted at: 2/26/09 09:29 PM

LostVoices LIGHT LEVEL 07

Sign-Up: 03/09/06

Posts: 1,889

try telling it to gotoAndPlay() the frame number instead of label see if that makes a difference if it does then its the labels that have a problem

awww


None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 10:15 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

I tried putting frame numbers instead of lables and blah blah blah it still doesnt work, so im restarting from a blank canvas to see if it was some wierd flash bug.

See that? Thats what i said before your post LostVoices. Take the time to read through the whole thread, dumb ass.

mmm.

BBS Signature

None

K-Guare

Reply To Post Reply & Quote

Posted at: 2/26/09 10:59 PM

K-Guare FAB LEVEL 16

Sign-Up: 05/23/08

Posts: 2,322

var enematk:Number = Math.round(Math.random());

I know for a fact that produces either a 1 or a zero.
Use that, and if it still doesn't work post more information.
If it works when you use play();,
but not when you use gotoAndPlay()
The problem is most likely the way the timeline is set up.

Give it a shot, kiddo. :]

BBS Signature

None

RobertJ

Reply To Post Reply & Quote

Posted at: 2/26/09 11:02 PM

RobertJ FAB LEVEL 07

Sign-Up: 01/05/09

Posts: 245

At 2/26/09 10:59 PM, K-Guare wrote: var enematk:Number = Math.round(Math.random());

I know for a fact that produces either a 1 or a zero.
Use that, and if it still doesn't work post more information.
If it works when you use play();,
but not when you use gotoAndPlay()
The problem is most likely the way the timeline is set up.

Give it a shot, kiddo. :]

It's probably the way the timeline is set up, cause with "random(1)" produces exactly 0 or 1, i tested it with a dynamic var box. Anyway i restarted to try again :D.

Thanks for the help KG
Stay fab!

mmm.

BBS Signature

None

K-Guare

Reply To Post Reply & Quote

Posted at: 2/26/09 11:08 PM

K-Guare FAB LEVEL 16

Sign-Up: 05/23/08

Posts: 2,322

At 2/26/09 11:02 PM, RobertJ wrote: It's probably the way the timeline is set up, cause with "random(1)" produces exactly 0 or 1

Not true. :]
Test this here code out:

for(var i:Number = 0; i<100; i++) {
	trace(random(1));
}

0 Every single time.
Now try it using random(2),

for(var i:Number = 0; i<100; i++) {
	trace(random(2));
}

Now that's more like it.
I'm guessing the random() method does a floor round?
Not sure, I haven't really used it before.
Which is fine because it's been depreciated since the
release of Math.random() in Flash Player 5.

i tested it with a dynamic var box. Anyway i restarted to try again :D.

K. :]

Thanks for the help KG
Stay fab!

You too, kiddo. :]
Wait! I haven't posted on there in forever!

Ahh i'll do that tomorrow.

</obvious_procrastination>
BBS Signature

None

Yambanshee

Reply To Post Reply & Quote

Posted at: 2/27/09 08:56 AM

Yambanshee DARK LEVEL 10

Sign-Up: 10/05/08

Posts: 1,436

im not quite sure how/waht your doing, but if my guess is correct try this=

onClipEvent(load){
var i:Boolean = false
}
onClipEvent (enterFrame) {
if(!i)
	if(_root.enematk == 0){
		this.gotoAndPlay("punch");
i = true;
	}
	if(_root.enematk == 1){
		this.gotoAndPlay("kick");
i =true;
	}
}
}

the bits i edited was using my AS2 knoledge, so it MIGHT need some turning into as3

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 10:53 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!