Is there a way for my instance gameobject to choose from a random position (a-i) from my lua table and once it got a random position it must remove the position from the lua table so that my other instance gameobjects can’t use the same position. I also want to insert the position back into the lua table once the gameobject gets destroyed.
Lua table:
local M = {}
M.planet_position =
{
a = {x_axis = 0, y_axis = 0}
b = {x_axis = 0, y_axis = 0}
c = {x_axis = 0, y_axis = 0}
d = {x_axis = 0, y_axis = 0}
e = {x_axis = 0, y_axis = 0}
f = {x_axis = 0, y_axis = 0}
g = {x_axis = 0, y_axis = 0}
h = {x_axis = 0, y_axis = 0}
i = {x_axis = 0, y_axis = 0}
}
return M
First you are missing ,s at the end of those table lines for each letter.
If you set a letter to nil ( a = nil ) it will remove it from the list.
You will want to keep a second copy of the table to restore the first one’s values. Probably can do it with a Lua table shallow copy function of the primary one. Then you will need to reference each letter when you create or destroy the gameobjects so that you know what to restore.
Is there a reason you are referencing each sub table by a letter? You could do
I think I will go for the last bit of code. It is a bit easier to understand.
I don’t know I referenced each sub table by a letter. Actually unnecessary. Now I understand better.
How would I go about changing the “x_axis” and “y_axis” values for each one because I do bit of calculations using screen height/width along with other values that will determine each axis.