• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker How to count down

M

Mythx

Guest
Im currently trying to make an ability where my character shoots a thunderbolt out of his arm, so i made a timer to detect when to change the sprite back to normal and then (i havent coded yet since the first part doesnt work) when to shoot the thunderbolt. The timer doesnt work, it doesnt switch back to spr_player_down. What am i doing wrong? (sorry for being a complete novice)
Code:
//Thunderbolt

if keyboard_check_pressed(ord("R"))
{
    thunder_bolt_countdown=9000
    sprite_index=spr_player_bolt_down
}
thunder_bolt_countdown=-600
if thunder_bolt_countdown==600
{
    sprite_index=spr_player_down
}
 
Last edited by a moderator:
M

Mythx

Guest
You have "thunder_bolt_countdown =-600"

So you're setting that var to -600 rather than minusing 600 from it.
ok so i changed it now its
Step
Code:
//Thunderbolt

if keyboard_check_pressed(ord("R"))
{
    thunder_bolt_countdown=9000
    sprite_index=spr_player_bolt_down
}
thunder_bolt_countdown=thunder_bolt_countdown-600
if thunder_bolt_countdown==600
{
    sprite_index=spr_player_down
}
Create
Code:
thunder_bolt_countdown=0
but i press R and the animation immediately stops, i can spam R and it will play bit by bit (holding does nothing).
I then tried changing the
Code:
if keyboard_check_pressed(ord("R"))
to
Code:
if keyboard_check(ord("R"))
but it would just play the animation on loop if i help down R
 

HayManMarc

Member
thunderbolt_countdown -= 600;

This will subtract 600 each step, until you tell it to do otherwise.

It's the same as:

thunderbolt_countdown = thunderbolt_countdown - 600;
 

Rob

Member
ok so i changed it now its
Step
Code:
//Thunderbolt

if keyboard_check_pressed(ord("R"))
{
    thunder_bolt_countdown=9000
    sprite_index=spr_player_bolt_down
}
thunder_bolt_countdown=thunder_bolt_countdown-600
if thunder_bolt_countdown==600
{
    sprite_index=spr_player_down
}
Create
Code:
thunder_bolt_countdown=0
but i press R and the animation immediately stops, i can spam R and it will play bit by bit (holding does nothing).
I then tried changing the
Code:
if keyboard_check_pressed(ord("R"))
to
Code:
if keyboard_check(ord("R"))
but it would just play the animation on loop if i help down R
Well 9000/600 = 15. That's 15 steps until the var equals 600.

It's a safe bet to assume your room speed is 30-60.
 
L

Lonewolff

Guest
Instead of this

Code:
if thunder_bolt_countdown==600

I'd do this

Code:
if thunder_bolt_countdown<=600

Due to GMS using floating point numbers behind the scenes, what you would logically think is 600 is more likely 600.0000001 or something in the internals of GM. So your code will never likely equate to true.
 
M

Mythx

Guest
Instead of this

Code:
if thunder_bolt_countdown==600

I'd do this

Code:
if thunder_bolt_countdown<=600

Due to GMS using floating point numbers behind the scenes, what you would logically think is 600 is more likely 600.0000001 or something in the internals of GM. So your code will never likely equate to true.
Well 9000/600 = 15. That's 15 steps until the var equals 600.

It's a safe bet to assume your room speed is 30-60.
Thank you both, I got it working now. Thanks so much :D
 
Top