• Calling a function within an array from within a sub array OF that array.
    8 replies, posted
[code]local ShittyScript = { Functions = { ["Negro"] = function( a ) print("[Negro]: " .. a); end }, SeperateShit = { ["DoThatNegro"] = function() --ShittyScript.Functions["Negro"]("Oh shit nigga you be doin me!") end } }[/code] The problem is: I can do seperately [b]ShittyScript.Functions["Negro"]("Lylz")[/b], and it will print "[Negro]: Lylz" in console, but I can't figure out how to call a function from WITHIN an array to the array that it's within. [code]MainArray -> { FirstSubArray -> { Function1() } SecondSubArray -> { Function2() { Call Function1() } } }[/code]
Say we use this: [lua]MainArray = { FirstSubArray = { ["func1"] = function(arg) print(arg); end; }, SecondSubArray = { ["secondfunc"] = function() MainArray.FirstSubArray.func1("hi"); end; }, } MainArray.SecondSubArray.secondfunc() > "hi"[/lua] Fixed it. And that above works.
I've already tried that, it returns a nil value. [code][lua\Blackpeople.lua:89] attempt to index global 'ArrayNegro' (a nil value) B[/code]
I've just tested it. And it works What's the full code?
You tested that exact code? Because that exact has errors, could you copy over your exact block that works for you?
I did. [lua] MainArray = { FirstSubArray = { ["func1"] = function(arg) print(arg); end; }, SecondSubArray = { ["secondfunc"] = function() MainArray.FirstSubArray.func1("hi"); end; }, } MainArray.SecondSubArray.secondfunc() [/lua] That exact code works. [editline]3rd March 2012[/editline] [img]http://puu.sh/jhCH[/img]
Oh okay thanks, I figured out my problem. Apparently if [code]local MainArray = {[/code] is localized, you can't call or get anything within it from inside of it.
Oh, yes. I forgot to mention about that. Sorry.
It's okay, thanks!
Sorry, you need to Log In to post a reply to this thread.