Need help with Lua

  • #1, by PaupasiaSaturday, 15. August 2015, 02:25 10 years ago
    I finally bought the program and I'm transferring my project in visionaire, unfortunately I don't know anything about programming in Lua and I am struggling to convert my instructions from vbscript to Lua. Are similar but I can't really understand how to handle the instructions. Can someone help me understand the differences of syntax? Thanks a lot for any help!

    Forum Fan

    165 Posts


  • #2, by ke4Saturday, 15. August 2015, 10:12 10 years ago
    Hi

    I dont know vbscript but AFRLme wrote a guide to Lua script on the wiki.
    http://wiki.visionaire-tracker.net/wiki/Basic_lua:_Index

    There are also some script examples you can take a look at from basic to advanced.
    http://wiki.visionaire-tracker.net/wiki/Compiled_Index_of_Lu...

    Key Killer

    810 Posts

  • #3, by Simon_ASASaturday, 15. August 2015, 11:12 10 years ago
    Hi Paupasia! Welcome on the VS forums.

    You will discover that you don't need to use LUA a lot in VS (most of the time you don't need to program, you use Action parts).

    A preview of the list of actions:
    http://wiki.visionaire-tracker.net/images/f/f1/Actionpart_box_en.png

    Some of the possible actions are decribed here:
    http://wiki.visionaire-tracker.net/wiki/Actionparts

    --> Before starting doing everything in LUA, try to become familiar with Visionaire and the Actions scripts through the various tutorials in the wiki.
    http://wiki.visionaire-tracker.net/wiki/Tutorials
    I know that you will be a bit lost after Adventure Maker (I was too).

    There is an old tutorial here (which is out of date) but I find it better to begin with:
    http://www2.visionaire2d.net/glenfx/
    I have started learning with it!

    Here's a quick comparison of languages:

    VBscript:

    If condition Then
             [Statements]
          [ElseIf condition-n] Then
             [Statements]
          [Else]
             [Statements]
          End If
    


    Visionaire Action parts:

    If 'condition' is True
      List of actions
    Else
     List of actions
    End if
    


    Visionaire LUA:

    if condition == true then
     do something 
    else
     do another thing
    endif
    


    If you have specific questions, please let us know.

    Great Poster

    321 Posts

  • #4, by PaupasiaSaturday, 15. August 2015, 12:46 10 years ago
    Hi guys! Thank you so much for the quick replies, really kind of you! I've read all the tutorials you mentioned and worked with Visionaire Action parts a little, but I really need an example to understand the syntax, my brain seems to be broken with Lua grin
    For example I have this script and I need to convert it to Lua, or maybe not (I don't know) where the variable "lift" is related to another script called in a different frame, so I think "lift" should be a global variable while "bottoni" should be a local variable... maybe...


    sub bottoni()
    Action.LoadAPicture Hotspot(12), ""
    If aperto = 1 then call bottoni1: bottoni3
    If aperto = 0 then call bottoni2
    End Sub

    sub bottoni1()
    If bot2 = 0 then lift = 0
    If bot2 = 1 then lift = 1
    If bot2 >= 2 then lift = 2
    If bot2 = -1 then lift = -1
    End Sub

    sub bottoni3()
    If lift >= 0 then Hotspot(10).enabled = true
    If bot1 = 0 and lift < 2 then Hotspot(9).enabled = true
    If bot1 = 1 and lift < 2 then Hotspot(9).enabled = true
    If bot1 >= 2 then Hotspot(9).enabled = false
    If bot1 = -1 then Hotspot(10).enabled = false
    End Sub

    sub bottoni2()
    If bot1 = 0 then Hotspot(1).enabled = true: Hotspot(5).enabled = true
    If bot1 = 1 then Hotspot(1).enabled = true: Hotspot(5).enabled = true
    If bot1 >= 2 then Hotspot(1).enabled = false: Hotspot(5).enabled = true
    If bot1 = -1 then Hotspot(5).enabled = false

    maybe there is a more simple way to do this in Lua or Action Parts, I don't know! As I said my brain needs a key to be unlocked! grin

    Forum Fan

    165 Posts

  • #5, by sebastianSaturday, 15. August 2015, 13:14 10 years ago
    all variables (values) you define in VS are global, so you can access them from anywhere in all actions or via Luascript.
    All i see in your code here are functions which could be easily done with action parts and no lua included.

    Is this some code to display the buttons of an elevator control panel?

    Thread Captain

    2346 Posts

  • #6, by PaupasiaSaturday, 15. August 2015, 13:39 10 years ago
    Yep! It is a strange elevator that I created, this is only part of the scripts involved (actions are shared between three frames connected to further frame depending on the button clicked) and if I understand your explanation, I can just put my actions in the scene action tab to make it work: D

    Forum Fan

    165 Posts

  • #7, by Simon_ASASaturday, 15. August 2015, 15:38 10 years ago
    I remember how things can be different between Adventure Maker and Visionaire, so yes just forget about code and start using action tabs wink

    This is more or less how it works:

    1 - create a new scene ('+' icon in the column on the left) and name it as you want
    2 - change your scene properties (background image, music, etc)
    3 - add action parts if you need (for the whole scene, "at beginning" or "at end" of scene, for example - which are executed automatically when the scene is loaded, or when you leave it)
    4 - locate the scene objects window (to create pictures, buttons, hotspots), then:

    1. create a scene object for each future button ('+' icon in the middle column)
    2. for each button, create a new hotspot area (it's the blue square icon named 'create and edit object areas')
    3. edit the settings of the selected scene object in the lower window (properties, actions, conditions...) --> use the action tab at the bottom of the screen to enter the script for your elevator button

    5 - write your scripts with action parts.
    Example:
    script1: 'when cursor enters object area' --> set cursor 'take' (rollover on)
    script2: 'when cursor leaves object area' --> set cursor 'arrow' (rollover off)
    script3: 'on left click' --> what happens when you click...

    --------------
    Quick note about Conditions:
    On the contrary to Adventure Maker, you can create as many conditions as you want in VS.

    Usually if you want to show/hide a picture in VS, you have to link the scene object with a condition (in the bottom properties tab). Add a condition in the "Condition" area. When the condition is false, the button is hidden, and when the condition is true, the button is visible. You can check "negate" to invert the visibility. However you cannot use variables to show/hide dierctly a picture, so you always have to use conditions somewhere in your Actions script.

    --------------
    Finally, a quick example:
    If you want to display a hidden picture only when 'variable1' is equal to 5, then you have to create an additional condition like in the following script:

    --* create a variable named variable1 *--
    --* create a condition to show/hide the picture, name it "condition1" and set it to false *--
    
    If variable 'variable1' = 5
       change condition 'condition1' to true -- this will show the picture if 'condition1' is linked to the scene object of the picture
    End if
    


    --------------
    Knowing this, you should be able to convert your vbscript to VS Action parts.
    Example with an extract of your code above:

    sub bottoni1()
    If bot2 = 0 then lift = 0
    If bot2 = 1 then lift = 1
    If bot2 >= 2 then lift = 2
    If bot2 = -1 then lift = -1
    End Sub

    Would need the following Action parts:

    If value 'bot2' = 0
       set variable 'lift' = 0
    else
       if value 'bot2' = 1
          set variable 'lift' = 1
       else
          if variable 'bot2' >= 2
             set variable 'lift' = 2
          else
             if variable 'bot'2' = -1
                set variable 'lift' = -1
             end if
          end if
       end if
    end if
    




    Great Poster

    321 Posts

  • #8, by PaupasiaSaturday, 15. August 2015, 16:02 10 years ago
    You're right! Lot of different things. Thank you so much for all the tips so well explained. And your example of Vbscript to VS action parts It was exactly what I wanted to know, Lua can wait grin
    Now finally I understand the differences between them and I can start with some script grin
    Have a nice day grin

    Forum Fan

    165 Posts