I'm learning Lua because I'm a having mappers block.
Now, I used the tutorials on the Garry's Mod Wiki page.
I combined everything in 1 Lua file because that is the easiest thing for now.
I get this error message when I run my Lua file:
[code]
lua\test.lua:11: attempt to index global 'Concommand' (a nil value)
[/code]
Line 11:
[lua]Concommand.Add("Number", whatIsMyNumber)[/lua]
I am trying to call this function:
[lua]function whatIsMyNumber()
print("myNumber is "..myNumber)
end [/lua]
myNumber is changing over the lua file, first value being 0, last value being 10.
Can anyone tell me why it is returning that error?
I think it has something to do with myNumber because I can get a normal message printed in the console.
[URL="http://wiki.garrysmod.com/?title=Concommand.Add"]concommand[/URL] should be lowercase.
Oh god I feel stupid.
I can remember back in the days at high school where my teacher hammered on that in Java.
Thanks
[QUOTE=Wokkel;23149883]Oh god I feel stupid.
I can remember back in the days at high school where my teacher hammered on that in Java.
Thanks[/QUOTE]
Clearly he didnt hammer it hard enough
Zing!
[QUOTE=Wokkel;23149825]I'm learning Lua because I'm a having mappers block.
Now, I used the tutorials on the Garry's Mod Wiki page.
I combined everything in 1 Lua file because that is the easiest thing for now.
I get this error message when I run my Lua file:
[code]
lua\test.lua:11: attempt to index global 'Concommand' (a nil value)
[/code]
Line 11:
[lua]Concommand.Add("Number", whatIsMyNumber)[/lua]
I am trying to call this function:
[lua]function whatIsMyNumber()
print("myNumber is "..myNumber)
end [/lua]
myNumber is changing over the lua file, first value being 0, last value being 10.
Can anyone tell me why it is returning that error?
I think it has something to do with myNumber because I can get a normal message printed in the console.[/QUOTE]
You're also missing!
[lua]function whatIsMyNumber(myNumber)
print("myNumber is "..myNumber)
end [/lua]
not if he uses a var.
[QUOTE=Jova;23160816]not if he uses a var.[/QUOTE]
Wrong.
he can't use vars?
If he uses a global variable, it will work perfectly fine without giving it as an argument.
[QUOTE=coolmission;23175592]If he uses a global variable, it will work perfectly fine without giving it as an argument.[/QUOTE]
[lua]
] lua_run_cl function whatIsMyNumber(myNumber) print("myNumber is "..myNumber) end whatIsMyNumber(5)
myNumber is 5
] lua_run_cl function whatIsMyNumber() print("myNumber is "..myNumber) end whatIsMyNumber(5)
:1: attempt to concatenate global 'myNumber' (a nil value)
] lua_run_cl function whatIsMyNumber() print("myNumber is "..myNumber) end concommand.Add("Number", whatIsMyNumber)
] Number 5
:1: attempt to concatenate global 'myNumber' (a nil value)
[/lua]
[QUOTE=Cubar;23183006]] lua_run_cl function whatIsMyNumber(myNumber) print("myNumber is "..myNumber) end whatIsMyNumber(5)
myNumber is 5
] lua_run_cl function whatIsMyNumber() print("myNumber is "..myNumber) end whatIsMyNumber(5)
:1: attempt to concatenate global 'myNumber' (a nil value)
] lua_run_cl function whatIsMyNumber() print("myNumber is "..myNumber) end concommand.Add("Number", whatIsMyNumber)
] Number 5
:1: attempt to concatenate global 'myNumber' (a nil value)[/QUOTE]
Are you serious..?
How about this:
[lua]
myNumber = 5
function whatIsMyNumber() print("myNumber is "..myNumber) end[/lua]
Sorry, you need to Log In to post a reply to this thread.