Beginning with LUA

  • #1, by ikarusMonday, 23. June 2014, 21:02 6 years ago
    I want to try learning LUA code language despite I have no idea about programming (well, only the basics).
    Do you have any recommendation to start?

    I've seen this book: Programming in LUA, by Roberto Ierusalimschy, the creator of the language.
    Do you know it? What do you think about it?

    Newbie

    37 Posts


  • #2, by afrlmeMonday, 23. June 2014, 22:34 6 years ago
    I don't really think you need to get a book or anything in-depth to learn it. Maybe you could learn it that way but I find that it is much easier to learn by doing, than reading! razz

    The thing is that the books & official documentation for lua are not going to explain to you about the Visionaire Studio data structure or exclusive Visionaire Studio functions etc.

    The best place to start would be by learning the basic operators & then having a little go at getting something to work using a combination of them.

    This blog here is quite a good place to learn from. It also has exercises for you to try.

    This section here of the Visionaire Studio wiki has pretty much everything relevant to approaching lua & Visionaire Studio.

    Here's a guide I wrote about the basic operators of lua here, complete with examples & screenshots. It needs updating a little bit though.

    My favorite way to learn something new is by reverse engineering something that already exists... in other words you take something that already exists, break it down & then try to build it back up again; in this case script it, until it's the same or better.

    Check out some of my scripts on this page here. Most of them contain comments which explain what each line, function etc is doing, or what it is for...

    Imperator

    6808 Posts

  • #3, by ikarusTuesday, 24. June 2014, 14:25 6 years ago
    Ok, thank you very much. I'll follow your advices.

    Newbie

    37 Posts

  • #4, by MachtnixTuesday, 24. June 2014, 18:33 6 years ago
    The thing is that the books & official documentation for lua are not going to explain to you about the Visionaire Studio data structure or exclusive Visionaire Studio functions etc.


    That's the problem :-). I can write a Lua-command to print "Hello, world" and it works perhaps, but I couldn't see the result anywhere. :-) I don't know how to fit lua and visionaire together...

    Machtnix

    Thread Captain

    1060 Posts

  • #5, by afrlmeTuesday, 24. June 2014, 20:50 6 years ago
    print("hello world")
    1
    2

    ...would be printed to the messages.txt/messages.log file.

    You can also access the log by pressing "tab" key while running your game via the visionaire studio editor & typing in...
    print log
    1
    2

    Imperator

    6808 Posts

  • #6, by MachtnixTuesday, 24. June 2014, 22:29 6 years ago
    Hi,

    It was only an example. I didn't really want to print this...:-)

    I give you another eyample to show (it's yours):

    getObject("Characters[character_name].CharacterCurrentOutfit"):setValue(VOutfitRandomMinTime, 2000) -- between 2 seconds


    OK. I think, I have to change [character_name] into my own character's name, haven't I? What about CharacterCurrentOutfit. Is this a placeholder or a variable? It looks like a typical command (with capitals between). I think I won't change it, because it seems correct in this way. What about Charakters? Must I change it into my own charakter name or folder? Is it a command or s.th. like this? No, it should be an character-object. So, first I have to understand the syntax and what is what. That's the reason I use German variables - to distinguish between commands, phrases and my own free choiced names. All English words I can find belongs to lua and are fixed - and the rest will be my own freedom... BTW: I looked for this random function months ago... :-) Thx for that.

    Machtnix

    Thread Captain

    1060 Posts

  • #7, by afrlmeTuesday, 24. June 2014, 22:55 6 years ago
    OutfitRandomMinTime & OutfitRandomMaxTime is new data structure entry to vs4.0 onwards, it wasn't available in 3.7.1.

    Ok I'll give you another example of the same thing you mentioned above...

    Let's say I have a character called "Tom"...
    getObject("Characters[Tom].CharacterCurrentOutfit")
    1
    2

    same as...
    getObject("Characters[Tom]"):getLink(VCharacterCurrentOutfit)
    1
    2

    alternatively...
    getObject("Characters[Tom].CharacterOutfits[outfit_name]") -- replace outfit name with name of an outfit (case sensitive)
    1
    2


    Now here's 2 more examples...

    1. get currently active character & characters currently active outfit with getObject method...
    getObject("Game.GameCurrentCharacter.CharacterCurrentOutfit")
    1
    2

    2. Same as above but with getLink method...
    game:getLink(VGameCurrentCharacter):getLink(VCharacterCurrentOutfit)
    1
    2

    ... it's kind of hard to explain as you might need to use different methods depending on what you are trying to do. But long story short is that you should use the vs data structure tables to see what is scriptable & what is read only & the type of get function it needs to return or change the data tables.

    here's another couple of quick examples...

    1. get the number of a value...
    local val = getObject("Values[value_name]") -- replace value_name with name of a value

    print( "the value of " .. val:getName() .. " is " .. val:getInt(VValueInt) ) -- prints "the value of value_name is x"
    1
    2
    3
    4

    2. get string of a value...
    local val = getObject("Values[value_name]") -- replace value_name with name of a value

    print( "the string value of " .. val:getName() .. " is: " .. val:getStr(VValueString) ) -- prints "the string value of value_name is: x"
    1
    2
    3
    4

    3. see if a condition is true or false...
    local cond = getObject("Conditions[condition_name]")

    if cond:getBool(VConditionValue) or cond:getBool(VConditionValue) == true then -- both the same thing
    print(cond:getName() .. " is true")
    else
    print(cond:getName() .. " is false")
    end
    1
    2
    3
    4
    5
    6
    7
    8

    I can't really explain everything in a few words that will suddenly make you jump up in the air shouting "EUREKA! I've got it!", as it's just not that simple. Go through some of those links I provided yesterday. The scripting page is a good place to start for some examples & explanations of some of the general vs lua functions.

    P.S: I'm considering setting up an official Visionaire Studio youtube account at some point in the near future - if I find the time - as I figure I could probably create some tutorials on lua script & using/writing various functions for Visionaire Studio. Maybe some general Visionaire tutorials as well. I prefer the lua stuff though.

    Imperator

    6808 Posts

  • #8, by MachtnixWednesday, 25. June 2014, 02:11 6 years ago
    Ah, whow, that's very useful! Thanks a lot. Sometimes I feel like a baby, which learns it's first mother tongue: that's your NOSE, that's a TREE, this is DAD and that's MUM!

    Machtnix

    Thread Captain

    1060 Posts

  • #9, by andy-rinaldiTuesday, 22. July 2014, 20:48 6 years ago
    P.S: I'm considering setting up an official Visionaire Studio youtube account at some point in the near future - if I find the time - as I figure I could probably create some tutorials on lua script & using/writing various functions for Visionaire Studio. Maybe some general Visionaire tutorials as well. I prefer the lua stuff though.


    YES, please!

    Forum Fan

    160 Posts

  • #10, by ikarusMonday, 11. August 2014, 14:33 6 years ago
    P.S: I'm considering setting up an official Visionaire Studio youtube account at some point in the near future - if I find the time - as I figure I could probably create some tutorials on lua script & using/writing various functions for Visionaire Studio. Maybe some general Visionaire tutorials as well. I prefer the lua stuff though.


    One more vote for those LUA tutorials!

    Newbie

    37 Posts

  • #11, by ikarusThursday, 14. August 2014, 09:34 6 years ago
    Well, I think this could become an interesting thread to post little steps and questions for begginers learning LUA with no experience in programming. I'm one of them and there must be more. So, why don't we try to learn together?

    I've begun with the links AFRLme posted, studying basic LUA syntax. The guide about operators is pretty good, but the scripting section of the VS wiki doesn't seem very easy for noobs like me (I don't understand anything), so I'm diving a little into LUA programming, and after that, I'll try to approach LUA and VS. I can't see another easier way to go through it, since there's no path for people like me to go on Visionaire Studio and LUA. I'm not very sure even where to put LUA scripts into the engine...

    I don't know how far I will get into LUA scripts. Maybe I get bored pretty soon or be surpassed, but I'll do what I can. If there's anybody with the same conditions as me, please join me, and this 'adventure' will be better and funnier. I'm a graphic designer, not a programmer, and this is a very hard task for me, like going across the jungle with a little knife...

    Now I'm beggining with the exercises of the blog AFRLme posted. I'll tell the results when it's done. I downloaded LuaEdit 2010 (the name was already suspicious) and even LuaForWindows editors, but I had strange troubles with both. I searched for alternatives and I found an IDE (wich means Integrated Development Environment) called ZeroBrane Studio. It looks good, it works fine -at the moment-, it has a tutorial for begginers, it's user-friendly... and it's free (but you can donate a free amount of money to support the creators if you want).

    That's all by now. Please, share your experiences beggining with LUA. We can make it.

    See you on the road.

    Newbie

    37 Posts

Write post