Problems with msg.post (defold rookie here) (SOLVED)

EDIT: Ok, found the error, had a underscore in the message_id that caused it, used to be “set_tile” but simplified the code here with ‘test’ and therefor it worked.

Hey, finally got around to play with Defold a bit, now with Defold 2.0’s alpha, that looks so much better than the old one. But ran into a problem. Probably just a noob error on my part :slight_smile:

I’m trying to build a level of blocks:

local function build_level(self)
    print("Building level...")
    local pos = vmath.vector3()
    for y=12,0,-1 do
        for x=0,16 do
           pos.x = x * blocksize
           pos.y = y * blocksize
           local block_id = factory.create("#blockfactory", pos)
           msg.post(block_id,"test"})
        end
    end
end

I got everything to work, level rendered just fine, except when I do the msg.post, then I get the following:

ERROR:SCRIPT: /main/level.script:26: Field layer_id not specified in table

Why is this, the error isn’t very helpful, at least not to a beginner like me.

Thanks,
Niklas

1 Like

Probably unrelated but you should remove ‘}’ after “test” in msg.post
as for the error you’re getting, my guess would be that it’s because you’re only specifying the url and position, whereas it requires rotation, properties and scale too.

eg. the getting started page does this:

factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)

f is id -> "#platform_factory"
the second parameter is the position
the third is rotation
the fourth is a table of properties
and the fifth is scale.

1 Like

Ok, found the error, had a underscore in the message_id that caused it, used to be “set_tile” but simplified the code here with ‘test’ and therefor it worked.

2 Likes

“set_tile” is a system message so you should not use that name for custom messages: http://www.defold.com/ref/tilemap/#tilemap.set_tile:url-layer-x-y-tile--h-flipped---v-flipped-

1 Like

Oh, right so it wasn’t the underscore. Great, good to know! Thanks!

The only required argument for factory.create() is URL, the rest are optional.

2 Likes