Jump to content

Is this possible?


Deltanic

Recommended Posts

What are you trying to achieve?

Creating a template system, where you can change your template ingame. But that isn't really relevant :P

You mean this?
  
local someFunc = {} 
someFunc["someString"] = function ( a, b, c ) 
end 
  

Probably, yes. Now, is the syntax to use it this?

  
local a = 1 
local b = 2 
local c = 3 
someFunc["someString"] ( a, b, c ) 
  

That doesn't look correct, does it?

Link to comment

Oh, okay. Thanx then, it's what I wanted :)

Wait. I had the time today to try it, but it doesn't work.

  
-- cfg.lua 
loadTemplate = {} 
usedTemplate = "default" 
  
-- loadgui.lua 
if loadTemplate[template]() then -- ERROR: Attempt to index global 'loadTemplate' (A nil value) 
    -- stuff 
end 
  
-- default.lua 
loadTemplate["default"] = function ( ) 
    -- Loads of unimportant stuff 
end -- ERROR, yes, here, at the last line of the function: 
-- Attempt to call field '?' (A nil value) 
  

And since I've never done something like this with functions, I don't know any way to solve this too :(

Link to comment

It seems like it should work tho, did you try putting it all in one lua file?

Also, this is another way of calling functions:

function test123() 
    outputChatBox("test123 executed") 
end 
  
local functionName = "test123" 
  
_G[functionName] ()   --  test123 executed 

Link to comment

Lol, my game just crashes when putting it in one file:

  
loadTemplate                = {} 
usedTemplate                = "default" 
loadTemplate["default"] = function ( ) 
    -- stuff 
end 
  
if loadTemplate[usedTemplate]() then 
    -- stuff 
end 
  

Which is basically the same.

EDIT:

Oh, when doing this:

  
loadTemplate["default"] = function ( ) 
    -- stuff 
    return true -- watch this one 
end 
  

It will work.

-----------------------------------------------------

But I don't like the idea it all has to be in the same file. Can't the solution be to put cfg.lua at the top of meta.xml, and putting template.lua below? I thought meta.xml arranged the loading order too.

EDIT2:

Oh, re-arranging works. Though it looks ugly to use cfg.lua at the top :P So thanx, it works now :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...