License from €75 Log in
DE EN FR ES IT CZ

Lua tables in defination script[SOLVED]

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 3 years ago
    Hello!

    I use tables in my scripts. The question arose, is it possible and how to create a table in the definition script and refer to it in all these scripts? (In order not to duplicate the same table in different scripts)

    Does it have to be placed in a function so that it can be referenced or what?

    Thanks
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 3 years ago
    Don't create it as local & you can access it in any script you like.

    t_example = {}

    instead of...

    local t_example = {}

    Just make sure you use an original name for the table as it can be accessed/updated from anywhere.

    Also, I would really recommend joining our discord server, if you aren't already on it as you will get a much faster response there.

  4. · 3 years ago
    Cool, thanks. Ok.

    A follow-up question...

    After the tables were translated into global ones, the names of the objects stopped responding to the selected language. (in the tables, the names of the objects that they take from the tab of the object's properties, i.e. their name for each language).

    There was no such problem with local tables...
    What could be the problem?

    example:

    t_items_nam = {
    [1] = Objects["itm1"]:getTextStr(VObjectName),
    [2] = Objects["itm2"]:getTextStr(VObjectName),
    [3] = Objects["itm3"]:getTextStr(VObjectName),
    [4] = Objects["itm4"]:getTextStr(VObjectName),
    [5] = Objects["itm5"]:getTextStr(VObjectName),
    [6] = Objects["itm6"]:getTextStr(VObjectName),
    [7] = Objects["itm7"]:getTextStr(VObjectName),
    [8] = Objects["itm8"]:getTextStr(VObjectName),
    [9] = Objects["itm9"]:getTextStr(VObjectName),
    [10] = Objects["itm10"]:getTextStr(VObjectName),
    [11] = Objects["itm11"]:getTextStr(VObjectName),
    [12] = Objects["itm12"]:getTextStr(VObjectName)
    }
  5. · 3 years ago
    Hmm, not really sure why that would be. Do you have multiple objects in the project with the same names? Was there anything in the log about it? At a guess, I'd say it was either getting confused with which to access or it was trying to access them before the game has finished loading.

    Also, you don't need to include the index numbers in brackets when you write tables like that...

    t_items_nam = {
    
    
    
    Objects["itm1"],
    
    Objects["itm2"],
    
    Objects["itm3"],
    
    Objects["itm4"],
    
    Objects["itm5"],
    
    Objects["itm6"],
    
    Objects["itm7"],
    
    Objects["itm8"],
    
    Objects["itm9"],
    
    Objects["itm10"],
    
    Objects["itm11"],
    
    Objects["itm12"]
    
    
    
    }

    I would recommend querying the textStr function when you want to grab the text as that way it will be accessed when you need it instead of storing the data in the table at the beginning - just in case you are updating the strings belonging to the values.
    print( t_items_nam[1]:getTextStr(VObjectName) )

    You could also use iteration if you want to access & print out each of them - assuming all the values are actually named like you've named them in the table above...

    for i = 1, 12 do
    
     print( Objects["itm" .. i]:getTextStr(VObjectName) )
    
    end
  6. · 3 years ago
    It's ok, I found the error, Thanks

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?