This is the error I'm getting in the console:
[CODE] lua_openscript_cl autorun/client/polymorphism.lua
Running script autorun/client/polymorphism.lua...
[lua\autorun\client\polymorphism.lua:4] attempt to index global 'self' (a nil value
[/CODE]
This is "polymorphism.lua":
[lua]
local Funcs = {
File = "PolyMorphic.txt",
T = function()
if file.Exists(self.File) then
else
self.TT()
end
end,
TT = function()
f1 = self.TTT()
file.Write(self.File,
[[
function ]]..f1..[[()
print("test")
end
]]..f1..[[()
]])
end,
TTT = function()
ret = ""
for i = 1, math.random(25,30) do
ret = ret .. string.char(math.random(97, 122))
end
return ret
end
}
Funcs.T()
[/lua]
Could you help me out here? I have no idea why this wouldn't work.. Thanks.
In the function parameter put self (or anything else for that matter, but if you do replace self with that) inside.
[QUOTE=marvincmarvin;33237162]This is the error I'm getting in the console:
BLA
[/QUOTE]
There are anonymous functions, you have to declare the self parameter.
And you also need to call it Funcs:T() not . .
[lua]
local Funcs = {
File = "PolyMorphic.txt",
T = function(self)
if file.Exists(self.File) then
else
self:TT()
end
end,
TT = function(self)
f1 = self:TTT()
file.Write(self.File,
[[
function ]]..f1..[[()
print("test")
end
]]..f1..[[()
]])
end,
TTT = function(self)
ret = ""
for i = 1, math.random(25,30) do
ret = ret .. string.char(math.random(97, 122))
end
return ret
end
}
Funcs:T()
[/lua]
Facepunch fucked the formatting, posting again.
[editline]12th November 2011[/editline]
[QUOTE=Derek_SM;33238957]self would only be in metatables and such. Since it appears to be a table, in the function parameter put pl (or anything) and replace self with that.[/QUOTE]
Wrong.
@Wizard I basically said put something in the function parameter. Yeah I also said that it couldn't be self but still.
[QUOTE=Derek_SM;33248339]@Wizard I basically said put something in the function parameter. Yeah I also said that it couldn't be self but still.[/QUOTE]
You edited your post after my post...
Don't try to play the smartass here(thats my job).
Yes your point is? I don't want to confuse anyone here.
Anyways I simply restated what I had already said, more clearly.
Oh I'm sorry, did I piss you off you German fuck?
Sorry, you need to Log In to post a reply to this thread.