• 🏆 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!

[JASS] Help fixing old maps triggers

Status
Not open for further replies.
Level 3
Joined
Sep 28, 2018
Messages
38
Extracted .j file and used a simple regex to find consecutive returns. Feast your eyes on the problem(s):

Code:
function jt takes rect R returns unit
return R
return null
endfunction

JASS:
function jU takes integer I returns group
if I!=0 then
return I
endif
return null
endfunction

Found some guides and helpful info (see below).
Not clear how to fix given example takes and returns a unit and the above is taking and returning different vars.

Please help :D

Thank you!!

the way to fix it (IIRC):

Code:
function returnBug takes unit u returns unit
return u
return null
endfunction

This is an example for a return bug. It has 2 returns, 1 after the other.

Code:
function fix1 takes unit u returns unit
return u
endfunction
function returnBug takes unit u returns unit
call fix1(u)
return u
endfunction

Now those are 2 functions, each returning 1 value.

Though I can't understand how it works, it keeps the maps working.

If at all helpful below is where the return bug func is used. Would appear to be for pathing.

JASS:
function K1 takes nothing returns nothing
local integer L=KL(GetTriggeringTrigger())
local integer Id=jr(GetTriggerUnit())
local integer K0=GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
local group G
if GetStoredBoolean(jS(),"IsPathing"+I2S(Id),"UnitAttached")then
return
endif
if DistanceBetweenPoints(GetUnitLoc(jt(bn[L])),GetUnitLoc(GetTriggerUnit()))<DistanceBetweenPoints(GetUnitLoc(jt(bM[L])),GetUnitLoc(GetTriggerUnit()))then
if GetTerrainCliffLevelBJ(GetUnitLoc(GetTriggerUnit()))>GetTerrainCliffLevelBJ(GetUnitLoc(jt(bn[L])))then
return
endif
else
if GetTerrainCliffLevelBJ(GetUnitLoc(jt(bM[L])))>GetTerrainCliffLevelBJ(GetUnitLoc(jt(bn[L])))then
return
endif
endif
set G=It(GetOwningPlayer(GetTriggerUnit()))
if not IsUnitInGroup(GetTriggerUnit(),G)then
call StoreBoolean(jS(),"BeenDeselected"+I2S(Id),"UnitAttached",true)
call DisplayTimedTextToPlayer(Player(0),0,0,5,"not selected")
else
call StoreBoolean(jS(),"BeenDeselected"+I2S(Id),"UnitAttached",false)
call StoreBoolean(jS(),"CurrentlyPathing"+I2S(K0),"PlayerAttached",true)
endif
call GroupAddUnit(jU(GetStoredInteger(jS(),"PathingUnits"+I2S(K0),"PlayerAttached")),GetTriggerUnit())
call StoreBoolean(jS(),"IsPathing"+I2S(Id),"UnitAttached",true)
call ShowUnitHide(GetTriggerUnit())
call PauseUnit(GetTriggerUnit(),true)
call TriggerSleepAction(DistanceBetweenPoints(GetUnitLoc(jt(bn[L])),GetUnitLoc(jt(bM[L])))/500)
call PauseUnit(GetTriggerUnit(),false)
call SetUnitPathing(GetTriggerUnit(),false)
call TriggerSleepAction(0.5)
call ShowUnitShow(GetTriggerUnit())
if not GetStoredBoolean(jS(),"BeenDeselected"+I2S(Id),"UnitAttached")then
if GetStoredBoolean(jS(),"CurrentlyPathing"+I2S(K0),"PlayerAttached")then
call StoreBoolean(jS(),"CurrentlyPathing"+I2S(K0),"PlayerAttached",false)
call SelectUnitAddForPlayer(GetTriggerUnit(),Player(K0))
call TriggerSleepAction(0)
call StoreBoolean(jS(),"CurrentlyPathing"+I2S(K0),"PlayerAttached",true)
else
call SelectUnitAddForPlayer(GetTriggerUnit(),GetOwningPlayer(GetTriggerUnit()))
endif
endif
call GroupRemoveUnit(jU(GetStoredInteger(jS(),"PathingUnits"+I2S(K0),"PlayerAttached")),GetTriggerUnit())
if CountUnitsInGroup(jU(GetStoredInteger(jS(),"PathingUnits"+I2S(K0),"PlayerAttached")))<=0 then
call StoreBoolean(jS(),"CurrentlyPathing"+I2S(K0),"PlayerAttached",false)
endif
call FlushStoredBoolean(jS(),"BeenDeselected"+I2S(Id),"UnitAttached")
call TriggerSleepAction(0.2)
call SetUnitPathing(GetTriggerUnit(),true)
call FlushStoredBoolean(jS(),"IsPathing"+I2S(Id),"UnitAttached")
call DestroyGroup(G)
set G=null
endfunction


**EDIT: 'Patching' func jt and jU (remove all code and leave return null) brought more issues to the surface. Detailing these below. Re-titled post as the scope has changed.

Cannot convert returned value from handle to event

JASS:
function ip takes trigger iP,rect r returns event
 local region iq=CreateRegion()
    call RegionAddRect(iq, r)
    set udg_in=TriggerRegisterEnterRegion(iP, iq, null)
    set iq=null
    return udg_in
endfunction

Cannot convert returned value from handle to group

JASS:
function In takes rect r,boolexpr IN returns group
 local group g=CreateGroup()
    call GroupEnumUnitsInRect(g, r, IN)
    call DestroyBoolExpr(IN)
    set udg_in=g
    set g=null
    return udg_in
endfunction

Cannot convert returned value from handle to force

JASS:
function IT takes player i2 returns force
 local force f=CreateForce()
    call ForceAddPlayer(f, i2)
    set udg_in=f
    set f=null
    return udg_in
endfunction

Variable udg_in is a variable created in the trigger editor with a variable type of handle. Don't understand how it works. As a start it would appear our handle variable is assigned an event via 'TriggerRegisterEnterRegion'. Accessors or other ways to pull event, group, and or force from a handle variable?


TriggerRegisterEnterRegion
trigger whichTrigger, region whichRegion, boolexpr filterevent

Is a proper solution using something like below? Cant find a lick about how to properly use Save/LoadTriggerEventHandle anywhere. Undoubtedly making this far more complicated then it needs to be.


SaveTriggerEventHandle
hashtable table, integer parentKey, integer childKey, event whichEventboolean
LoadTriggerEventHandlehashtable table, integer parentKey, integer childKeyevent

**EDIT2: We were able to get the map running on latest patch by implementing 'fixes' below. This isn't a complete fix as upon using a specific ability (it involved teleporting the unit around) one of our units actually disappeared and never came back. It's believed we need to truly fix the typecasting return bug used in funcs jt and jU at the minimum AND func ip is still a concern as we are no longer assigning the event result to the variable udg_in rather only returning the event. Funcs In and IT are believed to be fixed.

Code:
function jt takes rect R returns unit
return null
endfunction

JASS:
function jU takes integer I returns group
return null
endfunction

JASS:
function ip takes trigger iP,rect r returns event
 local region iq=CreateRegion()
    call RegionAddRect(iq, r)
    return TriggerRegisterEnterRegion(iP, iq, null)
endfunction

JASS:
function In takes rect r,boolexpr IN returns group
 local group g=CreateGroup()
    call GroupEnumUnitsInRect(g, r, IN)
    call DestroyBoolExpr(IN)
    set udg_in=g
    return g
endfunction

JASS:
function IT takes player i2 returns force
 local force f=CreateForce()
    call ForceAddPlayer(f, i2)
    set udg_in=f
    return f
endfunction
 
Last edited:
Status
Not open for further replies.
Top