Ability to use a lua global as a property value

#1

If I create a list of global offsets such as “ITEM_A”, “ITEM_B”, “ITEM_C” and then set the property to those values then nothing occurs (the value is left at the default value.) I would like to share one script between all collectables in my game and set the property to the item ID this way. Then if I need to change the offsets in the save file, I won’t have to redo the work (I don’t want to use a hard-coded integer value since that would negate the benefit of using the globals.)

0 Likes

#2

Do you mean script properties being set based on a global required module value?

Can you give an example of what you’re doing that isn’t working how you want?

1 Like

#3

Why not set the property in init?

0 Likes

#4

Just because I want to use the same script for multiple objects with the same behavior and it’s convenient to just enter the ID of the object to pass to the script properties directly in the object view. I know I can set it via a factory as well but was hoping it to be more convenient.

0 Likes

#5
local my_properties = {
  [hash("prop1")] = "prop1",
  [hash("prop2")] = "prop2",
}

go.property("prop", hash("prop1"))

function init()
  self.actual_prop = my_properties[self.prop]
end
4 Likes