object w parent (child object) not being created

S

S-4

Guest
hi all, im not new to gml but i havent touched it in about a year and im having trouble creating a child object.

so i have a parent button object (o_par_button) with two child button objects (o_button_green and o_button_red). im trying to create the child button objects in-game via another unmentioned object using the instance_create_depth() function, but heres the thing: if the child button objects have the parent button object assigned to them they dont even get created via said instance_dreate_depth() function (i confirmed they dont get created using instance_count), BUT if i remove the parent-child object hierarchy and copy/paste the exact same parent code back into the button objects (now WITHOUT parents), the button objects work PERFECTLY. so i know the problem is not the inherited code of parent object. it has to do something with the fact that im trying to instance_create_depth() an object that has a parent. is this not allowed? what am i doing wrong? all suggestions appreciated thanks all, from area S-4!
 

TsukaYuriko

☄️
Forum Staff
Moderator
What you're describing is allowed and a perfectly normal thing to do. Please post all relevant code for inspection (parent, child, creation).
 
  • Like
Reactions: S-4
S

S-4

Guest
code from the object that triggers the creation of the child object (well is supposed to at least)
GML:
//create light button objects on ufo
//hyper
if (!instance_exists(o_ufo_light_button_hyper))
{
    instance_create_depth(x,y,o_ufo.depth-10,o_ufo_light_button_hyper);
}

//tractor beam
if (!instance_exists(o_ufo_light_button_tractor_beam))
{
    instance_create_depth(x,y,o_ufo.depth-1,o_ufo_light_button_tractor_beam);
}
parent button code (this code works perfectly as mention in op above):
create event
GML:
is_selected=false;
step event
GML:
//align with ufo
depth=o_ufo.depth-1;
x=o_ufo.x;
y=o_ufo.y;

//initialize highlight-select
if (place_meeting(x,y,o_mouse_cursor))
{
    is_selected=true;
}
else
{
    is_selected=false;
}

//highlight buttons if selected
if (is_selected==true)
{
    image_alpha=85;
}
else
{
    image_alpha=35;
}
 
R

robproctor83

Guest
Your child object does it have a create or step event? If so you have to add event_inherited() to it so it runs the code from the parent. If your not running it then the step code isn't running either.

If you do have the event inherited then in the child object step event run show_debug(random(1)) and see if the output console is continuously printing a random number when you expect it to be there.

Also you can open debugger and see what objectsbexist, but I find it easier to print from them if it's just a single object like this.
 
  • Like
Reactions: S-4

TsukaYuriko

☄️
Forum Staff
Moderator
Do the children have any code?

The only chance I can see for no creation to happen when the code in question is ran should be when an instance of these objects (or their parent) already exists. Double-check your object relationships and make sure that the children have the parent object listed as their parent. Also ensure that the code in question is even running at all via debug messages or the debugger - output debug messages or step through your code to verify whether the block that handles creation runs, as well as the result of both instance_exists checks, for a start. Check whether this matches your expectations - if it doesn't, chances are something's being recognized as something it's not supposed to be.

Side note: image_alpha has the range 0~1, not 0~100.
 
  • Like
Reactions: S-4
S

S-4

Guest
Do the children have any code?

The only chance I can see for no creation to happen when the code in question is ran should be when an instance of these objects (or their parent) already exists. Double-check your object relationships and make sure that the children have the parent object listed as their parent. Also ensure that the code in question is even running at all via debug messages or the debugger - output debug messages or step through your code to verify whether the block that handles creation runs, as well as the result of both instance_exists checks, for a start. Check whether this matches your expectations - if it doesn't, chances are something's being recognized as something it's not supposed to be.

Side note: image_alpha has the range 0~1, not 0~100.
thank you! solved
 
Top