Hi, I am trying to use go.get() to fetch a property into a factory created object from another factory created object using a url stored in a list. With the go.get() line in place it causes a silent crash with nothing returned to the console, not even any previous print statements.
The attached code should demonstrate this, line 22 of sp.script is the culprit.
I hope you can recreate the issue, if not let me know and I`ll try the code on some other systems.
list and listpos are global. It’s usually not recommended to use global variables as it can result in a lot of unwanted side effects etc. In this case it’s not the cause of the problem though.
I usually recommend that you break-up hard to read lines of code into several shorter easier to read lines. Like this:
local list_index = math.random(0,listpos-1)
local list_value = list[list_index]
local parent_id = go.get(list_value, "parentid")
print(parent_id)
Now, in the init() function you do:
go.property("parentid", hash(""))
function init(self)
spawntimer = 0.1
list[listpos] = go.get_id()
listpos = listpos + 1
end
So, on the current script you have a script property called parentid. And you’re trying to look that up in your update() function where the crash happens. The thing is though that in init you store:
list[listpos] = go.get_id()
Where it really should be:
list[listpos] = go.get_id("#") -- the property is on this script
You could also do like this in init() and store the url: