Hey guys, im just learnin lua from the tutorial on gmod wiki, and when i try n run the small scripts ive made in the console, they wont run, it just keeps comin up with this error message
:1: '=' expected near '<eof>'
Heres some of my code:-
Tables code:-
shelves={}
shelves[0]=20
shelves[1]=15
shelves[2]=17
shelves[3]=35
function howMany(onWhat)
Msg("There are "..shelves[onWhat].." things on thatshelf\n")
end
howMany(0)
howMany(1)
howMany(2)
howmany(3)
Function code:-
function myFunc()
Msg("I ran myFunc\n")
end
function whoRanMyFunc(who)
Msg(who.." ran myFunc\n")
end
myFunc()
whoRanMyFunc("Liam")
It should be
[lua]Msg("There are "..table.Count(shelves[onWhat]).." things on thatshelf\n")[/lua]
[QUOTE=Kialtia;19610259]It should be
[lua]Msg("There are "..table.Count(shelves[onWhat]).." things on thatshelf\n")[/lua][/QUOTE]
No it shouldn't.
You are probably calling lua_run, you need to use lua_openscript. I'm not noticing any problems in your script besides the uncapitalized howmany(3).
Make sure you use [noparse][lua][/lua][/noparse] tags next time. It makes the code easier for us to read.
[QUOTE=Nori;19610304]No it shouldn't.
You are probably calling lua_run, you need to use lua_openscript. I'm not noticing any problems in your script besides the uncapitalized howmany(3).[/QUOTE]
Then what is he trying to do?
your lua file did run. lua scripts just terminated when they encounter an error. this line:
:1: '=' expected near '<eof>'
is telling you where there is an error and means that it expected there to be a "=" at the eof (end of function). i think the :1: means what line the error is at, in this case, it is at line 1.
also, lua scripts are CaSe SeNsItIvE. so the values howmany and howMany are 2 different values. also it would be nice if you organized your script a little so it is easier to read.
[lua]
--Tables code:-
shelves = {}
shelves[0] = 20
shelves[1] = 15
shelves[2] = 17
shelves[3] = 35
function howMany(onWhat)
Msg("There are " .. shelves[onWhat] .. " things on thatshelf\n")
end
howMany(0)
howMany(1)
howMany(2)
howMany(3)
--Function code:-
function myFunc()
Msg("I ran myFunc\n")
end
function whoRanMyFunc(who)
Msg([who] .. " ran myFunc\n")
end
myFunc()
whoRanMyFunc("Liam")
[/lua]
there, i cleaned up your script a bit. here are some changes:
- add "--" in front if a line to make it a comment, comments are ignored
- added spacing to lines inside of functions to show which lines are under which functions
- fixed the case on howMany
hopefully this should work now.
[QUOTE=thlaughincheese;19615892]your lua file did run. lua scripts just terminated when they encounter an error. this line:
:1: '=' expected near '<eof>'
is telling you where there is an error and means that it expected an "=" at the eof (end of function). i think the :1: means what line the error is at, in this case, it is at line 1.
also, lua scripts are CaSe SeNsItIvE. so all the values howmany and howMany are 2 different values. also it would me nice if you organized your script a it so it is easier to read.
[lua]
--Tables code:-
shelves = {}
shelves[0] = 20
shelves[1] = 15
shelves[2] = 17
shelves[3] = 35
function howMany(onWhat)
Msg("There are " .. shelves[onWhat] .. " things on thatshelf\n")
end
howMany(0)
howMany(1)
howMany(2)
howMany(3)
--Function code:-
function myFunc()
Msg("I ran myFunc\n")
end
function whoRanMyFunc(who)
Msg([who] .. " ran myFunc\n")
end
myFunc()
whoRanMyFunc("Liam")
[/lua]
there, i cleaned up your script a bit. here are some changes:
- add "--" in front if a line to make it a comment, comments are ignored
- added spacing to lines inside of functions to show which lines are under which functions
- fixed the case on howMany
hopefully this should work now.[/QUOTE]
If it's :1: that means that it was done from lua_run because there is no file. He's trying to do lua_run myfile.lua, when he needs to do lua_openscript myfile.lua. Also, EOF is end of file
Why are there brackets around who?
woops silly me, at least i tried to help :(
Thanks for the help guys, ill come askin again if i get any more problems
Sorry, you need to Log In to post a reply to this thread.