I’m trying to assign a value to a variable that is based on an expression that divides the object’s position avlue with the game’s Grid size, but it’s not working and I don’t get why.
Here is the code:
In the debugger, the value it returns to these variables is NULL.
If I multiply instead of dividing, it just sets the variable to 0.
Also, I’m using a for each condition which I assumed it would be heavy on performance, but I tried using a “pick all” condition previously, and nothing would happen for some reason.
I’m really confused, I have no idea why this isn’t working.
Do you have actual values in these fields? have you checked that they return results? If either value is 0, you’re going to get null as you can’t divide by zero.
Map_Character_Object.X fetches the object’s X position, Map.Variable(Grid_CellSize_X) fetches this variable which is set to 48 in the editor:
Same for the Y values.
EDIT: I found out what was happening. I didn’t place an instance of the object “Map” in the scene. I thought I could access its variables without it needing to be placed on the scene.
That makes more sense. Objects in the object list are just templates. They don’t exist in game logic at all. Only instances in the scene are actually accessible via logic. You might be better off making those variables into scene variables.
Yeah I thought that by having the objects listed in the Object list, I could access them easily. Helps to have these variables inside objects for database purposes and separating different global functionalities into different objects.
Scene variables wouldn’t work for me because I will need these variables to be accessed throughout the whole project, meaning I need to access them in all scenes. I guess I could have made them Global variables though, I will need to consider that.
What I did was just create each of these objects (like the Map one) when the scene is loaded, however, can I make their values be persistent from one scene to another?