[Solved] AutoFire behavior?

jjtaylor

  • Posts: 40
Hey guys! On my Player ship I have a behavior named "On Key Press" and it's labelled as shoot. Its code is attached to this forum post. Then I have another behavior named "Fire Laser". I'm trying to make it so you can just hold down the shoot button and it will fire automatically at fixed rates. Every .2 seconds. Does anyone have any suggestions as to how to make this possible?

« Last Edit: June 02, 2013, 08:35:36 pm by jjtaylor »

rob1221

  • *
  • Posts: 9473
Change key pressed to key down and use a boolean with a timer.

if boolean
---trigger message
---set boolean to true
---do after 0.2 seconds
------set boolean to false

jjtaylor

  • Posts: 40
Thank you Rob! But I'm confused as to where to place this code. Do I place it on the "Fire Laser" behavior or do I create a behavior? Do I add it to the key pressed? Thanks again.

rob1221

  • *
  • Posts: 9473
Wrap it around the trigger event block.

jjtaylor

  • Posts: 40
Wrap it around the trigger event block.

I'm actually having a hard time trying to comprehend what you're instructing me to do. Is this what you're looking for:

- if self is alive
-- if boolean (Where is this block???) (The boolean block)
--- trigger event (Action to perform) in all behaviors for self
---- (the rest of the code you instructed)

Sorry for being such a pain... I'm rather new to the coding style of this program.

cloa513

  • Posts: 245
boolean is an attribute type- create an attribute with that type. If (boolean) means if it is true
If Not (boolean) means if it is false

Tuo

  • *
  • Posts: 2469
If you go into the StencylForge and check out my "Demo- Infinite Space Shooter", is has an option to toggle on/off autofire in the "Firing" events for the player actor. Then, you can see the coding firsthand.

(Just go into the StencylForge, into the games section, and search for "Demo-")
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

jjtaylor

  • Posts: 40
If you go into the StencylForge and check out my "Demo- Infinite Space Shooter", is has an option to toggle on/off autofire in the "Firing" events for the player actor. Then, you can see the coding firsthand.

(Just go into the StencylForge, into the games section, and search for "Demo-")

I tried to reproduce your code and I couldn't fix the code to my vertical space shooter. The bullet would fire and as I got farther right of the scene it would decrease. It was a rather odd glitch that I probably created. I decided that I just want my ship to just ALL THE TIME fire. You don't have to hold down a button in other words ;). Any suggestions? It's for a vertical space shooter so the bullet it firing up. Any tutorials... or behaviors?

Hey if you want to always fire without pressing the button you can edit the FIRE BULLET behavior that comes with stencyl. its very easy to do. select the actor that you want to always fire.

Next add the behavior fire bullet to the actor. once you do that click on edit behavior. so you can edit the fire bullet behavior. now all you need to do is create a always block next you need to look in to the attributes setters and look for a boolean called (set fire to) add that to the always block and set it to true . it should look like this. look all the way to the bottom its the always block

jjtaylor

  • Posts: 40
Hey if you want to always fire without pressing the button you can edit the FIRE BULLET behavior that comes with stencyl. its very easy to do. select the actor that you want to always fire.

Where is this behavior? I searched it up in the Forge and couldn't find it.

its not in forge just click on dashboard and then actor behaviors under logic. and look for fire bullet it comes default with stencyl.

jjtaylor

  • Posts: 40
its not in forge just click on dashboard and then actor behaviors under logic. and look for fire bullet it comes default with stencyl.

It's not in my behaviors at all actually :O.

Thats weird it comes as default,try this. Click on file, import resource, go to your c drive and find program files. Look for the stenyl folder, click on it and open it up. Next open the behavior folder. Next look for the control folder open that up. Next open the Actor folder and you should find the fire bullet behavior there click on it and it should load up into stencyl. if not i dont know what else to say.


Edit: if you made a folder called my behaviors then its not gonna be there. i think i see what the confusion is.

Open up the actor you want to add the fire bullet behavior. goto behaviors. then click add behavior. once it opens up click on the (ALL)tab. and it should show you all the behaviors you have. im assuming you created a My behavior folder like i did. so it will not be in there. You have to click on the (ALL) tab to find it. all of the Pre shipped behaviors should be there.

« Last Edit: June 02, 2013, 08:13:52 pm by therealistone2003 »

Tuo

  • *
  • Posts: 2469
Follow the fourth tutorial, here: http://www.stencyl.com/help/viewArticle/109

All you change is to take it out of "if mouse is down" (just put the entire the in "always" directly) and instead of doing the trig to set the velocity, set it to have a direction of 270 (up).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

jjtaylor

  • Posts: 40
Thats weird it comes as default,try this. Click on file, import resource, go to your c drive and find program files. Look for the stenyl folder, click on it and open it up. Next open the behavior folder. Next look for the control folder open that up. Next open the Actor folder and you should find the fire bullet behavior there click on it and it should load up into stencyl. if not i dont know what else to say.


Edit: if you made a folder called my behaviors then its not gonna be there. i think i see what the confusion is.

Open up the actor you want to add the fire bullet behavior. goto behaviors. then click add behavior. once it opens up click on the (ALL)tab. and it should show you all the behaviors you have. im assuming you created a My behavior folder like i did. so it will not be in there. You have to click on the (ALL) tab to find it. all of the Pre shipped behaviors should be there.

I added the behavior and everything worked perfectly! Thank you so much!