User Tag List

Results 1 to 9 of 9

Thread: Get data from LUA tables, with LUA extension

  1. #1
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get data from LUA tables, with LUA extension

    I'm doing LUA for my project in another game engine, but I'd like to use MMF2 and the LUA extension to test my LUA script while displaying data from LUA tables

    I can't find a way to get data from LUA's global tables. I have quite many of them and need to retrieve values from them in various ways...

    Code:
    = missionlist.list[0].type[string]
    = libdata[0].lastfaction
    Now, I tried using the Get Public Variables expression, but it doesn't recognise the string "libdata[0].lastfaction" as an existing variable with number content. (I did confirm its content trough lua.exe)
    And with using the Call Function action and the Get Value Returns expression, I can't use string parameters to specify from what table I want to retrive data from.

    Does someone here have ideas how I can achieve this?
    I made a LUA function that returned the data by hardcoding the table's name and keys into the return command, but I really need to avoid creating extra LUA functions just for MMF access, since this is going to be for another game engine.

  2. #2
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    Seems like a complicated problem. I will have to think about how I want to fix this.

  3. #3
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    I found a solution!

    LUA has a function loadstring() that can load a string as a block, check its syntax and returns a usable global function of that new block. And if the syntax is invalid, an error is returned.
    So you can then run that function with an assert() function.

    Ex:
    Code:
    assert(loadstring(“return 0”))()
    This simply runs a function that returns 0, using a string parameter

    Then this is what I did in MMF2:
    Code:
    Always
    - (Lua object) : Call Function "runstring" with "return missionlist.total" with 1 return
    - (Counter) : Set Counter to LuaValRet("(Lua object), 0")
    And in the LUA script:
    Code:
    runstring = function(str)
     return assert(loadstring(str))()
     end
    So in the end, the Counter gets the numerical value found in the table missionlist at the key total :cool:
    This even makes it possible to add or modify objects in the loaded LUA script at the MMF runtime. Pretty awesome find!
    The only problem though is that if LUA returns a bool value (true, false) it makes MMF crash. I think this is because the LUA extension only supports numbers and strings.

  4. #4
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    Nice .

    I didn't know you could do functions like that in Lua O_o.

    I always use this syntax:

    Code:
    function runstring(str)
    return loadstring(str);
    end

  5. #5
    Clicker Multimedia Fusion 2

    Join Date
    Jun 2006
    Location
    Montreal, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    hehe, yeah well it's just like creating a variable and setting it to a function type.
    I'm used to doing this since I usualy build functions within table structures.

    fruitbasket = {
    content = {},
    material = "wood",
    addfruit = function() end,
    takefruit = function() end,
    }

    fruitbasket.addfruit = function(fruit)
    table.insert(fruitbasket.content, fruit)
    end

    fruitbasket.takefruit = function(index)
    local fruit = fruitbasket.content[index]
    table.remove(fruitbasket.content, index)
    return fruit
    end
    And I never even used the ;

  6. #6
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    That's what I like about Lua, it is flexible.

  7. #7
    Clicker Fusion 2.5 Developer

    Join Date
    Jun 2006
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    Dude, the syntax Lua allows is crazy! You should see that absurd way my buddy codes in Lua. I like Lua, but I can't even read it when he writes it. haha

  8. #8
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Århus
    Posts
    3,455
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    You should see the syntax for Scheme code or Standard ML of New Jersey :S

  9. #9
    Clicker Fusion 2.5 Developer

    Join Date
    Jun 2006
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Get data from LUA tables, with LUA extension

    Quote Originally Posted by Andos
    You should see the syntax for Scheme code or Standard ML of New Jersey :S
    WHY must you speak such evil! I was hoping I would never hear of ML again.

Similar Threads

  1. Data Storage Extension
    By Kracker in forum Android Export Module Version 2.0
    Replies: 10
    Last Post: 7th May 2013, 12:49 AM
  2. Storing Data in an Extension
    By Dines in forum Extension Development
    Replies: 1
    Last Post: 31st January 2012, 01:30 AM
  3. Tables of data?
    By alphabeta279 in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 2nd August 2011, 02:42 PM
  4. Extension Data
    By dingdong in forum Extension Development
    Replies: 0
    Last Post: 9th November 2008, 10:13 PM
  5. Best extension for saving data?
    By RaiFox in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 19th January 2007, 01:39 AM

Posting Permissions

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