• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Converted GUI to vJass

Status
Not open for further replies.
Level 2
Joined
Jun 22, 2010
Messages
12
Hello Hive. Today, I made a simple trigger that ordered a unit entering a region target a point. Here's the GUI code:
  • Untitled Trigger 004
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Unit - Order (Entering unit) to Move To (Point(0.20, -2431.00))
I converted the trigger, made a few modifications and I thought that I'd create and remove a rect each time a unit entered it. Though after having done that, I feel as if the Jass/vJass might be improperly written as in, there might be a leak somewhere.
JASS:
scope move initializer MoveTo

private function Actions takes nothing returns nothing
    call IssuePointOrderLocBJ( GetEnteringUnit(), "move", Location(0.20, -2431.00) )
endfunction

//===========================================================================
private function MoveTo takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local rect MoveToRegion = Rect(-33.9, -796.0, 31.6, -730.9)
    call TriggerRegisterEnterRectSimple(t, MoveToRegion)
    call TriggerAddAction( t, function Actions )
    call RemoveRect(MoveToRegion)
endfunction

endscope
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
1. Use call IssuePointOrder(GetEnteringUnit(), "move", 0.20, -2431.00) to avoid creating unnecessary handles.

2. Your "MoveTo" function is an initializer. This means it does NOT run everytime your trigger fires but only once in the very beginning. So creating and destroying the rect does not make sense, just remove the RemoveRect(MoveToRegion) line.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
JASS:
scope move initializer MoveTo

function Actions takes nothing returns nothing
    call IssuePointOrder(GetEnteringUnit(),"move",0.20,-2431.00)
endfunction

function MoveTo takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,Rect(-33.9,-796.0,31.6,-730.9))
    call TriggerAddAction(t,function Actions)
endfunction

endscope
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can keep the RemoveRect-line since you do not need that rect anymore after the init. If you read the implementation of TriggerRegisterEnterRectSimple, you can see that it creates a region and applies RegionAddRect, which however does not tie the rect to the region but copies the current cells of the rect, so there is no lasting connection to the rect. Local object variables like of type trigger or rect should be nullified after usage, so the object they pointed to is not longer referenced and can pass its id on.

You normally only have one local initializer and therefore it's comfortable to call it "init". At least not "MoveTo", it's not like you already move something there, it's just the setup. The event entry on the other hand would be something like "onEnter".
 
Status
Not open for further replies.
Top