help w/ shooting and reloading behavior

greybrid

  • Posts: 32
i've put together this behavior for shooting and reloading which seems to work until the time to reload comes. the player can shoot 6 times but then instead of waiting .1 seconds to 'reload' and get 6 more shots, the player can just shoot indefinitely because the 'pistol ammo' variable is not reset back to 6.

 i'm sure the method i've used is far from the most efficient one that could be used. i'd like to know if  this behavior is salvageable (and if so, how) or if i should scrap this pair of behaviors.

Update: so i've changed the behaviors a bit based on suggestions i've gotten in this thread and the result works better but my understanding of stencyl is very limited. now the player can shoot 6 times, then reload and shoot another 6 times but after that reloading doesn't work anymore. thank you so far for the replies.

« Last Edit: August 23, 2015, 06:26:02 pm by greybrid »

stefan

  • *
  • Posts: 2263
Hmm, I might do a tutorial on shoot and reloading behavior. Sounds like fun =)

UnrealCanine

  • Posts: 244
wouldn't 0.1 seconds not be long enough to notice a reload

greybrid

  • Posts: 32
wouldn't 0.1 seconds not be long enough to notice a reload

its only that short so i dont have to wait too long to see if it worked.

UnrealCanine

  • Posts: 244
well the way I did it in a old game was as such

If ammo>0 and canFire(boolean){
decrease ammo by 1
Set canFire to false
do after fireRateTime{
set canFire to true
}
}
if  ammo<1{
do after reloadTime{
set ammo to 6
}
}

DTH

  • *
  • Posts: 148
put the bullet creation code inside the otherwise block, then it will only be processed when ammo > 1, as it is the code will run no matter the ammo amount because your checking the ammo after the code has run

or encase the top half of the code with its own if statment "if ammo >= 1" will work also