Page 1 of 1

Trouble with Lua inside YMSAI (one of Conflict Terra's AI's)

Posted: 04 Jul 2011, 00:11
by yanom
so I have this code inside the gadget:UnitFinished function:

Code: Select all

if ((unitName (unitID) ~= "kdroneengineer") or (unitName (unitID) ~= "ktridroneroller")) then

			Spring.Echo( unitName(unitID) )
			Spring.Echo( "The above line better not say 'kdroneengineer'" )


			local x = math.random(Game.mapSizeX)

			local z = math.random(Game.mapSizeZ)

			Spring.GiveOrderToUnit(unitID, CMD.FIGHT , {x, Spring.GetGroundHeight (x,z), z  }, {})

		end
it's supposed to GiveOrderToUnit to send it to a random location if and only if the unit's name is not kdroneengineer or ktridroneroller . However, this check isn't working - all units get the order to go to a random location, even if they are the kdroneengineer unit. Infact, I get this output ingame whenever the AI makes a kdroneengineer unit:

Code: Select all

kdroneengineer
the above line better not say 'kdroneengineer'
Can anyone help me with this? I'm not really an experienced Lua coder, and besides, knorke wrote most of this code, not me.

Re: Trouble with Lua inside YMSAI (one of Conflict Terra's AI's)

Posted: 04 Jul 2011, 00:42
by Kloot

Code: Select all

if ((unitName (unitID) ~= "kdroneengineer") or (unitName (unitID) ~= "ktridroneroller"))
==>

Code: Select all

if ((x != A) or (x != B))
==>

Code: Select all

if (P or Q)
==>


if x is A, then Q = (x != B) is true and the check succeeds
if x is B, then P = (x != A) is true and the check succeeds
if x is C, then P = (x != A) and Q = (x != B) are both true and the check succeeds
if x is D, then P = (x != A) and Q = (x != B) are both true and the check succeeds
...
if x is Z, then P = (x != A) and Q = (x != B) are both true and the check succeeds

==>

'or' is not the operator you want here.

Re: Trouble with Lua inside YMSAI (one of Conflict Terra's AI's)

Posted: 04 Jul 2011, 02:43
by yanom
ah. that fixed it.