get layer of object expression

I’m about to create a “save/load” function to my game and to do it, I need to get position, size, angle/direction, ZOrder, animation, variables and layer of objects present in the scene to be able to store all these values in an external file and load it back later. I can get all the information using expressions, except layer of object. At least I can’t find expression to get layer of object, tried “object.Layer()” but didn’t work as it return “0” so would be nice to have such expression :slight_smile:

The idea is basically to “write” layer of object to an external file, and later read the string back in to a string variable and use that variable to set the layer of created object. Maybe it would also require to be able to use string variables to set layer of object, as now I’m about to try to store layer of object in a string variable and use that variable to write the value to file and later read that string back in to variable but seems like I can’t use variables to set layer of object , I can’t get it to work even that way :neutral_face:
Or am I do wrong something?

So what I’m requesting, is to be able to get layer of object expression to be able to write in to file, and to be bale to use string variable to set layer of object.

Thanks.

All parameters of actions/conditions/expressions asking for the name of a layer are text expressions, meaning that you can use variable and functions just like when there is a text parameter, even if there is no button to open the text expression editor.
You can see that because you must always add quotes around a layer name (otherwise, it is not a valid expression!).

So you can already use variables for example to change the layer of an object.
There is no object.Layer() expression but I can add it. But be careful, it seems that you were trying to use it in a expression waiting for a number (because you say “it returns 0”)! If this expression is added, it will be an expression returning a text, so you have to use it in a parameter waiting for a text, you won’t find it in an expression editor for a number parameter :slight_smile:

Yes, I was trying to use integer variable because I could not find the way to refer to string variable, but I found it now (VariableString()) :laughing:
Anyway I have solved the problem by changing the name of layers to only numbers and store layer number in object integer variable for each object and write these values to file as integer values on save, later when I want to load the save I just convert the value to string “”+ToString() to set layer of object.

But yes, that would be very useful to be able to get layer of objects in expression :slight_smile: That way I don’t have to use object variables and add value manually, I could simply get layer of object and write in to file directly on save, and read value back in to scene variable to set layer of object on load :slight_smile:

Thanks,

Can’t you save it as string? I mean, XML is one big string when it comes down to it.

Probably I can save it as string but I didn’t know how to refer to a string variable to read the text back in to a string variable and use that variable as “name” of layer when loading, so I worked around with integer variables. I found it now but I don’t mind really as all the other values get saved are integers and they have to be integers, layers the only exception so far.
Though it not perfect because if something is on the Base layer which is basically an empty string “”, as an integer value it get saved as “0” and when I load the save back, the objects on Base Layer don’t get loaded at least not visible as it loaded to layer “0” which is doesn’t exist :laughing:
So yeah, probably I have to save and load it as string or I have to drop “base layer” and use a layer with name “0” instead.