script error '=' and ')' I don't get it....

script error '=' and ')' I don't get it....

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
MacWarrior
Posts: 2
Joined: 02 Dec 2009, 04:52

script error '=' and ')' I don't get it....

Post by MacWarrior »

I have tried to hack a lua script (my first) and found the following problem. I do not understand the error. Can someone tell me what I need to do to correct this error?


From the info.txt log......
Failed to load: my_unit_Marker.lua ([string "C:\Program Files\Spring\LuaUI\Widgets\my_unit_Marker.lua"]:62: ')' expected near '=')


line 62 of the script......

if ((UnitDefs[uDefID].name) = 'armbrtha') then

local x, y, z = spGetUnitPosition(uID)
spMarkerAddPoint(x, y, z, "Bertha")

end
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: script error '=' and ')' I don't get it....

Post by CarRepairer »

Need two equals signs.

Code: Select all

if ((UnitDefs[uDefID].name) == 'armbrtha') then
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: script error '=' and ')' I don't get it....

Post by Beherith »

= assigns a value, it usually returns true when the assigning was successful. But since Lua is typeless, all assigns succeed
== compares two values, returns true if equal.
MacWarrior
Posts: 2
Joined: 02 Dec 2009, 04:52

Re: script error '=' and ')' I don't get it....

Post by MacWarrior »

Thanks! That did it.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: script error '=' and ')' I don't get it....

Post by CarRepairer »

Beherith wrote:= assigns a value, it usually returns true when the assigning was successful.
Not in lua, hence the context error, which turned out to be a good thing in this case.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: script error '=' and ')' I don't get it....

Post by Tobi »

In which languages does it actually do that?

In the ones I know it either returns nothing and it's illegal to use it where a result is expected (like in Lua), or it returns the value that was assigned (like in C/C++/C#, etc.) so you can assign the same value to multiple variables at once.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: script error '=' and ')' I don't get it....

Post by knorke »

well, in c/c++ anything not 0 means true so you are both correct i think.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: script error '=' and ')' I don't get it....

Post by Tobi »

According to that interpretation assigning 0 to some variable can never be successful ;-)
Post Reply

Return to “Lua Scripts”