Username:


Password:


Remember me


  • Find Us On Facebook



Compare unitname or id with a string in a procedure

Have a question about how to do something in the datafiles? Ask it here, we'll help if we can. NOTE: We cannot teach you how to use ABCREATE or how our files work, we don't have the time.

Compare unitname or id with a string in a procedure

#1  Postby 2XS » Sat May 09, 2009 11:52 am

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
User avatar
2XS
Recruit
Recruit
 
Posts: 2
Joined: Sun Sep 21, 2008 12:00 am

#2  Postby Spack » Sun May 10, 2009 7:52 am

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.
Dan
AB40k Site Admin/Beta Tester
Age of Strife Owner/Admin: http://www.ageofstrife.com
Gaming Figures Partner/Admin: http://www.gamingfigures.com
User avatar
Spack
Site Admin
Site Admin
 
Posts: 1150
Joined: Sat Jul 08, 2006 12:00 am

#3  Postby 2XS » Sun May 10, 2009 10:38 pm

Thank you for the reply, but it is "=". I also tried "==" because I know it from programming C.


Greetz,

Andy
User avatar
2XS
Recruit
Recruit
 
Posts: 2
Joined: Sun Sep 21, 2008 12:00 am


Return to Datafile Programming Support

Who is online

Registered users: No registered users

cron