Variable=array[]

Petrik33

Member
Hey guys, hello everybody. I have such a problem in GMS 2, see I have a lot if arrays in my game object, and i want to create objects with variable definitions, and one of the variable i need to set as one of my game object arrays like position=obj_game.posGK[]. Will it work and what will it do, cause I want then to set an array of postion in my object to be the same as posGK????
 

Joe Ellis

Member
To use\handle an array\assign it to a variable you simply do: variable = array
Then after that, you can write to the array using: variable[@ 1] = something.
And read from it: other_variable = variable[1]

This is assuming "array" has been created before hand.
To create an array, simply do: array[0] = 0
 

Petrik33

Member
To use\handle an array\assign it to a variable you simply do: variable = array
Then after that, you can write to the array using: variable[@ 1] = something.
And read from it: other_variable = variable[1]

This is assuming "array" has been created before hand.
To create an array, simply do: array[0] = 0
Thank you very much, but when I do it , the game sends the error of unknown variable:
I do it in variable definition menu
Variable=object.array and it sends the error.
 

FrostyCat

Redemption Seeker
Open your room, then select Room > Instance Creation Order and move your instance of obj_game to the top of the list. You are getting that error because you are trying to get at something from obj_game before it even exists in the room.
 

Petrik33

Member
Open your room, then select Room > Instance Creation Order and move your instance of obj_game to the top of the list. You are getting that error because you are trying to get at something from obj_game before it even exists in the room.
thank you, haven't seen your reply to thank but you're right
 
Top