Ah. I took a look. It’s bad that we crash but there is a reason. This line crashes:
print(go.get(list[math.random(0,listpos-1)], "parentid"))
First some comments:
-
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:
list[listpos] = msg.url()