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

Accessing all child objects individually[re-posted]

W

Wild_West

Guest
Just a re post of this issue I've been struggling with the past few days, only had one other brain helping me think of the solution so I thought I might need to bring in a fresh perspective as my original post is probably already lost in the shuffle of new ones lol

So this started out as what seemed like a more complicated problem but it's actually not, at least I don't think. I just don't know how to do it.


In my menu handler object I have a switch statement that checks the current value of an item's name (a string variable, not the actual name of the object asset)
and then assigns the item_spawned variable to create that item whenever spawn_item is set to true.

The problem is I can only ever create the first child object of item_parent so how do I get access to all of them?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Are you accessing them via the parent object's index/ID? You can just use the index (name) of each object, no matter whether it's a child of a certain object or not.
 
W

Wild_West

Guest
Are you accessing them via the parent object's index/ID? You can just use the index (name) of each object, no matter whether it's a child of a certain object or not.
you mean change the switch variable check to item_parent.id ?
or item_parent.name.id?

All that did was give me an error that the hp recovery item didn't exist.
and I already have an if instance exists check for the parent

I added the missing item to the room anyway and then got an invalid comparison error for te name matched up against the asset_get_index
 
Last edited by a moderator:
W

Wild_West

Guest
Are you accessing them via the parent object's index/ID? You can just use the index (name) of each object, no matter whether it's a child of a certain object or not.
I removed all references to item_parent and moved the item spawning to a script, and it's still making the wrong ones, and still swapping between the same 2.

I am officially out of ideas.

basically just calling the script for every slot in the array and using this

if(held_items[argument0] == "Gate Key" ) {instance_create(player_parent.x +130, player_parent.y -60, key);
spawn_item = false;

and in the menu handler I just do
create_item_from_menu(0)
create_item_from_menu(1)

ect with the number representing the array slots to check for the strings.
 
Top