• 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!

Windows Script executing every step

Chaser

Member
Hi having some issues, gamemaker appears to be creating my character every time it changes to a state. This has not done this all week, working fine and as intended until today, i opened the project, ran it before doing anything else and i've been trying to figure out why its started doing this.

Im using a state machine:

heres the code bits:

Room Creation Code: (Shortened)
enum states
{
P1idle,
P1Walk
}

Player Object ( Step event) (shortened)
switch(states)
{
case states.P1idle: scr_player_1_idle(); break;
case states.P1Walkright: scr_player_1_Walkright(); break;
}

Scripts: scr_player_1_idle()

keyboard_check(vk_right)
{
states = states.P1Walkright;
}

Scripts: scr_player_1_Walk()

keyboard_check(vk_nokey)
{
states = states.P1idle;
}

Player Object ( create event)
states = states.P1idle;

note: I have had other states in this game but i eliminated all off them to try and identify the problem, which i didn't, so im back to the original first two states and the problem persists.

As i said this was working fine up until today. i've cleaned the target, restarted my computer and i'm sorry i need to reach out now as to why this is happening, i cannot find anything wrong with my code. its just bizarre. Why is gamemaker constantly creating my player object every frame? and in every state? theres is nothing in my code that tells gamemaker to 'Create' anything, only to change states.

Any help would be so appreciated :)
 

Attachments

Have you run your project in debug mode to confirm your player is being re-created every step?

You can put a break point in your player step event code then step through it line by line to check what's happening.

Is there some other code / instance that might be doing this?

I would search my code for any instance_create_ functions and confirm that the parameters are correct. If you are passing incorrect/uninitialised variables into instance_create_ functions, you can end up creating the wrong instance.

If you don't resolve it, you may have to paste more/all of your step code here, as the code you have above looks ok to me.

If you do post more of your code, use the [code][/code] tags so that its formatted nicely and easier to read.
 

Chaser

Member
Have you run your project in debug mode to confirm your player is being re-created every step?

You can put a break point in your player step event code then step through it line by line to check what's happening.

Is there some other code / instance that might be doing this?

I would search my code for any instance_create_ functions and confirm that the parameters are correct. If you are passing incorrect/uninitialised variables into instance_create_ functions, you can end up creating the wrong instance.

If you don't resolve it, you may have to paste more/all of your step code here, as the code you have above looks ok to me.

If you do post more of your code, use the [code][/code] tags so that its formatted nicely and easier to read.
I may well have to paste my code, I cant see anything in the debugger that it is 'Creating' anything, and there is absolutely no Instance_create events in any of my code.
what i did notice in the debugger is it says there is no creation code in my room, but i only have 1 room and you can clearly see there IS a creation code in there. maybe this is the problem?
 

Attachments

Nocturne

Friendly Tyrant
Forum Staff
Admin
Having a variable that is the same name as the enum seems a recipe for disaster (and I didn't even think you could do that). I'd start by changing the "states" variable tobe a different name, like "my_state" or something...
 
One other thing to check, your first screenshot looks like what happens when you turn off the Clear Display Buffer or Clear Viewport background in your room settings. Might want to check that as well just in case.
 

Chaser

Member
@Nocturne I'm not quite sure what you mean? I get what you are saying, but not sure how else to change the 'State' to something else in a way your mean, i get 'unregistered variable' or 'Error, must be a constant', this way seems to work OK for me, my brain is a bit boggled with what your saying, i did try and figure it out.

@IndianaBones I tried the clear view port and background, but they didn't do the trick. HOWEVER, now i feel some what stupid here, and i'm just going to curl up into a ball somewhere.... I know why its doing it, are you ready for it?..........
My black background was disabled in the layer editor. whoops.

i cant apologise enough for wasting your time, if its any consolation i have spent a good 6 hours dissecting my code, deleting my code, and rewriting my code to try and find an answer so i wasted time too, and look like an idiot, haha.
(maybe a little pop up to remind users as they execute that some layers are turned off)

I thank you for your time and efforts in helping me. :)
 

TheouAegis

Member
@Nocturne I'm not quite sure what you mean? I get what you are saying, but not sure how else to change the 'State' to something else in a way your mean, i get 'unregistered variable' or 'Error, must be a constant', this way seems to work OK for me, my brain is a bit boggled with what your saying, i did try and figure it out.
He is saying your code has
Code:
states = states.P1idle;
which should be an illegal operation - you are setting the constant states to the enum states.P1idle. He said you should change your actual variable to something else, like state.
 

Chaser

Member
He is saying your code has
Code:
states = states.P1idle;
which should be an illegal operation - you are setting the constant states to the enum states.P1idle. He said you should change your actual variable to something else, like state.
Yep, I got ya now, I will defo change them tomorrow, il use something like ' behaviour' don't want no illegal stuff creeping up on me or anything causing me problems, right now my biggest problem is ME. ;) Thank you everyone.
 
Top