cannons a lil empty..... need some help please
ovechkin8
Member Posts: 42
I have a slight problem / bug in my game that is pretty random. I have had a few people check my code too but we cannot seem to find what is the problem so any help or advice would be most helpful. Anyways Im having trouble with a reload function of a cannon. If you shoot any of the three cannons you have a reload time that matches that set cannon. So for example if you fire the right cannon, then there is a right cannon reload time. Each reload time is set to 3 seconds and then a green outline shape appears indicating "go / fire". The problem is that every so often my a random of the three cannons will not reload. And this is how they are set up in game salad.
Center Cannon
when (game.middle reload) is( false) + actor receives events when touch is inside
--------------------------------------------------------------------------------------------------------
actor receives event when touch is pressed
--------------------------------------------------------------------------------------------------------
spawn actor (cannon ball)
play sound
spawn actor (smoke)
change attribute ( game.middlereload) to: (true)
--------------------------------------------------------------------------------------------------------
Rule
when attribute (game.middlerelaod) is (true)
------------------------------------------------------------------------------------------------------
Timer
After (3) seconds
Change attribute (game.middlereload) to: (false)
Spawn actor (go) * thats the green outline of the cannon
Thats how all 3 are set up. I have to guess that there is about a 20% failure rate when one tends not to reload. It not every game but I would say that 1 in 5 where one or two cannons do not reload. Sorry for the long post but any help would be great.
Thanks
Center Cannon
when (game.middle reload) is( false) + actor receives events when touch is inside
--------------------------------------------------------------------------------------------------------
actor receives event when touch is pressed
--------------------------------------------------------------------------------------------------------
spawn actor (cannon ball)
play sound
spawn actor (smoke)
change attribute ( game.middlereload) to: (true)
--------------------------------------------------------------------------------------------------------
Rule
when attribute (game.middlerelaod) is (true)
------------------------------------------------------------------------------------------------------
Timer
After (3) seconds
Change attribute (game.middlereload) to: (false)
Spawn actor (go) * thats the green outline of the cannon
Thats how all 3 are set up. I have to guess that there is about a 20% failure rate when one tends not to reload. It not every game but I would say that 1 in 5 where one or two cannons do not reload. Sorry for the long post but any help would be great.
Thanks
Comments
Everything
The problem may not be with your cannons but elsewhere. Too many sprites?(check fps), collisions, timers.
A good place to start would be in your 'cannon ball' and 'smoke' actors. Check there are no funnies in these actors.
Also and take this with a huge pinch of salt, but i always avoid the boolean variables. I always use integers 1/0.
Also in your first rule is 'all' or 'any' selected?
I will try the integer variable. I have heard of some other people doing that. Besides the spelling errors that might come with them, any other advantage?
if MyState=1 then... (run)
if MyState=2 then... (jump)
if MyState=3 then... (fall)
if MyState=4 then... (powerup)
Now you've got a nice structure that at least gives you a chance of being efficient, plus a little security that behaviors governing 'jumping' should never interfere with that of 'falling'.
Anyway back to booleans : like i said, i haven't done any testing, so i couldn't tell how, when, even if they fail, its pure prejudice on my part.
Check your frame rates, if they go below 24 its too slow anyway, but its a good indication of too many sprites.
Right now you have a touch is inside as well as a touch is pressed condition. You don't need both. I would remove the touch is inside so nothing gets triggered accidentally. Also make sure Run To Completion is set on the TImer.
(I changed game.middlereload to self.readyToFire just for my own clarity)
I would set up your Rule structure in each cannon like this:
Rule
When All conditions are valid
When Touch is Pressed
When self.readyToFire = true
-----spawn actor (cannon ball)
-----play sound
-----spawn actor (smoke)
-----Change Attribute: self.readyToFire to: false
-----Timer: After 3 seconds Run To Completion
----------Change Attribute: self.readyToFire to: true
----------Spawn actor (go) * thats the green outline of the cannon
That should do the trick and avoid misfires and reloading issues. Let us know if you're still having problems.
You can also throw a loose Display Text Behavior on the cannon (outside of that Rule) that tracks game.middlereload to make sure it is behaving properly.
Something not happening 20% of the time is a lot. I don't usually encounter any misfires so there is definitely something funky happening.