Be a Supporter!

2 simple questions for AS 2.0

  • 299 Views
  • 11 Replies
New Topic Respond to this Topic
MrMojoRisin5
MrMojoRisin5
  • Member since: Jun. 21, 2011
  • Offline.
Forum Stats
Member
Level 12
Programmer
2 simple questions for AS 2.0 2011-07-01 03:54:47 Reply

1.I need to limit my "ammo" variable, so it can't go below zero.
2.How can I put a key code (e.x. key code for M = 77) in a "on(keyPressed)" command?

Please help.


-Got to keep on risin'...
-Check out FlashFrame
-Check out my YouTube channel and my blog

BBS Signature
DimebagRip32
DimebagRip32
  • Member since: Oct. 13, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to 2 simple questions for AS 2.0 2011-07-01 03:56:56 Reply

At 7/1/11 03:54 AM, MrMojoRisin5 wrote: 1.I need to limit my "ammo" variable, so it can't go below zero.
2.How can I put a key code (e.x. key code for M = 77) in a "on(keyPressed)" command?

Please help.

Explain what you want to do with the keycode more?

Secretmapper
Secretmapper
  • Member since: Nov. 25, 2010
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to 2 simple questions for AS 2.0 2011-07-01 03:57:18 Reply

At 7/1/11 03:54 AM, MrMojoRisin5 wrote: 1.I need to limit my "ammo" variable, so it can't go below zero.
2.How can I put a key code (e.x. key code for M = 77) in a "on(keyPressed)" command?

Please help.

You can't limit your ammo variable. Well, actually you can, but limiting the ammo variable will cause problems. What you would want to do is to change the script that decreases ammo to check that your variable is more than 0. For example:

If ammo variable is more than 0
Shoot
else
Don't do anything.

MrMojoRisin5
MrMojoRisin5
  • Member since: Jun. 21, 2011
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to 2 simple questions for AS 2.0 2011-07-01 04:32:15 Reply

At 7/1/11 03:56 AM, DimebagRip32 wrote:
Explain what you want to do with the keycode more?

I want to disable and enable sound. I have a MC with 2 frames. In frame 1, the sound volume is 100 and in frame 2 it is 0. I 've added one button on each frame with the code:

on(keyPress /*need code here*/ ){
nextFrame();
}

and on the second frame:

on(keyPress /*need code here*/ ){
prevFrame();
}


-Got to keep on risin'...
-Check out FlashFrame
-Check out my YouTube channel and my blog

BBS Signature
MrMojoRisin5
MrMojoRisin5
  • Member since: Jun. 21, 2011
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to 2 simple questions for AS 2.0 2011-07-01 04:37:10 Reply

At 7/1/11 03:57 AM, Secretmapper wrote: You can't limit your ammo variable. Well, actually you can, but limiting the ammo variable will cause problems. What you would want to do is to change the script that decreases ammo to check that your variable is more than 0. For example:

If ammo variable is more than 0
Shoot
else
Don't do anything.

Well, can you explain it more simply to me?
P.S.: I 've added in the "crosshair" MC the code:

onClipEvent(mouseDown){
_root.ammo --;
}

onClipEvent(enterFrame){
if(_root.ammo < 0){
_root.gotoAndPlay("Lost", 1);
}
}


-Got to keep on risin'...
-Check out FlashFrame
-Check out my YouTube channel and my blog

BBS Signature
MrMojoRisin5
MrMojoRisin5
  • Member since: Jun. 21, 2011
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to 2 simple questions for AS 2.0 2011-07-01 06:18:29 Reply

Could someone please help?


-Got to keep on risin'...
-Check out FlashFrame
-Check out my YouTube channel and my blog

BBS Signature
Sandremss128
Sandremss128
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Supporter
Level 11
Programmer
Response to 2 simple questions for AS 2.0 2011-07-01 07:56:57 Reply

learn actionscript, then ask questions if they are sill there.

MrMojoRisin5
MrMojoRisin5
  • Member since: Jun. 21, 2011
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to 2 simple questions for AS 2.0 2011-07-01 09:26:37 Reply

At 7/1/11 07:56 AM, Sandremss128 wrote: learn actionscript, then ask questions if they are sill there.

Well, I 'm asking questions so I can learn ActionScript.


-Got to keep on risin'...
-Check out FlashFrame
-Check out my YouTube channel and my blog

BBS Signature
HowardWimshurst
HowardWimshurst
  • Member since: Apr. 20, 2011
  • Offline.
Forum Stats
Supporter
Level 05
Animator
Response to 2 simple questions for AS 2.0 2011-07-01 11:07:26 Reply

can i ask a quick question?
what symbol is used to apply a function to two or more intance names? e.g if want this to apply to the instance named "ground" and to the instance named "block" at the same time.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to 2 simple questions for AS 2.0 2011-07-01 11:27:03 Reply

Jesus, either it's a bad couple of days or this forum is deteriorating.

Why isn't anyone answering the questions?

At 7/1/11 03:54 AM, MrMojoRisin5 wrote: 1.I need to limit my "ammo" variable, so it can't go below zero.

Just use a simple if statement to check, but I do agree with DimebagRip32.

if(ammo <= 0){
ammo = 0
}
2.How can I put a key code (e.x. key code for M = 77) in a "on(keyPressed)" command?

You don't. You make a keyDown check.

if(Key.isDown(77)){
//Your code hre
}

Of course, since this is just an if statement and not an event listener, you'd need to put this code in an enterFrame event. Whereas, with AS3, you'd just add the keyDown listener and work with that.

At 7/1/11 11:07 AM, terabiter wrote: can i ask a quick question?
what symbol is used to apply a function to two or more intance names? e.g if want this to apply to the instance named "ground" and to the instance named "block" at the same time.

You should make your own thread if you have a question that is irrelevant to the current thread, otherwise that'd be derailing the thread.

As for your question, if you want to apply code to more than one symbol, then just stick all these symbols into an array, loop through that and apply the code. If you're still new to actionscript, look up "arrays" and "for loops".

MrMojoRisin5
MrMojoRisin5
  • Member since: Jun. 21, 2011
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to 2 simple questions for AS 2.0 2011-07-01 12:27:03 Reply

At 7/1/11 11:27 AM, 4urentertainment wrote: Jesus, either it's a bad couple of days or this forum is deteriorating.

Why isn't anyone answering the questions?

Thank you very much for answering my questions.


-Got to keep on risin'...
-Check out FlashFrame
-Check out my YouTube channel and my blog

BBS Signature