Page 1 of 1

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

Posted: 03 Dec 2009, 00:39
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

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

Posted: 03 Dec 2009, 01:21
by CarRepairer
Need two equals signs.

Code: Select all

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

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

Posted: 03 Dec 2009, 05:29
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.

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

Posted: 03 Dec 2009, 13:15
by MacWarrior
Thanks! That did it.

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

Posted: 03 Dec 2009, 20:12
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.

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

Posted: 03 Dec 2009, 23:00
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.

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

Posted: 04 Dec 2009, 00:46
by knorke
well, in c/c++ anything not 0 means true so you are both correct i think.

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

Posted: 04 Dec 2009, 10:41
by Tobi
According to that interpretation assigning 0 to some variable can never be successful ;-)