Deltanic Posted January 28, 2011 Share Posted January 28, 2011 function someFunc.["someString"] ( a, b, c ) end function someFunc.["anotherString"] ( a, b, c ) end Just wondering if that could work, or is there any other way to achieve this? Link to comment
eAi Posted January 28, 2011 Share Posted January 28, 2011 What are you trying to achieve? Link to comment
DakiLLa Posted January 28, 2011 Share Posted January 28, 2011 You mean this? local someFunc = {} someFunc["someString"] = function ( a, b, c ) end --etc. Link to comment
Deltanic Posted January 28, 2011 Author Share Posted January 28, 2011 What are you trying to achieve? Creating a template system, where you can change your template ingame. But that isn't really relevant 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
Deltanic Posted January 30, 2011 Author Share Posted January 30, 2011 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
SDK Posted January 30, 2011 Share Posted January 30, 2011 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
Deltanic Posted January 30, 2011 Author Share Posted January 30, 2011 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 So thanx, it works now Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now