I did like this code, and my game just loading and closed up (no errors, no console), why?
EXAMPLES
How to create a new game object:
function init(self)
-- create a new game object and provide property values
self.my_created_object = factory.create("#factory", nil, nil, {my_value = 1})
-- communicate with the object
msg.post(self.my_created_object, "hello")
end
And then let the new game object have a script attached:
go.property("my_value", 0)
function init(self)
-- do something with self.my_value which is now one
end
My code: Ps: I created 9 cards with giving them ID and stored them in table, after that i tryed to get this property(ID) but my game just 4-5 secs loading and cloasing back without errors in console Pps: Without any information on console, it is clear!
for i = 1, 9 do
if x==3 then
y = y + 1
x = 0
end
local d = vmath.vector3(p.x+x*(SizeOfSprite["Card"]["width"] + scale),p.y+y*(SizeOfSprite["Card"]["height"] + scale),0)
local raId = rand(1,tablelength(RandomCards))
local random = RandomCards[raId]
local cr = factory.create(random["url"], d, nil, { name=tablelength(Cards), cardId=raId }, 1.0)
table.insert(Cards, cr)
x=x+1
end
pprint(Cards)
local id = go.get(Cards[1], "name")
print(msg.url())
end
in a card sript:
go.property("name", 0)
go.property("cardId", 0)
function init(self)
msg.post(".", "acquire_input_focus")
end
Sounds like you have an infinite loop somewhere. Are you spawning objects that spawn other objects? I think it’s impossible to tell from just this though. Can you zip up the project files and post it here?
Defold shut down for me as well when I tried your project. I noticed that you are using my old timer extension and it is probably crashing the engine. It should no longer be used since Defold now provides a native timer. I have removed my timer from the Asset portal and GitHub. Please update your project to use the Defold native timer instead.
No you haven’t created a property. The Factory manual states:
“properties
A Lua table with any script property values to initiate the game object with. See the Script property manual for information on script properties.”
And the Script property manual describes how to create a script property and how to read it.
Ah, sorry I didn’t look carefully. The properties you create exist on the script component in question, not on the game object. This means that when you use go.get() you must address the script component, like this:
local script_url = msg.url(nil, Cards[1], "CardScript")
local name = go.get(script_url, "name")