Be a Supporter!

Attacking code problem

  • 423 Views
  • 12 Replies
New Topic Respond to this Topic
evilmutantmonkey
evilmutantmonkey
  • Member since: Dec. 19, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Attacking code problem 2009-03-19 00:09:03 Reply

ok, so, my dilema is, I am trying to do a simple bit of coding, which is turning out to be the most complicated problem I've ever had, I want it so when you press the space bar it will go to a frame I have labeled attack, this is my code

if (Key.isDown(Key.SPACE))
gotoAndStop("attack");

now... when I test this, it comes up with no errors, however, it will not do anything when I hit space, please, I need help, could someone please give me the code that will work, it will be greatly appreciated, and I will credit you in my special thanks section in the credits. P.S. this game is not going to be crappy game, this is actually going to be fun to play, and has a good chance of reaching at least a blue on newgrounds, possibly better.

RobertJ
RobertJ
  • Member since: Jan. 5, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Attacking code problem 2009-03-19 00:26:39 Reply

going to be crappy game, this is actually going to be fun to play, and has a good chance of reaching at
least a blue on newgrounds, possibly better.

Oh you just keep thinking that!

Also..

Is there a frame named "attack" >.>

if(Key.isDown(Key.SPACE)) {
_root.gotoAndStop("attack");
}

mmm.

BBS Signature
geohoundz55
geohoundz55
  • Member since: May. 31, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Attacking code problem 2009-03-19 00:30:36 Reply

the problem was pretty basic but the frame labeled "attack" where it it?
on the main timeline or inside of MC?

evilmutantmonkey
evilmutantmonkey
  • Member since: Dec. 19, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Attacking code problem 2009-03-19 01:02:36 Reply

At 3/19/09 12:30 AM, geohoundz55 wrote: the problem was pretty basic but the frame labeled "attack" where it it?
on the main timeline or inside of MC?

it is in the movie clip.

x33905
x33905
  • Member since: Feb. 6, 2006
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Attacking code problem 2009-03-19 01:09:38 Reply

If you've got other code that sends it to another frame when the spacebar isn't down, this code will only be able to send it to the first frame of the attack animation (which if its the same as the "not attacking" animation it will appear to do nothing". Put a trace in there to make sure that the code is being executed at all.

digitalgenre
digitalgenre
  • Member since: Mar. 9, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Attacking code problem 2009-03-19 01:58:23 Reply

At 3/19/09 12:09 AM, evilmutantmonkey wrote:

'turning out to be the most complicated problem I've ever had' ???

if (Key.isDown(Key.SPACE))
gotoAndStop("attack");

YOU NEED CURLY BRACKETS e.g. '{' & '}'

if (Key.isDown(Key.SPACE)){
gotoAndStop("attack");
}

kiwi-kiwi
kiwi-kiwi
  • Member since: Mar. 6, 2009
  • Offline.
Forum Stats
Member
Level 09
Programmer
Response to Attacking code problem 2009-03-19 02:42:50 Reply

I don't know maybe it's because of the Stop in gotoAndStop. Try changing that to Play, I mean like gotoAndPlay.

kiwi-kiwi
kiwi-kiwi
  • Member since: Mar. 6, 2009
  • Offline.
Forum Stats
Member
Level 09
Programmer
Response to Attacking code problem 2009-03-19 02:59:43 Reply

At 3/19/09 01:58 AM, digitalgenre wrote:
YOU NEED CURLY BRACKETS e.g. '{' & '}'

if (Key.isDown(Key.SPACE)){
gotoAndStop("attack");
}

No you don't :P. {} Tell flash to execute everything between the brackets, if they don't exist, flash will run just the first statement after the if when the condition evaluates to true and will continue normally after that.

Example:

if (0)
trace("nothing");
trace("something");
//traces something
if (0)
{
   trace("nothing");
   trace("something");
}
//no output

P.S. sorry for the double post

evilmutantmonkey
evilmutantmonkey
  • Member since: Dec. 19, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Attacking code problem 2009-03-19 09:51:50 Reply

At 3/19/09 02:59 AM, kiwi-kiwi wrote:
At 3/19/09 01:58 AM, digitalgenre wrote:
YOU NEED CURLY BRACKETS e.g. '{' & '}'

if (Key.isDown(Key.SPACE)){
gotoAndStop("attack");
}


Example:

if (0)
trace("nothing");
trace("something");
//traces something

if (0)
{
trace("nothing");
trace("something");
}

I tried that, it did the trace, however, it will not do the gotoandstop, and I've tried the play, also, brackets did not make a difference..

Cojones893
Cojones893
  • Member since: Mar. 9, 2003
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to Attacking code problem 2009-03-19 09:55:32 Reply

Is that all you have is an if statement? You need to run it each time you want to check. You can do an onEnterFrame or a timer.

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Attacking code problem 2009-03-19 15:01:18 Reply

five us ALL your code for that mc/timeline. tell us where its placed, and what the mc istance name is of the thing your changing


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

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Attacking code problem 2009-03-20 07:43:36 Reply

onClipEvent(enterFrame){
	if (Key.isDown(Key.SPACE)){
		gotoAndStop("attack");
	}
}

- - Flash - Music - Images - -

BBS Signature
PanzyFace
PanzyFace
  • Member since: Jan. 11, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Attacking code problem 2009-03-20 08:05:20 Reply

I think what you're missing is this:

if (Key.isDown(Key.SPACE))
_root.character.gotoAndStop("attack");
}

If ur using 3.0, i dont know if its the same, im still using 2.0.
But replace character with the instance name of the movie clip and there u go.


Love me, hate me, y'know you wana bake me.

BBS Signature