Introducing Seeds

After a request from @h5apps - https://twitter.com/h5apps/status/38985386831253504 - I am now happy to annouce the fruits (ha, get it?) of about 15 minutes labour.

In 2.9 you will be able to set properties in Tiled via Lua code in Lime.

Essentially you create a small module that has a main() function and returns a value. What that function does is up to you. You would then call that file “lime-seed-seedName.lua” and call it in Tiled by setting the value of a property to this:

“seed:seedName”

They are explained here - http://justaddli.me/seeds.php - and include an example seed that will explain things. [import]uid: 5833 topic_id: 6848 reply_id: 306848[/import]

cool stuff!!!

-FS.

(nitpick alternative for lime-seed-randomValue.lua: [lua]function main(params) return math.random(unpack(params)) end[/lua])

[import]uid: 8093 topic_id: 6848 reply_id: 23900[/import]

I hope it’s helpful!

Also, I’ve never used unpack before as I think I recall reading somewhere that it was a slight performance hit? I can’t remember though so if I’m wrong I will be happily corrected. Does unpack play nicely if the params argument was nil? [import]uid: 5833 topic_id: 6848 reply_id: 23937[/import]

Not sure about the performance hit - cannot imagine that it would be anything you could measure - specially compared to all the xml parsing you are doing :wink:

Anyway, unpack is an extremely useful function to transform a table-array into a list of values, either for return values or to use a table-array for the function argument values. You can even specify the array indices for the range of elements to use.

You were right to be concerned about nil values as unpack(nil) would blow up . A more prudent version would be:

[lua] function main(params) return math.random(unpack(params or {})) end[/lua]

or even better

[lua] function main(params) return type(params)==“table” and math.random(unpack(params)) end[/lua]
-FS.
[import]uid: 8093 topic_id: 6848 reply_id: 23942[/import]

rotate seed working perfectly thank you!

i am now trying to use seeds to give tiles (not objects, but background tiles) properties like being able to drag them or change their physics behavior… any thoughts? (i can’t get tile:drag() to do what I want it to)

[import]uid: 24493 topic_id: 6848 reply_id: 25402[/import]

Glad it’s working!

What is tile:drag() doing? [import]uid: 5833 topic_id: 6848 reply_id: 25431[/import]

not at my dev computer, but was trying to use “this” and drag - i know that’s vague - sorry.

Do you have any example code of tile:drag() working?

Thanks!

[import]uid: 24493 topic_id: 6848 reply_id: 25534[/import]

The drag code uses a touch event object to do its magic. To see it in action you would want a touch listener, something like this:

local onTouch = function( event )  
 tile:drag( event )  
end  
  
Runtime:addEventListener( "touch", onTouch )  

This is working on the assumption that “tile” is a valid tile object. [import]uid: 5833 topic_id: 6848 reply_id: 25537[/import]