Disfunctional lua parser on my friend's computer !

Hello all,

I just want to speak about a strange bug happening only on my friend’s computer. He owns Garry’s Mod too, so there is no downloaded GMod or other things as that.

So when he install my tools for RealisticRoleplay, his game is sending errors about a line which is commented !! Indeed I realy said a line that should normally be ignored !!
Seriously I never saw someone with this problem.

Note that this problem does not happen on server. Client side scripts while in server are correctly interpreted. That’s just when plays in Singleplayer.

What can cause that ? A c++ virus dll he downloaded ? A workshop addon ? A file system addon ?

Thanks by advance,
Yuri

It’s a Lua error. I’ve noticed that the line numbers come out wrong sometimes if you’re using /* */ style comments so look at the lines around it

Yes however it’s not crashing on my computer only on my friend’s computer.

I’ll give the code :



TOOL.Category		= "Engine Tools"
TOOL.Name			= "VC2 Helper"
TOOL.Command		= nil
TOOL.ConfigName 	= ""
TOOL.Tab            = "RealisticRoleplay"

if CLIENT then	
	language.Add("Tool.vc2_helper.name" , "RealisticRoleplay VC2 Helper")
	language.Add("Tool.vc2_helper.desc" , "Help using RealisticRoleplay's VC2Mod")
	language.Add("Tool.vc2_helper.0" , "Left-click to add a light to vehicle. Right-click to go next state. Use Reload to reset the car script generator tool.")
	
	net.Receive("RRP_VC2Helper_ScriptBegan", function(len, ply)
		local mainFrame = vgui.Create('DFrame', mainFrame)
		mainFrame:SetSize(408, 191)
		mainFrame:Center()
		mainFrame:SetTitle('VC2 Helper - Script began')
		mainFrame:SetSizable(true)
		mainFrame:SetDeleteOnClose(false)
		mainFrame:MakePopup()		

		local fuelSlide = vgui.Create('DNumSlider', mainFrame)
		fuelSlide:SetSize(386, 40)		
		fuelSlide:SetPos(11, 31)
		fuelSlide:SetText('Select Max Fuel')
		fuelSlide:SetValue(0)
		fuelSlide:SetMinMax(1, 100)

		local healthSlide = vgui.Create('DNumSlider', mainFrame)
		healthSlide:SetSize(386, 40)		
		healthSlide:SetPos(10, 89)
		healthSlide:SetText('Select Max Health')
		healthSlide:SetValue(0)
		healthSlide:SetMinMax(1, 1024)

		local okBut = vgui.Create('DButton', mainFrame)		
		okBut:SetSize(152, 34)
		okBut:SetPos(125, 150)
		okBut:SetText('OK')
		okBut.DoClick = function()			
			net.Start("RRP_VC2Helper_ScriptFirstVars")
				net.WriteInt(healthSlide:GetValue(), 8)
				net.WriteInt(fuelSlide:GetValue(), 8)
			net.SendToServer()
			mainFrame:Close()
		end
	end)
	
	net.Receive("RRP_VC2Helper_GenerateScript", function(len, ply) 
		local tb = net.ReadTable()
		local scrName = net.ReadString()
		
		local frame = vgui.Create("DFrame")
		frame:SetTitle("VehicleController 2 Script")
		frame:SetPos(10, 10)
		frame:SetDraggable(true)
		frame:SetSize(812, 512)
		frame:ShowCloseButton(true)
		
		local panel = vgui.Create("DPanelList", frame)
		panel:EnableHorizontal(true)
		panel:EnableVerticalScrollbar(true)
		panel:SetPos(0, 32)
		panel:SetSize(812, 400)
		
		local but = vgui.Create("DButton")
		but:SetSize(812, 32)
		but:SetText("Copy to clipboard")
		but.DoClick = function()
			local str = ""
			for k, v in pairs(tb) do
				str = str .. v .. "
"
			end
			SetClipboardText(str)
		end
		panel:AddItem(but)
		
		//Script display
		print("---------------SCRIPT_VC2---------------")
		for k, v in pairs(tb) do
			local b = vgui.Create("DButton")
			local len = string.len(v)
			if (len > 128) then			
				b:SetSize(812, 32)
			else
				b:SetSize(812 + len, 32)
			end
			b:SetText(v)
			panel:AddItem(b)
			print(v)
		end
		print("---------------SCRIPT_END---------------")

		frame:MakePopup()
		
		//File generation
		local files, folders = file.Find("lua/bin/*.dll", "GAME")		
		if (system.IsWindows() && table.HasValue(files, "gmcl_vc2helper_win32.dll")) then
			require("vc2helper") //Using C++ Hacking module to save at Desktop and to make some lua files !!
			local str = vc2helper_GetVersion()
			print("--> VC2HelperModule Using Version " .. str .. " <--")
			local desktop = vc2helper_GetDesktopDir()
			local dir = desktop .. "\\" .. "vc2_helper" .. "\\"
			if (!vc2helper_IsDirExisting(dir)) then
				vc2helper_CreateDir(dir)
			end
			local name = string.lower(scrName)
			local f = dir .. name .. ".lua"
			local data = ""
			for k, v in pairs(tb) do
				data = data .. v .. "
"
			end
			vc2helper_WriteFile(f, data)
		end
		//End
	end) //This is the line given by the error : unexpected symbol near ')'
	
	net.Receive("RRP_VC2Helper_StateChanged", function(len, ply)
		LocalPlayer():GetActiveWeapon().State = net.ReadInt(32)
	end)
	
	surface.CreateFont("VC2Helper", {
		font = "Arial Black", 
		size = 32, 
		weight = 900, 
		blursize = 0, 
		scanlines = 0, 
		antialias = true, 
		underline = false, 
		italic = true, 
		strikeout = false, 
		symbol = false, 
		rotary = false, 
		shadow = false, 
		additive = false, 
		outline = false, 
	})
	function TOOL:DrawHUD()
		if (!IsValid(LocalPlayer():GetActiveWeapon())) then return end
		
		self.State = LocalPlayer():GetActiveWeapon().State
		local txt = ""
		if (self.State == nil) then return end
		if (self.State == -1) then
			txt = "Script not began ; right-click vehicle first !"
		elseif (self.State == 0) then
			txt = "Left click to place front lights !"
		elseif (self.State == 1) then
			txt = "Left click to place back lights !"
		elseif (self.State == 2) then
			txt = "Left click to place left blinkers !"
		elseif (self.State == 3) then
			txt = "Left click to place right blinkers !"
		elseif (self.State == 4) then
			txt = "Left click to place head lights !"
		elseif (self.State == 5) then
			txt = "Left click to place road lights !"
		elseif (self.State == 6) then
			txt = "Left click to place brake lights !"
		elseif (self.State == 7) then
			txt = "Left click to set engine's position !"
		elseif (self.State == 8) then
			txt = "Left click to set car-chest's position !"
		elseif (self.State == 9) then
			txt = "Left click to place smoke's escapes !"
		elseif (self.State == 10) then
			txt = "Left click to place vehicle seats !"
		elseif (self.State == 11) then
			txt = "Script completed ; right-click to show script, and RELOAD to reset the tool !"
		end
		
		draw.DrawText(txt, "VC2Helper", ScrW() / 2, ScrH() - 128, Color(255, 0, 0), TEXT_ALIGN_CENTER)
	end
end

if SERVER then
	function TOOL:Think() //GMod Tool system hacker
		local v = player.GetAll()[1]
		if (v:GetActiveWeapon() != nil) then
			if (v:GetActiveWeapon().HackTable != nil) then
				for k1, v1 in pairs(v:GetActiveWeapon().HackTable) do
					v1(self, v:GetActiveWeapon())
				end
				table.Empty(v:GetActiveWeapon().HackTable)
				v:GetActiveWeapon().HackTable = nil
			end
		end		
	end

	util.AddNetworkString("RRP_VC2Helper_GenerateScript")
	util.AddNetworkString("RRP_VC2Helper_StateChanged")
	util.AddNetworkString("RRP_VC2Helper_OffsetChanged")
	util.AddNetworkString("RRP_VC2Helper_ScriptBegan")
	util.AddNetworkString("RRP_VC2Helper_ScriptFirstVars")
	
	net.Receive("RRP_VC2Helper_OffsetChanged", function(len, ply)		
		local weap = ply:GetActiveWeapon()
		weap.SeatYOffset = net.ReadFloat() * -1
		if (weap.HackTable == nil) then weap.HackTable = {} end
		table.insert(weap.HackTable, function(ent, weap)
			ent.SeatYOffset = weap.SeatYOffset
		end)
	end)
	
	net.Receive("RRP_VC2Helper_ScriptFirstVars", function(len, ply)
		local weap = ply:GetActiveWeapon()
		weap.MaxHealth = net.ReadInt(8)
		weap.MaxFuel = net.ReadInt(8)
		if (weap.HackTable == nil) then weap.HackTable = {} end
		table.insert(weap.HackTable, function(ent, weap)			
			ent.MaxHealth = weap.MaxHealth
			ent.MaxFuel = weap.MaxFuel
			ent.State = ent.State + 1
			net.Start("RRP_VC2Helper_StateChanged")
				net.WriteInt(ent.State, 32)
			net.Broadcast()
		end)
	end)
end

function TOOL:Deploy()
	self:ResetVC2HelperTool()
end

function TOOL:ResetVC2HelperTool()
	self.SeatYOffset = 0
	self.FrontLights = {}
	self.BackLights = {}
	self.LeftBlinkers = {}
	self.RightBlinkers = {}
	self.HeadLights = {}
	self.RoadLights = {}
	self.BrakeLights = {}
	self.VehicleSeats = {}
	self.VehName = ""
	self.EnginePos = Vector(0, 0, 0)
	self.ChestPos = Vector(0, 0, 0)
	self.SmokeEscapes = {}
	self.MaxHealth = 1
	self.MaxFuel = 1
	
	self.State = -1
	net.Start("RRP_VC2Helper_StateChanged")
		net.WriteInt(-1, 32)
	net.Broadcast()
end

function TOOL:LeftClick(tr)
	if CLIENT then return false end
	
	if (tr == nil) then return false end
	local entity = tr.Entity
	if (IsValid(entity) and entity:IsVehicle() and self.State > -1) then
		if (self.State == 0) then
			table.insert(self.FrontLights, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 1) then
			table.insert(self.BackLights, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 2) then
			table.insert(self.LeftBlinkers, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 3) then
			table.insert(self.RightBlinkers, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 4) then
			table.insert(self.HeadLights, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 5) then
			table.insert(self.RoadLights, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 6) then
			table.insert(self.BrakeLights, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 7) then
			self.EnginePos = entity:WorldToLocal(tr.HitPos)
		elseif (self.State == 8) then
			self.ChestPos = entity:WorldToLocal(tr.HitPos)
		elseif (self.State == 9) then
			table.insert(self.SmokeEscapes, entity:WorldToLocal(tr.HitPos))
		elseif (self.State == 10) then
			local vec = tr.HitPos
			vec:Add(Vector(0, 0, self.SeatYOffset))
			local ent = ents.Create("prop_vehicle_prisoner_pod")
			ent:SetModel("models/nova/airboat_seat.mdl")
			ent:SetKeyValue("vehiclescript", "scripts/vehicles/prisoner_pod.txt")
			ent:SetPos(vec)
			ent:SetParent(entity)
			ent:Spawn()
			table.insert(self.VehicleSeats, entity:WorldToLocal(vec))
			undo.Create("vc2_seat")
				undo.AddEntity(ent)
				undo.SetPlayer(self.Owner)
				undo.AddFunction(function(tab, arg2)
					table.removeValue(self.VehicleSeats, entity:WorldToLocal(vec))
				end)
			undo.Finish()
		end
		return true
	end
	
	return true
end

function table.removeValue(tbl, var)
	for k, v in pairs(tbl) do
		if (v == var) then
			table.remove(tbl, k)
			return
		end
	end
end

/**
* Script Generation functions
*/
function TOOL:GenerateSeatsPosScript()
	if (table.Count(self.VehicleSeats) == 0) then return {} end
	local strTable = {}

	local i = 0
	for k, v in pairs(self.VehicleSeats) do		
		table.insert(strTable, "		SEAT_" .. i .. " = {pos = Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. "), dir = Angle(0, 0, 0)},")
		i = i + 1
	end
	
	local str = table.GetLastValue(strTable)
	str = string.sub(str, 1, string.len(str) - 1)
	strTable* = str
	
	return strTable
end
function TOOL:GenerateFrontLightsArray()
	local str = "frontLights = {"
	for _, v in pairs(self.FrontLights) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end
function TOOL:GenerateBackLightsArray()
	local str = "backLights = {"
	for _, v in pairs(self.BackLights) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end
function TOOL:GenerateHeadLightsArray()
	local str = "headLights = {"
	for _, v in pairs(self.HeadLights) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end
function TOOL:GenerateRoadLightsArray()
	local str = "roadLights = {"
	for _, v in pairs(self.RoadLights) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end
function TOOL:GenerateLeftBlinkersArray()
	local str = "leftBlinkers = {"
	for _, v in pairs(self.LeftBlinkers) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end
function TOOL:GenerateRightBlinkersArray()
	local str = "rightBlinkers = {"
	for _, v in pairs(self.RightBlinkers) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end
function TOOL:GenerateBrakeLightsArray()
	local str = "breakLights = {"
	for _, v in pairs(self.BrakeLights) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end

function TOOL:GenerateLightPosScript()
	local front = self:GenerateFrontLightsArray()
	local back = self:GenerateBackLightsArray()
	local blkLeft = self:GenerateLeftBlinkersArray()
	local blkRight = self:GenerateRightBlinkersArray()
	local head = self:GenerateHeadLightsArray()
	local road = self:GenerateRoadLightsArray()
	local brake = self:GenerateBrakeLightsArray()
	
	local tbl = {}
	table.insert(tbl, "--Light Related")
	table.insert(tbl, front .. "//PosLights (FRONT)")
	table.insert(tbl, back .. "//PosLights (BACK)")
	table.insert(tbl, head)
	table.insert(tbl, road)
	table.insert(tbl, brake)
	table.insert(tbl, blkLeft)
	table.insert(tbl, blkRight)
	return tbl
end
/**
* End
*/

function TOOL:GenerateSmokeEscapesArray()
	local str = "smokeEscapes = {"
	for _, v in pairs(self.SmokeEscapes) do
		local vec = "Vector(" .. v.x .. ", " .. v.y .. ", " .. v.z .. ")"
		str = str .. vec .. ", "
	end
	str = string.sub(str, 1, string.len(str) - 2)
	str = str .. "},"
	return str
end

function TOOL:GetVehicleScriptName()
	local name = self.VehName	
	name = string.upper(name)	
	name = string.Replace(name, " ", "_")	
	return name
end

function TOOL:RightClick(tr)
	if CLIENT then return false end
	
	if (tr == nil) then return false end
	local entity = tr.Entity
	if (IsValid(entity) and entity:IsVehicle()) then
		if (self.State == -1) then
			self.VehName = entity.VehicleTable.Name			
			net.Start("RRP_VC2Helper_ScriptBegan")				
			net.Broadcast()			
			return false
		end
		if (self.State == 11) then
			net.Start("RRP_VC2Helper_GenerateScript")
				local strTable = {}
				table.insert(strTable, "local " .. self:GetVehicleScriptName() .. " = {")
				table.insert(strTable, "	--The name of the vehicle")
				table.insert(strTable, "	id = \"" .. self.VehName .. "\",")
				table.insert(strTable, "")
				for _, v in pairs(self:GenerateLightPosScript()) do
					table.insert(strTable, "	" .. v)
				end
				table.insert(strTable, "")
				table.insert(strTable, "	--Engine related")
				table.insert(strTable, "	enginePos = Vector(" .. self.EnginePos.x .. ", " .. self.EnginePos.y .. ", " .. self.EnginePos.z .. "),")
				table.insert(strTable, "	chestPos = Vector(" .. self.ChestPos.x .. ", " .. self.ChestPos.y .. ", " .. self.ChestPos.z .. "),")
				table.insert(strTable, "	" .. self:GenerateSmokeEscapesArray())
				table.insert(strTable, "	maxHealth = 100,")
				table.insert(strTable, "	maxFuel = 90,")
				table.insert(strTable, "")
				table.insert(strTable, "	--Passengers")
				table.insert(strTable, "	passengers = {")
				for k, v in pairs(self:GenerateSeatsPosScript()) do
					table.insert(strTable, v)
				end
				//table.insert(strTable, "		//Insert custom additional seats here")
				//table.insert(strTable, "		//SEAT_0 = {pos = Vector(0, 0, 0), dir = Angle(0, 0, 0)}")
				table.insert(strTable, "	}")
				table.insert(strTable, "}")
				table.insert(strTable, "")
				table.insert(strTable, "VC2:RegisterVehicleScript(" .. self:GetVehicleScriptName() .. ")")
				net.WriteTable(strTable)
				net.WriteString(self:GetVehicleScriptName())
			net.Broadcast()
			return true
		end
		self.State = self.State + 1
		net.Start("RRP_VC2Helper_StateChanged")
			net.WriteInt(self.State, 32)
		net.Broadcast()
		if (self.State == 11) then
			net.Start("RRP_VC2Helper_GenerateScript")
				local strTable = {}
				table.insert(strTable, "local " .. self:GetVehicleScriptName() .. " = {")
				table.insert(strTable, "	--The name of the vehicle")
				table.insert(strTable, "	id = \"" .. self.VehName .. "\",")
				table.insert(strTable, "")
				for _, v in pairs(self:GenerateLightPosScript()) do
					table.insert(strTable, "	" .. v)
				end
				table.insert(strTable, "")
				table.insert(strTable, "	--Engine related")
				table.insert(strTable, "	enginePos = Vector(" .. self.EnginePos.x .. ", " .. self.EnginePos.y .. ", " .. self.EnginePos.z .. "),")
				table.insert(strTable, "	chestPos = Vector(" .. self.ChestPos.x .. ", " .. self.ChestPos.y .. ", " .. self.ChestPos.z .. "),")
				table.insert(strTable, "	" .. self:GenerateSmokeEscapesArray())
				table.insert(strTable, "	maxHealth = 100,")
				table.insert(strTable, "	maxFuel = 90,")
				table.insert(strTable, "")
				table.insert(strTable, "	--Passengers")
				table.insert(strTable, "	passengers = {")
				for k, v in pairs(self:GenerateSeatsPosScript()) do
					table.insert(strTable, v)
				end
				//table.insert(strTable, "		//Insert custom additional seats here")
				//table.insert(strTable, "		//SEAT_0 = {pos = Vector(0, 0, 0), dir = Angle(0, 0, 0)}")
				table.insert(strTable, "	}")
				table.insert(strTable, "}")
				table.insert(strTable, "")
				table.insert(strTable, "VC2:RegisterVehicleScript(" .. self:GetVehicleScriptName() .. ")")				
				net.WriteTable(strTable)
				net.WriteString(self:GetVehicleScriptName())
			net.Broadcast()
		end
		return true
	end
	
	return false
end

function TOOL:Reload(tr)
	if CLIENT then return false end	
	
	self:ResetVC2HelperTool()	
	return true
end

function TOOL.BuildCPanel(panel)
	panel:SetSpacing(10)
	panel:SetName("RealisticRoleplay VC2-Helper")
	
	local lst = vgui.Create("DPanelList", panel)
	lst:SetSize(256, 256)
	lst:SetPos(0, 30)	
	lst:EnableHorizontal(false)
	lst:EnableVerticalScrollbar(true)
	lst:SetSpacing(10)
	
	local lbl = vgui.Create("DLabel")
	lbl:SetSize(256, 32)
	lbl:SetText("Choose seats Y-Offset")
	lst:AddItem(lbl)
	local lblChoosen = vgui.Create("DLabel")
	lblChoosen:SetSize(256, 32)
	lblChoosen:SetText("YOffset is 0")
	local numScr = vgui.Create("DNumberScratch")
	numScr:SetMin(0)
	numScr:SetValue(0)
	numScr:SetMax(100)
	numScr.OnValueChanged = function()
		lblChoosen:SetText("YOffset is -" .. numScr:GetFloatValue())
		net.Start("RRP_VC2Helper_OffsetChanged")
			net.WriteFloat(numScr:GetFloatValue())
		net.SendToServer()
	end
	lst:AddItem(numScr)
	lst:AddItem(lblChoosen)
end


Replace all C style comments with respectively and –[[ ]] blocks.
The C style ones are just an addition to Gmod Lua, and they seem to occasionally break the line numerations in error messages.

What the f*** ?! The script works fine on my friend’s computer when not using // or // or /*/ !

This is the internet, you can swear.

fk i didn’t know that, thank exo skeleton !

also i reccommend not using // and /* */ ever in glua they are terrible additions and i am pretty sure they are preprocessed and not actually in the lua parser

The only issue is with multi-line C-style comments and only when you have multiple newlines in a row.

Anyways that’s a bit strange because some computers including my own, are not returning any error the code executes correctly. This happens at my knowledge only on his computer. Many others tried my helpers and no ones got this problem.

He doesn’t seams to get any errors when working on Server. If I host the server and he downloads client side scripts with CStyle comments it’s not causing any errors, that happens only in Singleplayer. Which makes this bug realy weird…

What error is he getting?