• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Save struct in hashtable?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Try using SaveInteger.

Not sure how you mean.

Im trying to index, deindex these at OnStart and OnStop form my previous posted question. Is this the correct way of doing it? Should I destroy the deindexed struct?

JASS:
private function OnStart takes nothing returns boolean  
        if Spell() then
            if hex[index] == null then
                set hex[index] = Hex.create()
            endif
            set hex[index].u = GetTriggerUnit()
            set hex[index].x = GetLocationX(GetSpellTargetLoc())
            set hex[index].y = GetLocationY(GetSpellTargetLoc())
            call SaveInteger(hash, GetHandleId(hex[index].u), 1, index)
            set index = index + 1
        endif
        return false
    endfunction
    
    private function OnStop takes nothing returns boolean
        local integer i
        local integer j
        if Spell() then 
            set i = LoadInteger(hash, GetHandleId(GetTriggerUnit()), 1)
            set j = index - 1
            call FlushChildHashtable(hash, GetHandleId(hex[i].u))
            call FlushChildHashtable(hash, GetHandleId(hex[j].u))
            call SaveInteger(hash, GetHandleId(hex[j].u), 1, i) 
            set hex[i] = hex[j]
            call hex[j].destroy()     
            set index = j
        endif
        return false 
    endfunction
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
I mean think struct as an integer, and try to attach it to unit via SaveInteger.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
JASS:
method groupFilter takes nothing returns boolean 
            return not IsUnitInGroup(GetFilterUnit(), .hexed) and IsPlayerEnemy(GetOwningPlayer(.u), GetOwningPlayer(GetFilterUnit()))
        endmethod
        
        method addUnitsInRange takes group g returns group 
            call GroupEnumUnitsInRangeOfLoc(g, Location(.x, .y), RADIUS, function .groupFilter) 
            return g
        endmethod
"function .groupFilter" is not working as well, meh.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
You can update mappings. You only need to clear mappings that no-longer exist.

hence this...
JASS:
             call FlushChildHashtable(hash, GetHandleId(hex[i].u))
             call FlushChildHashtable(hash, GetHandleId(hex[j].u))
             call SaveInteger(hash, GetHandleId(hex[j].u), 1, i)
Should be the same as...
JASS:
             call FlushChildHashtable(hash, GetHandleId(hex[i].u))
             call SaveInteger(hash, GetHandleId(hex[j].u), 1, i)
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
why is this statement illegal?
The function "GroupEnumUnitsInRangeOfLoc" expects a function which "takes nothing returns boolean". You are giving it a function which "takes integer structref returns boolean".

Methods are implemented by passing an integer index representing a struct reference as a function argument. The struct reference is the index inside a collection of parallel arrays representing struct members. As such referencing a member is referencing a function which takes an extra integer on top of all the parameters you define. Such function cannot be used as an action, condition or filter as those require functions that "take nothing".

The solution is to make the method static. To pass the struct reference you use a "register" like global variable. This is a global variable which sole purpose is to temporarily store some data between or inside a thread where passing directly is not possible.

JASS:
         private static STRUCTNAMEGOESHERE fmreg

         static method groupFilter takes nothing returns boolean 
             return not IsUnitInGroup(GetFilterUnit(), fmreg.hexed) and IsPlayerEnemy(GetOwningPlayer(fmreg.u), GetOwningPlayer(GetFilterUnit()))
         endmethod
         
         method addUnitsInRange takes group g returns group 
             set fmreg = this
             call GroupEnumUnitsInRangeOfLoc(g, Location(.x, .y), RADIUS, function STRUCTNAMEGOESHERE.groupFilter) 
             return g
         endmethod

If that does not work try simply "groupFilter" since it is static it might pick it up as a named space.
 
Status
Not open for further replies.
Top