- Joined
- Jan 9, 2005
- Messages
- 2,126
So I have a bunch of units stored on a hashtable, and I want to be able to pick a random unit from that hashtable. Ideally, I'd want to be able to pass a filter on that. I've used boolexpr in the past, but I was wondering if I could use it myself for my own functions?
Now, to reiterate from the comment inside the code, I know this isn't how boolexpr are used, but essentially, if the user wants to pass a filter on that function, I'd want to be able to filter through the hashtable-stored units and return one with the correct parameters.
Can anyone shed some light?
JASS:
function GetRandomGuest takes unit host, boolexpr guestFilter returns unit
local integer idHost = GetUnitUserData(host)
local integer i
local boolean firstPass
if guestFilter == null then
return LoadUnitHandle(GuestStorage, idHost, GetRandomInt(1, HostInvites[idHost]))
else
set i = GetRandomInt(1, HostInvites[idHost])
if i == 1 then
set firstPass = true
else
set firstPass = false
endif
loop
exitwhen i > HostInvites[idHost] and firstPass
set i = i + 1
if i > HostInvites[idHost] and not firstPass then
set i = 1
set firstPass = true
endif
//I know that's not how boolexpr are used, but hopefully this should illustrate what I'm trying to do.
//if Filter(guestFilter)
//return LoadUnitHandle(GuestStorage, idHost, i)
//endif
endloop
endif
return null
endfunction
Now, to reiterate from the comment inside the code, I know this isn't how boolexpr are used, but essentially, if the user wants to pass a filter on that function, I'd want to be able to filter through the hashtable-stored units and return one with the correct parameters.
Can anyone shed some light?