Timer not Working :(
Blitz3D Forums/Blitz3D Beginners Area/Timer not Working :(
| ||
My game has three guns - a semi, a full auto, and a slow auto. The semi works like this:If MouseHit(1) CreateBullet() EndIf or something like that. The full auto looks like this: If MouseDown(1) CreateBullet() EndIf But the slow-auto, which uses a timer, doesn't work: If gun=3 If MouseDown(1) If Millisecs() >= shottimer + 500 CreateBullet() shottimer = Millisecs() EndIf EndIf EndIf Yet it doesn't work. And "shottimer = Millisecs()" is in my Globals section. |
| ||
Should work. Check the spelling of your variable, since there's no Option Explicit in Blitz (at least, no yet). Perhaps you have declared it as shottiner, while in the code you refer to shottimer (do you see the difference ?). Check also that the variable name is not a function name too. Remember, to make any variable Global, you have to declare it in this way: Global shottimerWhat do you mean with "Globals section" ? There's no such a section in Blitz. You make a variable Global only when you declare it as shown above. Hope it helps, Sergio. |
| ||
How about adding a text message in between the 'IF's which lets you know which bits are being processes and what the current values are? |
| ||
oops,... deleted |
| ||
"Globals section" - the place in my program where I declare all the Globals. I check for misspellings. Thanks. |
| ||
Have you added the text messages to check these sections of code are being run? I, generally, add a 'called from' parm to my functions (i.e. Createbullet("slowauto")) and then add a text command to the function to display where it was called from. |
| ||
By the way, this code:If MouseDown(1) CreateBullet() EndIfwill probably execute much faster than you wish it to. You should probably change it the same code you are using for your 'slow auto', but just use a shorter time increment. For example, if I remember correctly, an M-16 machine gun can fire about 700 rounds per minute. That would equate to 11-2/3 rounds per second. That would equate to a round about every 86 milliseconds. So use that number in place of the 500 you use for your 'slow auto' mode. |
| ||
Your code is fine, so it's something else. Check the value of the gun variable. this works: While Not KeyHit(1) ; start main loop If MouseDown(1) If MilliSecs() >= shottimer + 500 Print "bullet";CreateBullet() shottimer = MilliSecs() EndIf EndIf Wend ;end main loop End ;end program |