Recurring Lua Error ('=' expected near '<eof>')

I’ve recently started trying to learn Lua, but my attempts to create a Lua program have been ruined by this recurring error:


'=' expected near '<eof>'

I’m beginning to think that what’s causing this error is me simply putting the Lua files in the wrong places. I’ve been putting them in:
lua/myprogram.lua
lua/myfolder/myprogram.lua
lua/autorun/client/myprogram.lua

But they never seem to work. Here’s my most recent piece of code, it’s a modified version of a wallhack that can also detect NPCs:



CreateClientConVar( "xray_enabled", 0, true, false )

hook.Add( "HUDPaint", "XRayVision", function()
	
	if ConVarExists( "xray_enabled" ) and GetConVar("xray_enabled"):GetInt() == 1 then
		
		for k,v in pairs ( ents.GetAll() ) do
			
			local Position = ( v:GetPos() + Vector( 0,0,80 ) ):ToScreen()
			local Name = ""
			local TextColor = Color(255, 255, 255, 255)
			
			if v:IsNPC() then
				
				Name = v:GetClass()
				
				if     v:Disposition(LocalPlayer()) == 1 then TextColor = Color(255, 100, 100, 255)
				elseif v:Disposition(LocalPlayer()) == 2 then TextColor = Color(100, 255, 100, 255)
				elseif v:Disposition(LocalPlayer()) == 3 then TextColor = Color(100, 100, 255, 255)
				elseif v:Disposition(LocalPlayer()) == 4 then TextColor = Color(100, 100, 100, 255) end
				
				draw.DrawText( Name, "MenuLarge", Position.x, Position.y, TextColor, 1 )
				
			elseif v:IsPlayer() then
				
				TextColor = Color(0, 255, 255, 255)
				if v == LocalPlayer() then Name = "" else Name = v:Name() end
				
				draw.DrawText( Name, "MenuLarge", Position.x, Position.y, TextColor, 1 )
				
			end
			
		end
		
	end
	
end )


Does anyone have any idea what’s causing this error?

I dont think the ) at the last end belongs there.

The ) at the end is to close the “hook.Add”.

That code works(AFAIK), post full code please.

Does it tell you at which line the error occurs? And how frequently does it appear?

Can’t really see anything wrong with your code, other than the fact that **[Entity.Disposition

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.Disposition)** appears to be serverside only. If you’re going to show NPCs differently depending on whether they are friendly or not, you’ll probably need to set a networked var serverside when a NPC is created.
But that wouldn’t give you such an error anyway, is that the only piece of code that you have?

The error always appears at line 1. It only appears once. Maybe it’s the way I’m running the Lua file from the console. The command I use is:



lua_run_cl path_to_file/myprogram.lua


I don’t have any other code, but I’m going to try to run the following and post back with the results:



for i=1,10 do 
	Msg("Hello!
") 
end


And thanks for noticing that Entity.Disposition is serverside, that would have been an extra headache to puzzle through since I’m still trying to wrap my head around serverside vs. clientside in general.

EDIT: Yup. I got the same error. The file was stored in lua/fortest.lua and I tried to run it with lua_run_cl as well as lua_run. Here’s a condump:



] lua_run_cl fortest.lua
[LuaCmd:1] '=' expected near '<eof>'
] lua_run fortest.lua
> fortest.lua...
[lua_run:1] '=' expected near '<eof>'



lua_openscript_cl path_to_file/myprogram.lua

Oh… I’m going to be really embarrassed if that’s what I was doing wrong. (Which it probably is.) I’m trying that now.

EDIT: Yup. That’s what I was doing wrong and now I’m really embarrassed. Well, at least now I know.

[lua]local xray = CreateClientConVar(“xray_enabled”, 1, true, false)

local TextColor = Color(255, 255, 255, 255)
local Name

hook.Add(“HUDPaint”, “esp”, function()
if xray:GetInt() == 1 then
for _, v in pairs(player.GetAll()) do
local pos = (v:GetPos() + Vector(0, 0, 80)):ToScreen()
if v:IsNPC() then
Name = v:GetClass()
if v:Disposition(LocalPlayer()) == 1 then
TextColor = Color(255, 100, 100, 255)
elseif v:Disposition(LocalPlayer()) == 2 then
TextColor = Color(100, 255, 100, 255)
elseif v:Disposition(LocalPlayer()) == 3 then
TextColor = Color(100, 100, 255, 255)
elseif v:Disposition(LocalPlayer()) == 4 then
TextColor = Color(100, 100, 100, 255)
end
elseif v:IsPlayer() then
TextColor = Color(0, 255, 255)
if v == LocalPlayer() then
return
else
Name = v:Name()
end
draw.DrawText(Name, “MenuLarge”, pos.x, pos.y, TextColor, TEXT_ALIGN_CENTER)
end
end
end
end)[/lua]

You did not make this.

yes i did?

Impossible, this code works.

[editline]9th March 2011[/editline]

Oh wait, there won’t be any text showing if its an npc, oh well, its still too good to be yours.

“oh, good one m8!”

[editline]9th March 2011[/editline]

wait why am i getting rated dumb for posting working code?

[editline]9th March 2011[/editline]

Also that just means that i beat your expectations ;D