• 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.

[JASS] What's wrong here? O_o

Status
Not open for further replies.
Level 3
Joined
Feb 20, 2007
Messages
32
I'm lost, I've been writing and rewriting this for an hour, I dont get what is wrong here >.<. This should find a unit in a small terrain block and return a handled id.

Here's my code to give it an id:

JASS:
//blah
  set cnt = CreateUnit(Player(11), 'h006', x, y, 90)
  call RegisterWheel(cnt)
//blah

function RegisterWheel takes unit u returns nothing
 local gamecache g = LocalVars()
 local integer I = GetHandleInt(g, "Wheels")
 call SetHandleInt(u, "Wheelid", I)
 call SetHandleHandle(g, "Wheel" + I2S(I), u)
 call SetHandleInt(g, "Wheels", I + 1)
endfunction

JASS:
function IsWheelAtPoint takes real x, real y returns integer
 local group g = CreateGroup()
 local unit u = null

 call GroupEnumUnitsInRange(g, x, y, 64.0, null)

 loop
  set u = FirstOfGroup(g)
  call GroupRemoveUnit(g, u)
  if(GetUnitTypeId(u) == 'h006')then
   call DestroyGroup(g)
   set g = null
   call BJDebugMsg("vomg")
   return GetHandleInt(u, "Wheelid")
  endif
  exitwhen(u == null)
 endloop
 call DestroyGroup(g)
 set g = null

 return -1
endfunction

This always returns -1. It doesnt matter if the unit is created on the x/y coord used to find it. I'm baffled, what did I do wrong here?
 
Level 11
Joined
Jul 12, 2005
Messages
764
Hm.. Try this:
JASS:
function IsWheelAtPoint takes real x, real y returns integer
 local group g = CreateGroup()
 local unit u = null
 local integer i = -1
 call GroupEnumUnitsInRange(g, x, y, 64.0, null)
 loop
  set u = FirstOfGroup(g)
  call GroupRemoveUnit(g, u)
  if GetUnitTypeId(u) == 'h006' then
   //call BJDebugMsg("vomg")
   set i = GetHandleInt(u, "Wheelid")
   set u = null
  endif
  exitwhen u == null
 endloop
 call DestroyGroup(g)
 set g = null
 return i
endfunction
But in the first jass-block, shouldn't the function RegisterWheel be above the "blah-blah" part? Or is it, and you just messed it here?
 
Level 3
Joined
Feb 20, 2007
Messages
32
Yeah, in the actual code it's below the //blah stuff.

...I just figured out my problem, GroupEnumUnits doesnt work on locusted units. Dammit bliz >.<. Well, I revised my code and treated the unit as an x/y coord rather than a unit, it works now. That's one pesky bug >.<.

Sorry to bother you guys, and thanks for the help pask.
 
Status
Not open for further replies.
Top