Integer change Attribute not working properly
hey guys. So on the current game im working on, there is an integer called 'Timer' that ticks down from 4 to 0 every 1.5 seconds. When it hits 0, its game over. Every time a player collects a coin, the Timer goes back up to 4. there are 4 actors on the screen, each with a number (1-4), when the Timer goes down, the corresponding number's Alpha changes to 0, making in disappear, simulating a countdown. The problem im having is that, on a very rare occasion, if the player collects a coin JUST before/during the integer change (lets say from 3 to 2) then the timer will carry on, not registering that the integer should have been changed back to 4, and continue the change from to 3 to 2, so rather than the integer being 4, it is now 2. i put a Display text with the Timer attribute on it, so i could see what is happening to the attribute when the bug occurs. the count hits 3, then if i collect the coin just as it is about to change/during the change, the Timer will go '4 - 2' straight away. is this normal? and is there a way to code in a guarantee that the integer will change, no matter where a bouts along the countdown the integers are at? The current code is like this:
When game.timer = 0
after 0.5 sec - change game.gameover - true
when game.timer = 4
after 1.5 sec (NOT run to completion) - change game.timer - to 3
when game.timer = 3
after 1.5 sec (NOT run to completion)- change game.timer - to 2
when game.timer = 2
after 1.5 sec -(NOT run to completion) change game.timer - to 1
when game.timer = 1
after 1.5 sec -(NOT run to completion) change game.timer - to 0
in coin actor:
when actor receives event - collide with actor - player
change attribute - game.timer - to 4.
so basically if i collect a coin JUST during/after that 1.5 seconds where the integer changes, the Timer continues to register that change from 3 to 2, rather than the change to 4, and just changes to 2 regardless. minus this bug, the whole thing works beautifully.
sorry this is a long post, but I've been slated in the past for not giving enough information, so i wanted to be thorough. Thanks in advance to anyone who can help with this. Cheers
Comments
What happens if you place a Log Debugging Statement in the coin's collision rule? Does it show up in the Debugger window every single time there's a collision?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang hi, can you explain to me how to use the log debugging statement? I've never even heard of it, let alone used it haha. Thanks
ok i think i MIGHT have solved it. i did this in the coin actor:
when actor receives event - collide - player
for 0.2 secs (Run to completion) - change game.timer - to 4
after 0.2 secs (Run to completion) - change game.timer - to 4
destroy actor
so even during that transition phase between integers, the code is spamming that integer back up to 4. i haven't tested this properly yet, but really hope this fixes it. let me know if this code could be improved somehow. id really appreciate it. Cheers
A Log Debugging Statement is a behavior you add to an actor. It can have a text string or an expression, just like a Display Text behavior would have. The difference is the Log statements only appear in the Debugger window. I forget which menu its under (Window?) but if you open it and preview your app, you'll see the statement appear.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User