• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Getting Pre-Placed Units

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

This is probably something that I should know, but I don't :wink:
How can I get pre-placed units in vJASS? I have tried this:

JASS:
scope TestSystem initializer OnInit

    private function OnInit takes nothing returns nothing
        local unit u = gg_unit_h001_0002
    endfunction

endscope

But it gives errors. I've also tried with a 0.0 timer, but with the same errors. The main error that I can't solve:
Undeclared variable: gg_unit_h001_0002
It happens in this function:

JASS:
function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p= Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set gg_unit_H000_0001=CreateUnit(p, 'H000', - 205.2, - 560.6, 270.000)
    call SetHeroLevel(gg_unit_H000_0001, 10, false)
    call SetUnitState(gg_unit_H000_0001, UNIT_STATE_MANA, 690)
    set gg_unit_h001_0002=CreateUnit(p, 'h001', - 728.7, 532.3, 315.000)
    set u=CreateUnit(p, 'h002', - 861.7, 380.0, 270.000)
    set u=CreateUnit(p, 'h002', - 718.2, 364.7, 270.000)
    set u=CreateUnit(p, 'h002', - 611.2, 392.3, 315.000)
    set u=CreateUnit(p, 'h002', - 548.9, 473.5, 0.000)
    set u=CreateUnit(p, 'h002', - 547.4, 602.6, 0.000)
endfunction

Any help would be appreciated :D

Thanks,

Mr_Bean
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
either, or make some simple trigger and try placing those preplaced units there(something like move unit instantly, that should allow usage of those vars, at least until next trigger save, I never tried after reopening the map)

if you are going to create those units with vJass tho, force compiler error(write a to somewhere) and copy content of CreateUnitsForPlayer function and place it to some init trigger, give them some variables or one big array of units, and you can reference those for further use
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Why don't you create them yourself?

JASS:
// System does this:
set gg_unit_h001_0002=CreateUnit(p, 'h001', - 728.7, 532.3, 315.000)

//So, do this:

call GroupEnumUnitsInRange(g, 1, -728.7, 532.3, null)
 
Last edited:
Level 17
Joined
Feb 11, 2011
Messages
1,860
I think you got the arguments the wrong way around for the second statement.
Thanks, but I found a way around it. I created a temporary unit variable in the Variable Editor and then set it to each pre-placed unit. Then I can successfully access the globals, such as gg_unit_h001_0001.
 
Status
Not open for further replies.
Top