Results 1 to 8 of 8

Thread: LUA Boot Camp

  1. #1

    Default LUA Boot Camp

    While I am trying to learn yet another language, I figured I would start this thread, which would document all the 'basics' of programming in LUA. The official Girder documentation does contain a lot of information, I spent way too much time trying to find out how to do some of the basic things. So let's put all the useful examples in this thread.

    Some basic LUA rules:
    • LUA is case sensitive
    • to comment out a line, start the line with 2 dashes. Example: --this is a comment
    • Ending lines with a semi-colon is optional


    Would be great if this thread could be set 'sticky', making it easier to find this basic knowledge.
    Last edited by etron; November 7th, 2008 at 07:22 AM.

  2. #2

    Default

    Simple if-else examples:
    Code:
    if varA == 0 and varB == 0 then
      return "yes"
    else
      return "false"  
    end
    Valid operators can be found in the Girder manual (PDF file in your Program Files directory).
    Last edited by etron; November 7th, 2008 at 06:53 AM.

  3. #3

    Default

    Splitting a delimited string into a usable array (similar to explode() in PHP). Keep in mind that the array starts at 1, not 0 as in most other languages:
    Code:
    local strTest = "yellow|red|green"
    local arrTest = string.Split(strTest, "|")
    
    print(arrTest[1])
    print(arrTest[2])
    print(arrTest[3])
    This would print:
    yellow
    red
    green

  4. #4
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    personal favorite function

    Code:
    table.print(arrTest)
    will print the complete array in one go.
    Ron
    No support through PM

  5. #5
    Join Date
    Mar 2008
    Location
    Nottingham, England
    Posts
    406

    Default

    come on all,

    keep 'em coming....

    trying to learn Lua

    every days a school day....

    Mark
    some people learn by writing, some by reading, some by listening and some by doing?...me I'm not learning at all

  6. #6
    Join Date
    Jan 2009
    Location
    Copenhagen, Denmark
    Posts
    8

    Default

    Hi
    I'm also trying to learn...
    When you use print ex. print(arrTest[1])
    Where can you se the output? Could be usefull for debugging i think.

  7. #7
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    The output should appear in the Interactive Lua Scripting Console (see the view menu)
    --Rob

  8. #8
    Join Date
    Jan 2009
    Location
    Copenhagen, Denmark
    Posts
    8

    Default

    So it does. Thanks..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •