Factory create with property trable (SOLVED)

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

Withlocal id = go.get(Cards[1], "name")


Without:

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?

Nope, i don’t. One line:

id = go.get(Cards[1], "name")

do this “loading”

Test1.zip (6.2 MB)

Look up.

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.

1 Like

And I have deleted the forum post as well.

oh, ok… will try

That timer extension is SO dead. :smile:

ok, i did, and removed timer. But it steel loading and exit…

Can you share the new version of your project please?

Test1.zip (9.6 MB)

oh, and del main on_input, but it will be still loading

It works well here. Tested on macOS. The game launches and I see the following:

Please supply the following information requested here so that we can give better support:

yup, just uncomment this on main script:

pprint(Cards)
	--BUG HERE
	--local id = go.get(Cards[1], "name")
	print(msg.url())

It crashes for me now as well. But I don’t understand this line though:

local id = go.get(Cards[1], "name")

What are you trying to do?

The Cards table contains a list of game object ids. And there is no “name” property on the game object.

The engine shouldn’t crash though, but what you are doing is wrong. What do you actually wish to do?

yup, i got a URL from the table “Cards”, for example first, and try to got “name” that must be here cose i created this property:

local cr = factory.create("#Card", d, nil, { name=tablelength(Cards), cardId=raId }, 1.0)

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.

i sow and i did it here:

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")