Move object to absolute position with Lua.

  • #1, by ke4Wednesday, 02. December 2015, 12:55 9 years ago
    Hi, as there is currently no direct option to move object to absolute position with Lua. I wrote a simple function for that. There is action part for that, but there have to be the positions set manually. So i'm just sharing it. Deelay and easing is an optional argument.

    function moveObject(name, x, y, deelay, easing)
    	deelay = deelay or 0
    	easing = easing or easeQuintOut
    	obj = Objects[name].Position
    	Objects[name]:to( deelay, { Offset = { x = x - obj.x, y = y - obj.y } }, easing )
    end	
    

    Key Killer

    810 Posts


  • #2, by MachtnixThursday, 03. December 2015, 19:32 9 years ago
    Hi. Looks simple. But too complicated to me: So I make an action "call lua script", take in the name of my object (unfortunally I have to do a loop first, they are 26 objects, calling "Rohr01 to Rohr26", but I don't know how, so I use only one object first to test) into the obj-variable, and I want it to 150, 250 (f.e.). Where are the position values? Is this correct?

    function moveObject(name, x, y, deelay, easing)
    	deelay = deelay or 0
    	easing = easing or easeQuintOut
    	obj = Objects[Rohr01].Position
    	Objects[Rohr01]:to( deelay, { Offset = { 150 = 150 - obj.150, 250 = 250 - obj.250 } }, easing )
    end	
    

    I don't understand this object thing...

    Machtnix

    Thread Captain

    1097 Posts

  • #3, by ke4Thursday, 03. December 2015, 19:44 9 years ago
    Put the code i wrote above somewhere into your scripts.

    Then create "execute a script" action part. & this is how you call the function. Keep the name variable in the function.

    moveObject("Rohr01", 150, 250)
    


    Or with deelay 1 second.

    moveObject("Rohr01", 150, 250, 1000)
    


    As for the loop you can create table and loop it.

    objects = {"Rohr01", "Rohr02, "Rohr03", "Rohr04",
                "Rohr05", "Rohr06", "Rohr07"}
    


    for o = 1, #objects do
        moveObject(objects[o], 150, 250)
    end
    

    Key Killer

    810 Posts

  • #4, by MachtnixThursday, 03. December 2015, 19:54 9 years ago
    Yepp. I remember (I did Basic and Pascal functions 30 years ago... ;-). My mistake.

    Thank you very much. I will try it.

    First I have to search the log-file I can see any Lua results like comments and check-values. The main problem isn't Lua itself (it's silly similar to Pascal...), it's the object system and data structure of Visionaire (who's who and how I adress the right part?). Then I start with printing "Hello world" to learn Lua ;-) It takes quite a while...

    This field options and loops is a job next year...

    Thread Captain

    1097 Posts

  • #5, by ke4Thursday, 03. December 2015, 20:14 9 years ago
    It took me a while either :-)

    I recommend take a look at the examples at wiki.
    http://wiki.visionaire-tracker.net/wiki/Scripting

    Key Killer

    810 Posts

  • #6, by MachtnixThursday, 03. December 2015, 20:27 9 years ago
    Both sides are permanently on my side (scripting and data structure), but I haven't the right "divine flash" yet how it works REALLY. :-)

    If you start to work with Vis editor only, you will make a "dirty" way, it' s a huge improvisation. I think, if you need ONE Lua script it's better to realize the whole mini game with Lua just as well... ;-) All this big problems are suddenly only some tiny script lines. IF YOU CAN...

    Machtnix

    Thread Captain

    1097 Posts

  • #7, by MachtnixThursday, 03. December 2015, 21:49 9 years ago
    I haven't allocate any "object name", there is only the name listed leftside the scene menu. Because I don't want pop up a name while playing - it's only a dummy object to lock the jigsaws. Can I use the IDs as well? There are randomly: 12, 68, 104, 105...

    Thread Captain

    1097 Posts

  • #8, by ke4Thursday, 03. December 2015, 22:04 9 years ago
    I think it's possible to use ID's, but i've never used it though.
    But you only need the "leftside panel" name for the object, it's the name you should write into the function. I think it will work even if the object itself doesn't have any name.

    Key Killer

    810 Posts

  • #9, by MachtnixThursday, 03. December 2015, 22:47 9 years ago
    Ah, thx.

    Thread Captain

    1097 Posts

  • #10, by sebastianFriday, 04. December 2015, 08:19 9 years ago
    Uh, nice. What gets moved hefe now? Only the object image or also its area polygon?

    Thread Captain

    2346 Posts

  • #11, by ke4Friday, 04. December 2015, 08:58 9 years ago
    Both :-)

    Key Killer

    810 Posts