Move object to absolute position with Lua.

  • #1, z ke4Wednesday, 02. December 2015, 12:55 hodinky 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	
    

    Zabiják klíčů

    810 Posts


  • #2, z MachtnixThursday, 03. December 2015, 19:32 hodinky 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

    Kapitán

    1097 Posts

  • #3, z ke4Thursday, 03. December 2015, 19:44 hodinky 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
    

    Zabiják klíčů

    810 Posts

  • #4, z MachtnixThursday, 03. December 2015, 19:54 hodinky 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...

    Kapitán

    1097 Posts

  • #5, z ke4Thursday, 03. December 2015, 20:14 hodinky 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

    Zabiják klíčů

    810 Posts

  • #6, z MachtnixThursday, 03. December 2015, 20:27 hodinky 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

    Kapitán

    1097 Posts

  • #7, z MachtnixThursday, 03. December 2015, 21:49 hodinky 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...

    Kapitán

    1097 Posts

  • #8, z ke4Thursday, 03. December 2015, 22:04 hodinky 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.

    Zabiják klíčů

    810 Posts

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

    Kapitán

    1097 Posts

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

    Kapitán

    2346 Posts

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

    Zabiják klíčů

    810 Posts