SOLVED How to create list of Objects Without their Instances???

Petrik33

Member
So, I want to create level editor for my game, and I have stuck again. Now I don't know how can I collect all my objects that I can edit in one ds_list without creating their Instances. Maybe there is a way I can loop through all of the objects and check for their parent, so the manager objects are excluded???
 

Roldy

Member
If you want to access object information for making instances then you need to use the appropriate methods.

For instance if you have an object 'obj_myObject; you can access its sprite before making any instance like so:

GML:
var _sprite = object_get_sprite(obj_myObject);

draw_sprite(_sprite, 0, 0, 0);
Review the following:


 

woods

Member
so would he do something like this to place my_Object with the mouse?
Code:
var_placeable_myObject = obj_myObject;
instance_create{mouse.x, mouse.y, _placeable_myObject}
 

Roldy

Member
so would he do something like this to place my_Object with the mouse?
Code:
var_placeable_myObject = obj_myObject;
instance_create{mouse.x, mouse.y, _placeable_myObject}
Yes that is correct.

The asset 'obj_myobject' defines the object. In gml, referencing 'obj_myobject' is just another name for the object index.

OP can't say 'obj_myobject.sprite_index' unless he has instances. Because only instances have the built in variable 'sprite_index'.

However, the object definition still has a sprite which is retrievable with 'object_get_sprite(obj_myobject.'

He can build a list or like

GML:
ds_list_add(myObjectList, obj_myObject1); // obj_myObject1 is the name of an object index in the asset list
ds_list_add(myObjectList, obj_myObject2); // obj_myObject2 is the name of an object index in the asset list
ds_list_add(myObjectList, obj_myObject3); // obj_myObject3 is the name of an object index in the asset list
ds_list_add(myObjectList, obj_myObject4); // obj_myObject4 is the name of an object index in the asset list

// etc..
 

woods

Member
OP can't say 'obj_myobject.sprite_index' unless he has instances. Because only instances have the built in variable 'sprite_index'.

this makes it alot more clear to me ... thanks ;o)

i have a project forming on back burner that this will definitely be useful for. ....modular parts for the player to custom build their ship
 

Petrik33

Member
Yes that is correct.

The asset 'obj_myobject' defines the object. In gml, referencing 'obj_myobject' is just another name for the object index.

OP can't say 'obj_myobject.sprite_index' unless he has instances. Because only instances have the built in variable 'sprite_index'.

However, the object definition still has a sprite which is retrievable with 'object_get_sprite(obj_myobject.'

He can build a list or like

GML:
ds_list_add(myObjectList, obj_myObject1); // obj_myObject1 is the name of an object index in the asset list
ds_list_add(myObjectList, obj_myObject2); // obj_myObject2 is the name of an object index in the asset list
ds_list_add(myObjectList, obj_myObject3); // obj_myObject3 is the name of an object index in the asset list
ds_list_add(myObjectList, obj_myObject4); // obj_myObject4 is the name of an object index in the asset list

// etc..
Yeah, thanks for help, but you haven't helped solving the main problem, the solution of manually adding all the objects in the ds list can't fit the system, with hundreds of objects. I have to find the way to loop through the asset list, to get object indexes, but how???
 

kburkhart84

Firehammer Games
There is a function object_exists(). I don't know if it would work for you though. If objects are indexed basically from 0 to x, then you could simply loop through a few hundred indices, checking if the object exists. If it does, you can check what the parent is using object_get_parent(). There is also object_is_ancestor() would directly check if the parent is a specific object(in case you knew ahead of time exactly what the parented objects are that you want to exclude children of). Once you have a list, you may have to exclude specific objects that shouldn't be part of the list, but, as long as object indices are stored from 0 to whatever like I think they still are, this should get you started.
 

Petrik33

Member
There is a function object_exists(). I don't know if it would work for you though. If objects are indexed basically from 0 to x, then you could simply loop through a few hundred indices, checking if the object exists. If it does, you can check what the parent is using object_get_parent(). There is also object_is_ancestor() would directly check if the parent is a specific object(in case you knew ahead of time exactly what the parented objects are that you want to exclude children of). Once you have a list, you may have to exclude specific objects that shouldn't be part of the list, but, as long as object indices are stored from 0 to whatever like I think they still are, this should get you started.
There is a function object_exists(). I don't know if it would work for you though. If objects are indexed basically from 0 to x, then you could simply loop through a few hundred indices, checking if the object exists. If it does, you can check what the parent is using object_get_parent(). There is also object_is_ancestor() would directly check if the parent is a specific object(in case you knew ahead of time exactly what the parented objects are that you want to exclude children of). Once you have a list, you may have to exclude specific objects that shouldn't be part of the list, but, as long as object indices are stored from 0 to whatever like I think they still are, this should get you started.
Oh, haven't known the objects are just indexed from 0, this helps a lot, exactly thr solution I needed, thank you, very much!
 

TheouAegis

Member
As long as you are using studio, for the time being at least (mandatory disclaimer), you can use the first index of the object you want the user to be able to referencec and the last index of the object you want the user to reference. As long as you keep all of the objects that the user has access to together, then you simply need to loop from the first object to the last object, add them to the list. In studio, objects are assigned an ID at compile time. But if you're going to be doing level editing, you will want to make sure you don't modify the position of the objects at all. You can add onto the objects, but do not change the positions. If you do, you will throw off the save files for your levels.
 

Petrik33

Member
As long as you are using studio, for the time being at least (mandatory disclaimer), you can use the first index of the object you want the user to be able to referencec and the last index of the object you want the user to reference. As long as you keep all of the objects that the user has access to together, then you simply need to loop from the first object to the last object, add them to the list. In studio, objects are assigned an ID at compile time. But if you're going to be doing level editing, you will want to make sure you don't modify the position of the objects at all. You can add onto the objects, but do not change the positions. If you do, you will throw off the save files for your levels.
Sure, that's why I will try saving the objects by their asset names and then use function asset_get_index
 
Top