Predefined unit returns (null) with registered to system

Embrace_It

New Member
Reaction score
9
Yet another problem...This is a weird one though.

I have a system that can only register heroes.
I created a custom hero, and to further test the system I created another hero by copying the data from the first hero. I added the following debug message to the function, that checks whether or not the unit provided is a hero:

JASS:

call GetUnitName(whichhero)


This outputs "(null)", which doesnt make sense. I call the function with gg_unit_O001_0009 as the unit argument. This works fine for hero 1, but not for unit 2. I then tried to create a hero from scratch, but it didnt work either.

The function tests like this:

JASS:

if not IsUnitType(whichhero, UNIT_TYPE_HERO) then
    call PassError("Must register talents for heroes only")
    return
else
    set id = GetHandleId(whichhero)
endif


Unless someone has an explain for this based on the above, I wont post the code for the system if it isnt necessary.

Thanks! :)
 

Embrace_It

New Member
Reaction score
9
Perhaps the string table is not initialised (yet).

What do you mean?

I forgot to mention that when I save the map, it sometimes pops 1 error message: "Undeclared variable gg_unit_O001_0009". It seems this predefined global variable is either not created, or not created properly.
 

Prozix

New Member
Reaction score
7
It is a preplaced unit right? Maybe, just maybe you have deleted this unit which means it doesn't exist anymore. The name of an unit that doesn't exist doesn't exist either^^
Maybe there is a problem with the initialization of the variable "whichhero". Where and how do you initialize it?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Even if you can guess the variable name of preplaced unit, you have to select them with a gui condition/action (one time is enough and can you can delete the gui stuff after the selection), or the variable won't be created at all.
As simple and annoying as that.
 

Embrace_It

New Member
Reaction score
9
I usually create a trigger, make an action for killing a unit, select the unit I want and "Convert to Custom Text" it, so that I can see the preplaced unit's id/variable.

I have not deleted the unit.
 

Embrace_It

New Member
Reaction score
9
Solved!....Somewhat...

I noticed that there HAS to be a trigger of some kind using the preplaced unit's id (fx. gg_unit_O001_0009) for this to work. If you deleted the trigger(s) it doesnt work since the values are set to null. In this case I have a trigger that increases all heroes' levels in the map when Player 1 enters "-lvlup"...

If someone has an alternative, please show me :)

As always, thanks for the help/advice!
 

Prozix

New Member
Reaction score
7
May I ask why you have preplaced heroes? If users pick a hero you could put them in a
JASS:
unit array heroes

and do stuff with them when you need to
doing things for one player could be done like this
JASS:
local integer i = 0
loop
  if GetOwningPlayer(heroes<i>) == thePlayer then
    //dostuff
  endif
  set i = i+1
  exitwhen i==MAXHEROES
endloop</i>

//untested
 

Embrace_It

New Member
Reaction score
9
@ Prozix: True, but this is a map for testing purposes, so I have preplaced units for testing.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top