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

Legacy GM Variable doesn't exist when it does?

Hello everyone!
I really don't know whats wrong with my code, maybe I'm just using Parents wrong.
Parent Code:
Code:
//Create
selected =  0
//Step
if(selected = 1) {
x = mouse_x
y = mouse_y
}
the child just uses the drag and drop inherit event code
My problem is vary confusing..
when I first open the game nothing is wrong, but when I create an object it crashes and says selected doesn't exist. so I try creating an object with out using that parent object but no mater what the crash says this:
Code:
############################################################################################
FATAL ERROR in
action number 1
of Mouse Event for Left Pressed
for object obj_parent:

Push :: Execution Error - Variable Get 100099.selected(100301, -2147483648)
 at gml_Object_obj_parent_LeftButtonPressed_1 (line 4) - if(cmSelected = 0 && selected = 0) {
############################################################################################
also this happens with any object in the room (even the ones that don't have that parent)
 

jo-thijs

Member
Did you declare selected in the create event as:
Code:
var selected ...;
If so, that's your mistake.

Is the line of code in the error message executed inside a with structure or is the code action it is in set to be executed by some other object?
If so, that's your mistake.

Otherwise, post the object information (text that appears when you click on "object information" when editing an object) of both your parent and child objects.
 
Did you declare selected in the create event as:
Code:
var selected ...;
If so, that's your mistake.

Is the line of code in the error message executed inside a with structure or is the code action it is in set to be executed by some other object?
If so, that's your mistake.

Otherwise, post the object information (text that appears when you click on "object information" when editing an object) of both your parent and child objects.
I didn't do the first thing, the second thing I'm not sure on what you meant, third:
Parent:
Information about object: obj_cm_objs
Sprite:
Solid: false
Visible: true
Depth: 10
Persistent: false
Parent:
Children
obj_more_options
obj_cm_shelf
obj_cm_counter
obj_cm_counter2
obj_cm_door
obj_cm_inside
Mask:
No Physics Object
Create Event:
execute code:

selected = 0
image_speed = 0
rot = 0

Mouse Event for Left Pressed:
execute code:

if(!place_meeting(mouse_x,mouse_y,obj_vis_options)) {
if(mouse_y < 768-128 || cmGUIen = 0) {
if(cmMode = 0) {
if(cmSelected = 0 && selected = 0) { //this is where it crashes (with selected not cmSelected, that is a global var)
selected = 1
cmSelected = 1
} else {
if(cmSelected = 1 && selected = 1) {
if(place_free(x,y)) {
selected = 0
cmSelected = 0
}}}}

Child:
Information about object: obj_cm_shelf
Sprite: spr_food_stand
Solid: true
Visible: true
Depth: 10
Persistent: false
Parent: obj_cm_objs
Children:
Mask:
No Physics Object
Create Event:
execute code:

selff = "obj_cm_shelf"
selff2 = "obj_food_stand"

selected = 0
image_speed = 0
rot = 0

cmObjs += 1
cmId = cmObjs

Destroy Event:
call the inherited event of the parent object
Step Event:
call the inherited event of the parent object
Mouse Event for Left Pressed:
call the inherited event of the parent object

I think you need to add "event_inherited();" to the specific event in order for the parent code to work.
There is also a documentation https://docs.yoyogames.com/source/dadiospice/002_reference/objects and instances/objects/generating events/event_inherited.html
I already did :3
 

jo-thijs

Member
Your error message doesn't match your object information.
Your error message is thrown by the object obj_parent, which is neither of the objects you gave.

Furthermore, either the objects you gave are never created, or you have not provided their full object information, or you have other objects initialize variables of these objects, or you are using globalvar.
In the first case, why are you even looking at these objects then?
In the second case, why are you not giving the entire object information?
In the third case, you should still initialize those variables in the create event.
In the fourth case, don't use globalvar, it eventually just causes confusion.
 
Your error message doesn't match your object information.
Your error message is thrown by the object obj_parent, which is neither of the objects you gave.

Furthermore, either the objects you gave are never created, or you have not provided their full object information, or you have other objects initialize variables of these objects, or you are using globalvar.
In the first case, why are you even looking at these objects then?
In the second case, why are you not giving the entire object information?
In the third case, you should still initialize those variables in the create event.
In the fourth case, don't use globalvar, it eventually just causes confusion.
Never-mind I fixed it myself :)
 
Top