• 🏆 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] Rects and Regions, conversion?

Status
Not open for further replies.
Level 2
Joined
Oct 29, 2013
Messages
6
I'm just now making the transition from GUI to JASS, and I have a problem with a trigger that transports a unit from one rect to another upon entering the first rect. I want to apply it in a few different places, and I want to make it as general as possible so that I don't have to write and call different functions for each instance.

Here's what it looks like now, it works but it's only for one of the instances. I'm just using one of the regions for testing purposes right now.
JASS:
function BossEntranceConditions takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction

function BossEntranceHandlerfunc takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = LoadUnitHandle(udg_bossEntranceHash, GetHandleId(t), 0)
    call ShowUnit(u, true)
    call SelectUnitAddForPlayer( u, GetOwningPlayer(u) )
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
    set u = null
    call RemoveUnit(u)
endfunction

function BossEntranceActions01 takes nothing returns nothing
    local location l = GetRectCenter(udg_bossEntranceTargets[1])
    local unit u = GetTriggerUnit()
    local timer t = CreateTimer()
    call ShowUnit(u, false)
    call SetUnitPositionLoc(u, l)
    call SaveUnitHandle(udg_bossEntranceHash, GetHandleId(t), 0, u)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(u), l, 0.25)
    call TimerStart(t, 0.25, false, function BossEntranceHandlerfunc)
    set t = null
    set l = null
    set u = null
    call RemoveLocation(l)
    call RemoveUnit(u)
endfunction

//===========================================================================

function InitTrig_Boss_Entrances takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( t, udg_bossEntranceRegions[1])
    call TriggerAddCondition( t, Condition( function BossEntranceConditions ) )
    call TriggerAddAction( t, function BossEntranceActions01 )
endfunction
So I put all of the entry rects into an array and all of the rects used for exits in another. The idea was to get the index of the entry rect so I could use that number to get a rect with the same index from the other array with this function:
JASS:
function BossEntranceRegionCheck takes rect r returns integer
      local integer i = 0
      loop
         exitwhen i > 20
        if  r == udg_bossEntranceRegions[i] then
            return i
        endif
        set i = i + 1
      endloop
      set r = null
      return 0
endfunction
It didn't really work out since from what I understand there is no way to check for the triggering rect, just regions with GetTriggeringRegion(). At first I had the BossEntranceRegionCheck take a region as an argument instead and just converting the entry rect into a region. However this lead to some other problems, since to my knowledge you can't get the center of a region, just the center of a rect and I can't seem to find a way to turn the region back into a rect either.

I feel like this isn't that hard and that I'm likely missing something obvious, but I'm not sure what.
 
From the region to the rect_goal_region -> you want access to 'something_a' with using 'something_b'. It's like region is wanted to be used as key to access the rect.

Similar like you use the timer's handle id as key in the code to access data, you might use the region's handle id for the rect access.

Practically you can bind the rect to each region in an init function with using hashtable.
At the enter function you can just get the rect by using the triggering region again.

You might want to look into what "TriggerRegisterEnterRectSimple" does inside, to replicate the code.
The IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) check might happen inside an if-statement in the action function. (2 seperated functions are not really required)
Objects should be nulled only after removal, not before. Have a look at Memory Leaks -> Reference Leaks -> Tequnique of Removal
 
Status
Not open for further replies.
Top