GameMaker Get speed causing sprites to change [solved]

S

Snayff

Guest
Evening all,

Bit of a weird one. I am trying to find the game speed so that I can determine the length of a second. I used

Code:
global.oneSecond = game_get_speed(gamespeed_fps)
to do so. When I have that in place my game foes from this

upload_2017-9-1_20-27-46.png

to this

upload_2017-9-1_20-30-11.png

That means the sprite has changed (how?!) and it no longer moves or changes state, though the lack of a state change may be in part down to the nature of the states.

So I have two questions; is there an easier way to get the value of a second and how on earth did it change the sprite?

Thanks in advance.

-Snayff
 
K

KaiXtr

Guest
Well, you can get the game speed in settings at the room editor, most of times appears 30.
 
S

Snayff

Guest
@KaiXtr thanks for the reply. You're right of course, though I need it programmatically so that eventually users can set their frame rate.
 

TheouAegis

Member
If the sprite changed, then you have conflicting code somewhere, you have an improperly defined variable somewhere, or some other thing. Just getting the game speed doesn't change a sprite in and of itself. And there's no way of knowing if the state changed because of the wrong sprite or if the sprite is wrong because the state is changed, but the state did change as well, not just the sprite.
 
S

Snayff

Guest
@TheouAegis in principal I agree with you buddy but in practice I am not so sure. Whilst that must be the case I am struggling to find where it is changing to the player state. There are two states it can more to and both are for the enemy.

Also worth noting is that when I set the global.oneSecond to 0 it works as expected but if I give it any value it has the issue mentioned above. I reference the variable in one place (other than setting it) as an if and only set one other variable.

Code:
//update readyToPatrol
if  stateVar[0] < (global.oneSecond * stateVar[1]){
    stateVar[0]++; //increment
}else{
    readyToPatrol = true;
}
stateVar[0] is a timer, stateVar[1] has an integer of the seconds to wait and readyToPatrol is a flag that allows me to move to the patrol state.
 

TheouAegis

Member
When global.oneSecond is 0, then stateVar[0] can never be less than 0, so readyToPatrol is true by default. So then as soon as you factor in a second, stateVar[0] is immediately less, so readyToPatrol is false, which I just noticed is what's going on in the second pic. So that suggests

a) You used stateVar somewhere else inappropriately, or
b) The enemy's state is set to Airborne by default if readyToPatrol is false and the sprite is that which is associated with Airborne state
c) The enemy's sprite is that green block by default (perhaps due to bad programming) when readyToPatrol is false and the airborne state is activated as a result.
 
S

Snayff

Guest
OK, so if I take out the whole if statement it still doesnt work so it cant be that section causing the issue.

stateVar is reset on state change and the default state for the enemy is idle. :/ Interestingly when I load the debug it doesnt hit my breakpoint in the idle state so I guess something is changing it before it gets there.

Hey, "bad programming" is quite an inflammatory comment there buddy! Though arguably it is all bad programming seeing as it isnt working! ;)
 
S

Snayff

Guest
Just for reference I managed to solve it. The issue was that no state was appropriate... though I still can't figure how it then bumped across to the player state!
 
Hey, "bad programming" is quite an inflammatory comment there buddy! Though arguably it is all bad programming seeing as it isnt working!
This is an attitude I deal with myself sometimes, but it's ultimately harmful to take. It's better to adopt the humble attitude of all your programming being bad programming (until you become a recognised programming genius (and even then...)) and trying to learn from those around you. Sometimes you will be right, sometimes they will be right, but it's never useful to take umbrage at someone pointing out that a bug is probably the result of bad programming (or said more diplomatically, incorrect programming). Just take the statement for what it is, something is being done wrong, otherwise there wouldn't be a bug.
 
S

Snayff

Guest
@RefresherTowel You're right. I tried to make light of it but it can be challenging to remain positive when faced with a lack of tact. I'll do better next time to remain more resilient. :)
 
Top