Forum

> > CS2D > Scripts > Lua Error 'then' expected near '='
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Error 'then' expected near '='

4 replies
To the start Previous 1 Next To the start

old Lua Error 'then' expected near '='

Louie
User Off Offline

Quote
So i'm trying to make this lua for my map but i always get this error:
IMG:https://i.imgur.com/6KAAY9Q.png

heres my code
1
2
3
4
5
if entity= 7,5 typename=Info_Dom_Point int=2
then parse('spawnobject 8 8 5 0 0 2')
elseif entity= 7,5 typename=Info_Dom_Point int=1
then parse('spawnobject 8 8 5 0 0 1')
end
what did i do wrong? I'm still newbie at this scripting stuff

old Re: Lua Error 'then' expected near '='

DC
Admin Off Offline

Quote
To explain the problem a bit more:

A single = is an assignment (variable will have the value afterwards):
1
variable = value

Double = is a comparison (will be true if variable currently has that value):
1
if variable == value then ...

So simply remember this:
Always use == in if-conditions!

old Re: Lua Error 'then' expected near '='

Dousea
User Off Offline

Quote
This may help you.
1
2
3
4
5
6
7
if (entity(7, 5, "typename") == "Info_Dom_Point") then
	local team = entity(7, 5, "int0")
	
	if (team > 0) then
		parse("spawnobject 8 8 5 0 0 " .. team)
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview