Page 1 of 1

Compare unitname or id with a string in a procedure

PostPosted: Sat May 09, 2009 11:52 am
by 2XS
Hello all,

how can I access the name of a unit in a script?

I tried it this way, but it didn't work.


Code: Select all
~ This procedure adds one 'Scythe' tag to the unit for every instance of this option taken.
~ For Tyrant Guards only add a single 'Scythe' tag to the unit

var i as number
var selcount as number
var result as number
var unitname as string
var unitid as string

selcount = selection
unitname = "Tyrant Guard"
unitid = "tyTyrGuard"

if ([b]this.unit.name = unitname[/b]) then
  result = unit.assign[tyTags.Scythe]
else
  for i = 1 to selcount
    result = unit.assign[tyTags.Scythe]
  next
endif


My problem is the bold marked part of the IF statement. Either all units jump into the else part or in the then part. But there is no difference if the unit is tyrant guard od not...


Many thanks in advance,

Andy

PostPosted: Sun May 10, 2009 7:52 am
by Spack
I don't know how the language works for AB, but in some languages you need to use == in an if comparison for equivalence as = is for assigning.

PostPosted: Sun May 10, 2009 10:38 pm
by 2XS
Thank you for the reply, but it is "=". I also tried "==" because I know it from programming C.


Greetz,

Andy