| 12-06-2009, 06:18 PM | #1 |
Alright, my problem is when I call "SetUnitOwner", it wants me to pass a unit object, but I have a long list of locations, so I am looping them. But when attempting to pass a joined string of the unit, it tells me I "cannot convert string to unit". I have looked everywhere for a function that I can call to convert the object ID to a unit object with no luck. If I pass the actual string, no quotes of course. It treats it like a unit object just fine, but the location number needs to be dynamic based on my array list. JASS:call SetUnitOwner(gg_unit_hbar_0001, Player(0), true ) // WORKS JASS:call SetUnitOwner("gg_unit_hbar_"+Locations[c], Player(0), true ) // DOES NOT WORK I have already tried using a group instead of an array and tried using a unit array, both say undeclared variable "gg_unit_hbar_xxxx", where xxxx = object ID JASS:
local string array Locations
set Locations[0] = "0056"
set Locations[1] = "0145"
set Locations[2] = "0151"
set Locations[3] = "0148"
set Locations[4] = "0154"
set Locations[5] = "0157"
set c = 0
loop
exitwhen c >= 4
// Assign Ownership
//call SetUnitOwner(gg_unit_hbar_0001, Player(0), true )
call SetUnitOwner("gg_unit_hbar_"+Locations[c], Player(0), true )
set c = c + 1
endloop |
| 12-06-2009, 06:25 PM | #2 |
gg_unit_hbar_0001 is a global variable poiting to a unit. The name of the variable can't be manipulated by other functions. To do this you need to use textmacros. I don't know however if looping textmacros have been added yet. |
| 12-06-2009, 06:48 PM | #3 |
What you need is a unit array. JASS:local unit array u set u[0]=gg_unit_hbar_0056 set u[1]=gg_unit_hbar_0145 set u[2]=gg_unit_hbar_0151 //... call SetUnitOwner(u[c], Player(0), true ) |
