Attacking code problem
- evilmutantmonkey
-
evilmutantmonkey
- Member since: Dec. 19, 2006
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
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
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.
- geohoundz55
-
geohoundz55
- Member since: May. 31, 2007
- Offline.
-
- Forum Stats
- Member
- Level 10
- Blank Slate
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
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
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
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
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
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
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
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
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
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
onClipEvent(enterFrame){
if (Key.isDown(Key.SPACE)){
gotoAndStop("attack");
}
} - PanzyFace
-
PanzyFace
- Member since: Jan. 11, 2009
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
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.




