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

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

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

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

Post 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.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

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

Post 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.
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

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

Post by yanom »

ah. that fixed it.
Post Reply

Return to “AI”