GMS 2.3+ Children not inheriting

ww_y

Member
I have an object named pPlayerEntity which contains all the keyboard input movements and some information about a player state machine I have set up. My goal here is to have the player control multiple different little characters throughout the game. I thought I would do this by having the player input controls in a different object (pPlayerEntity) and then having the controllable characters be children of this object to make my life easier. Unfortunately, this seems to be the opposite. The child object does not inherit any of the code from pPlayerEntity and I just have no idea what's going on. I even messed with the code of the parent to see if Game Maker would give back an error and nothing. It seems the child object is not running any of the code of the parent. And by the way, no the child object has no code of itself, so it should definitely just be running the code of the parent. Even so, I have put in the Inherit code command just in case, and still nothing.

Any insight?

Here is some screenshots of the objects in question and some of the code Im trying to inherit. Aswell as what i see when running it:
 

Attachments

Last edited:

kburkhart84

Firehammer Games
I'd have to see the project and the object settings to know for sure. If you don't have a step event at all, it should automatically be running the code of the parent. This was working fine last time I tried it(in my GMC Jam entry in fact a couple months ago).

Can you show us the object settings and events please?
 

ww_y

Member
I'd have to see the project and the object settings to know for sure. If you don't have a step event at all, it should automatically be running the code of the parent. This was working fine last time I tried it(in my GMC Jam entry in fact a couple months ago).

Can you show us the object settings and events please?
I've updated the post to include pictures of everything! Should have added that in the first place, my bad.
 

kburkhart84

Firehammer Games
What is in the create and step events of oPlayer?

Sorry, the pic shows it grayed out so you don't have such events on them. So how do you know for sure that said code isn't happening at all? I don't see any code there that would make an actual change. I'm guessing your issue is that maybe you are using script_execute() incorrectly and it isn't doing anything.
 

ww_y

Member
What is in the create and step events of oPlayer?

Sorry, the pic shows it grayed out so you don't have such events on them. So how do you know for sure that said code isn't happening at all? I don't see any code there that would make an actual change. I'm guessing your issue is that maybe you are using script_execute() incorrectly and it isn't doing anything.
So currently, I am not using script_execute in the example I screenshotted (as you can see from the grayed-out are). I know for sure the code isn't happening because I am unable to move the player character at all. When the game runs, the only thing that happens with the child player object is that it plays the object sprite continually making it look like it's spinning in place, but no inputs are responsive. (This spinning seems to be another indicator that the code is not even being looked at by the engine for some reason, as image_speed = 0 is part of the parent code's create event.

I don't understand why I even need script_execute if this is a child object with no code of its own. The nature of it being a child of another object should make it run the parent code, at least that is how I understand it, however, it seems to be completely ignored.
 

kburkhart84

Firehammer Games
So currently, I am not using script_execute in the example I screenshotted (as you can see from the grayed-out are). I know for sure the code isn't happening because I am unable to move the player character at all. When the game runs, the only thing that happens with the child player object is that it plays the object sprite continually making it look like it's spinning in place, but no inputs are responsive. (This spinning seems to be another indicator that the code is not even being looked at by the engine for some reason, as image_speed = 0 is part of the parent code's create event.

I don't understand why I even need script_execute if this is a child object with no code of its own. The nature of it being a child of another object should make it run the parent code, at least that is how I understand it, however, it seems to be completely ignored.
Here is the problem I see. I don't see ANY code anywhere that would do the moving of the objects at all, parent OR child. Where is the code that does the moving?

Also, in most cases you don't need script_execute. It is only in very specific circumstances. This is a separate issue from the whole parent/child thing. I saw it in the parent code, but I don't know what it is doing because I don't know what "state" is.
 

ww_y

Member
Here is the problem I see. I don't see ANY code anywhere that would do the moving of the objects at all, parent OR child. Where is the code that does the moving?
I am new to GMS but from what I understand the code in the parent object receives the keyboard input, while the code in the state machine translates it into movement. state = PlayerStateFree which is the script that runs the movement code and updates the sprite accordingly

There doesnt seem to be a problem with the code itself because if I were to copy and past the create and step event into oPlayer instead of having it in pPlayerEntity, then it works perfectly fine. The player object moves corresponding to the input and everything works perfectly. It's only when I have it in the parent/child set up that it does not work.
 

Attachments

Nidoking

Member
You seem to have forgotten to write the PlayerCollision function. The open curly brace there doesn't have a matching close, so you've got a function definition inside another function. That's definitely not going to do what you want.
 

ww_y

Member
You seem to have forgotten to write the PlayerCollision function. The open curly brace there doesn't have a matching close, so you've got a function definition inside another function. That's definitely not going to do what you want.
if you mean in the screenshot below, that function is just collapsed for convenience, but it does have code and a closing bracket.
 

Attachments

kburkhart84

Firehammer Games
Have you added any debug messages to see 100% for sure that the code is not running at all? Add a debug message to the playerstatefree() function. Add another one to the step event in question(on the parent object). Then have ONLY an instance of the child in the room, and see if you get any of those messages.
 
The problem is all this code does nothing that would change what's drawn on the screen.
No movement code, no "x+= hspeed" anywhere.
I'm pretty sure everything runs, you just have 0 visual cues that it does so.
Just because you have a variable called "keyLeft" doesn't magically makes your player move to the left if true ;)
 

ww_y

Member
The problem is all this code does nothing that would change what's drawn on the screen.
No movement code, no "x+= hspeed" anywhere.
I'm pretty sure everything runs, you just have 0 visual cues that it does so.
Just because you have a variable called "keyLeft" doesn't magically makes your player move to the left if true ;)
I have the specific calculations for movement organized in a state machine that I reference in the step event "script_execute(state)"
It specifically all works when I don't do this parent-child relationship. If I just put the exact same code I showed into oPlayer, then it works perfectly.
 
I have the specific calculations for movement organized in a state machine that I reference in the step event "script_execute(state)"
It specifically all works when I don't do this parent-child relationship. If I just put the exact same code I showed into oPlayer, then it works perfectly.
If I understand correctly, this is a global function (outside an object or a constructor) then you want to have something like this in your step event
GML:
PlayerScriptFree(state);
Forget script_execute (read the manual, pretty sure this is NOT what you need), and just make your function to take the player state as an argument.
 

Roldy

Member
First I would suggest using the debugger and just stepping through the code and see what is occurring: Debugger

However, what I would suspect is occurring is with how ever you have implemented:
My goal here is to have the player control multiple different little characters throughout the game. I
Seeing as you have multiple characters which inherit the same parent and the parent is what looks for input, then all the characters are always checking for input (parent step event); how do you determine which child character is the one being controlled?

However you have implemented this switch is most likely where your error is. Review this code.

But again, just use the debugger, break in the step event and see whats going on. Review your code, step through with the debugger, fix the error.

EDIT: Additionally check the documentation for keyboard_check_pressed

I have never tested but it is possible that the first time in a frame the function is called will be the only time it returns true. Since the parent is calling it then it might only work for the first instance that calls it. But I am unsure if the documentation is implying it works for a single frame, or a single call.
 
Last edited:

ww_y

Member
So when I went back into Game Maker and tried to do the parent/child thing again, it worked. Not sure what did the trick, maybe it was closing and opening game maker over and over again, I dont know. Regardless, Thank you all for your replies and for trying to help me figure this one out.
 
Top