• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Enumeration does not work

Status
Not open for further replies.
JASS:
....
    nothing defaults nothing
    module Missile_Collisions_Unit
	public	boolean	hitsUnits		= true
	public	boolean	hitsUnitsOnZ	= false
	private	group	enumedUnits		= null
        private static  boolexpr    unitFilter  = null
	
	....
		
        private static method enum takes nothing returns boolean
	    local thistype	this	= thistype.self
            local unit		u 		= GetFilterUnit()
            local real		z 		= 0.
            local boolean	collide	= true
            
            call BJDebugMsg("Before GroupCheck")
            //if IsUnitInGroup(u, .enumedUnits) then
                //set u = null
                //return false
            //endif
            
            if .hitsUnitsOnZ then
                set z = GetUnitZ(u)
                set collide = z >= .z - .height /2  and z <= .z + .height /2
            endif
            
            call BJDebugMsg("Hitting unit now.")
            if collide then
                call BJDebugMsg("Unit is hit")
                call .hitUnit(u)
            endif
            
            set u = null
            return false
        endmethod
		
	private static method check takes thistype this returns nothing
            if not .hitsUnits then
                return
            endif
            
            call BJDebugMsg("X: " + R2S(.x) + " - Y: " + R2S(.y))
            call BJDebugMsg("Range: " + R2S(.range))
	    call GroupEnumUnitsInRange(.enumedUnits, .x, .y, .range, thistype.unitFilter)
	endmethod
		
	private static method init takes thistype this returns nothing
	    if LIBRARY_GroupUtils then
	        set .enumedUnits = NewGroup()
	    else
	        set .enumedUnits = CreateGroup()
	    endif
        endmethod
        
        private static method onInit takes nothing returns nothing
            set thistype.unitFilter = Filter(function thistype.enum)
            call thistype.addCreateEvent(thistype.init)
            call thistype.addMoveEvent(thistype.check)
            call BJDebugMsg("Test: " + I2S(GetHandleId(thistype.unitFilter)))
        endmethod
    endmodule
What it does: Prints all values correct. The filter isn't null and enumedUnits isn't null either.

What it does not do: It NEVER, even with a range of 100000. and the full map with units, runs the condition function.
Edit: Sorry for bad indention, hive screws it up. (Has Ralle again changed something?)

Can anyone help me please?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I don't really see the point of your private static method init you might as well just use an instance-method and make the code easier to navigate through. By default vJass instance methods take a parameter thistype this - you're only confusing things. I notice you've done this for pretty much all your methods; do you think this makes the code execute faster?

As for the problem at hand, are you trying to enumerate locust units or something? If so then that is your problem, because units with the Locust ability can only be enumerated by GroupEnumUnitsOfPlayer.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Try putting a BJDebugMsg(GetUnitName(FirstOfGroup(.enumedUnits))) and see what it displays. If it's not even running once then that indicates there aren't any units in the group. By the looks of it you didn't really check to determine if there were actually units in the group.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Where did you set thistype.self?

units with the Locust ability can only be enumerated by GroupEnumUnitsOfPlayer.

Also by GroupEnumUnitsOfType

The only other position than init in the code above where enumedUnits is set is the declaration. So when you say the init function runs once and it's because of the module, maybe the module pastes the start value down to an own init function?
 
What do you mean the group will be reset to 0? You mean it will be null ?
Yes, GetHandleId = 0 / group = null.

Where did you set thistype.self?
Inside the other struct that is implementing the module.

Thanks for your help guys, I've found my way. (I just put it into the check method because modules are somehow bugged)
 
Status
Not open for further replies.
Top