Create table rows in LUA

  • #1, z DundilFriday, 29. March 2013, 17:21 hodinky 12 years ago
    Hi:

    How can Visionaire table rows be created in LUA? For example, how can an Object, or an Action be created? Once created I know you can insert it into the right table using table.insert, but... How can first I create it?

    TIA

    Bažant

    19 Posts


  • #2, z afrlmeFriday, 29. March 2013, 18:36 hodinky 12 years ago
    table_name = {}
    table_name[1] = getObject('Actions[action_name]')
    table_name[some_name] = something else
    

    or
    table_name = {something, something else, & so on}
    

    various methods.

    I think Mowren left a better example somewhere, in one of the threads in the LUA Scipting section.

    P.S: if you don't want the stuff in the table to be stored in a save game to save on memory then you do something along these lines:
    table_name = {}
    table_name['_temporary_'] = ''
    table_name[number or name] = something
    

    Imperátor

    7285 Posts

  • #3, z DundilFriday, 29. March 2013, 19:36 hodinky 12 years ago
    Yes, but, in which order? Let's see an example: I want to create a condition. Should I write:
    TCondition[condition_name] = { ??? }
    

    I'd like to know what's written in the ???, and if I have to define in any way that it is a Condition.

    Bažant

    19 Posts

  • #4, z afrlmeFriday, 29. March 2013, 21:20 hodinky 12 years ago
    I'm not right savvy on tables yet but I think simplest method to keep track of is what I showed above & by using the index numbers or by adding a name wrapped like "so"!
    condTable = {} -- create the table (this is global unless local is added before table name)
    condTable[1] = getObject("Conditions[condition_name_1]") -- store condition 1 as condTable[1]
    condTable[2] = getObject("Conditions[condition_name_2]") -- store condition 2 as condTable[2]
    condTable[3] = getObject("Conditions[condition_name_3]") -- store condition 3 as condTable[3]
    condTable["example_name"] = getObject("Conditions[condition_name_4]") -- store condition 4 as condTable["example_name"]
    

    you use/call the table in a query like so ...
    -- if condition 1 is true & condition 2 is false then do action parts listed below!
    if cond[1] and not cond[2] then
     -- do something
    end
    


    Mowren or Alex or someone with more LUA knowledge than me would be able to explain things in more detail than I can - but hope this helps somewhat wink

    Imperátor

    7285 Posts

  • #5, z DundilFriday, 29. March 2013, 21:59 hodinky 12 years ago
    Sorry, but I think there's a misunderstanding. Maybe I haven't explained the problem clearly enough or maybe I don't understand the answers.

    On the examples above you explain how to create a table and add rows inside. Those rows are objects that already exist, like a condition that is already stored in the Visionaire Conditions table.

    What I need is the opposite: I don't want to store in a new table objects that already exist, but to store in an existing Visionaire table objects that do not exist yet. I want a completely new condition object, that is nowhere (as it doesn't exist yet) into the existing visionaire conditions table (in data structure docs its name seems to be TCondition).

    Thanks for your time, and sorry for the misunderstanding.

    Bažant

    19 Posts

  • #6, z afrlmeFriday, 29. March 2013, 23:17 hodinky 12 years ago
    ahh ok - sorry razz

    I will look into it later - off for something to eat now.

    Imperátor

    7285 Posts

  • #7, z afrlmeSaturday, 30. March 2013, 01:16 hodinky 12 years ago
    I think this is the documentation you should be looking at: http://wiki.visionaire2d.net/index.php?title=DataStructCmds

    tells you how to create objects & do various other things with LUA - I'm not sure about the syntax examples as I often have trouble understanding the examples Alex has added to the pages.

    P.S: you've piqued my interest a wee bit with all your requests for using LUA - I'm wondering why you are wanting to do certain things which would be much simpler done via the editor itself?

    also I'm not entirely sure but I think if you added the createObject command inside of a table, it would create whatever you added, then & there - I think?

    Finally: I will get around to adding the data structure commands to the new wiki at some point & try & add some clear examples as well as the syntax; when I've figured out how each of them work!

    Imperátor

    7285 Posts

  • #8, z DundilSaturday, 30. March 2013, 11:18 hodinky 12 years ago
    Thanks a lot! That URL is very very interesting. I didn't see it.

    About my reasons to do things in LUA, well... I come from programming, more than design. Reasons to ask these things:

    1. Many objects in my learning-project have the same code and I feel much more comfortable watching the initial definitions in plain text (LUA code) than going one by one copying actions.
    2. I know it is not mandatory for me to know this, but I need to feel I control the languages I work with, and until some weeks ago LUA was like a big mistery with strange data structures.
    3. Once I have some flexible functions to give objects or characters some behaviours, assigning them is just a line of code. For me it is much easier, although it may take more time at the beginning. I think changes are faster, but I'll tell you soon :-)


    Anyway, this information opens a new world to me, thanks. I hope soon I can add a post in the forums to show you the way I like to work. Some general functions may be for some use for anybody who wants to make some more complex scripts.

    Regards and thanks a lot!

    Bažant

    19 Posts

  • #9, z AlexSaturday, 30. March 2013, 11:44 hodinky 12 years ago
    you should not use the data struct commands. Maybe it works out to use some of them but in general they were designed for internal use in the editor. You should use the
    player specific commands
    e.g. if you want to start an animation use the startAnimation command.

    Čestný člen

    378 Posts

  • #10, z afrlmeSaturday, 30. March 2013, 11:45 hodinky 12 years ago
    thanks for the reply wink

    both me & mowren were/are interested in adding a pause/delay/sleep type function between lines of lua code to work in a similar way as the pause action part does by waiting until the set time has ended before continuing the rest of the lines below or whatever is wrapped in a function or if else query. - I figured out a way to do this using the getTime command, but it's not a very clean method.

    I agree with you on using LUA/code is much quicker than having to browse here, there, click this & that in the editor as you can do it on a single page by typing a few lines & search for a line of code you need to alter directly. - are you writing code inside of the VS editor or using another application? (I use sublime text editor)

    things like conditions & values though - I would recommend creating them via the editor so they are all available on game launch (I tend to create them in scene value tab or on my main character as global values)

    here are the visionaire player commands I have written up so far - most of them are more or less finished but I need to sort a few more examples for some of them. also the audio commands are for the next release for use with openAL & won't work in the current release.

    Imperátor

    7285 Posts

  • #11, z DundilSaturday, 30. March 2013, 11:56 hodinky 12 years ago
    About the "timer" function, it's interesting. I'll think on it.

    Editor: I use Notepad++, out of VS editor, yes. I import the script files at the beginning as I saw in a forum post.

    Global values... At the beginning I had an object called "GLOBAL", to store all of them. Now I just add them in an "init" function.

    Finally, about functions I've created, for the moment just some of the basic ones: addItemToChar, removeItemFromChar and things like that, so all the other scripts become clearer.

    Bažant

    19 Posts