• 🏆 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] Detecting Entered Region

Status
Not open for further replies.
Level 4
Joined
Jul 11, 2007
Messages
82
Usually I post on WC3C, but I decided to post here for a change.

I have a trigger that I converted into JASS because I needed to edit it a lot, and it fires after one of several events.

JASS:
function InitTrig_New takes nothing returns nothing
    set gg_trg_New = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player0 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player1 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player2 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player3 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player4 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player5 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player6 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player7 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player8 )
    call TriggerRegisterEnterRectSimple( gg_trg_New, gg_rct_Player9 )    
    call TriggerAddCondition( gg_trg_New, Condition( function Trig_New_Conditions ) )
    call TriggerAddAction( gg_trg_New, function Trig_New_Actions )
endfunction

So you can see it fires when a unit enters either region Player0, Player1, Player2, etc. In the actions function I need to detect which of those units was entered. How do I do this?

I tried things like "if the triggering unit is in rect Player3 then" but that didn't work for some reason. I also tried to check if a point (location of triggering unit) was in the each of the regions. So anyway, I need to set a variable based on which of those units was the one entered. Thanks.
 
Level 3
Joined
May 12, 2006
Messages
31
I don't understand your problem. there is an action like this "event response - entering unit"
so my_var = entering unit.

I mean this is in GUI, and i know nothing about JASS, but it mustbe the same action in JASS like in GUI.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
He wants to know what region the triggering unit has entered.
Either some ridiculous solution or just split it in several triggers :)
 
Level 4
Joined
Jul 11, 2007
Messages
82
At first I did have in in different triggers, but I wanted to put it in one to make it cleaner.

I didn't know there was a GetTriggeringRegion() function. I looked for something like that but couldn't find one. I'm having troubles getting it to work though. As you can see, I'm new to JASS so I don't know how to put this in exactly.

This line gives a syntax error:
JASS:
if (GetTriggeringRegion() = gg_rct_Player0) and p == Player(0) then

Is it because it treats Player0 like a rect instead of a region?
 
Level 4
Joined
Jul 11, 2007
Messages
82
I don't understand how to do what you just said, but I made a global variable called PRegion[x] and then I set PRegion[0] to be the region Player0, PRegion[1] = region Player1, etc.

JASS:
if (GetTriggeringRegion() = udg_PRegion[0]) and p == Player(0) then

Then I used this to compare to see if that global region variable is the triggering region. Syntax error on that line.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
It's because you have to declare the variable in Jass. The 'Region' in the variable manager is, again, rect.

Use vJass's free global declaration:

JASS:
globals
    region array udg_PRegion
endglobals

Also, for your code as a whole, you could just do this instead of a mass of if-statements:

JASS:
local integer i = 0
local region r = GetTriggeringRegion()
    loop
        exitwhen r == udg_PRegion[i]
        set i = i + 1
    endloop
    set r = null
    //i is the player id
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Im sorry but I have a question about this...

call TriggerRegisterEnterRectSimple(bla, blaa)

Since JNGP is highlighting this... Is it ineffective, or should you create a custom one to avoid inefficiency... Or is it fine to use it?

And hm, 4 days revival is allowed right? (guess I should completely read the rules someday...)
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
There is no need to ask about every BJ function if it's uneffective or not. Press ctrl+leftclick on a function and you'll see what's inside it. Or you can simply look it up in the function list.

JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction

If I'm right then it creates a region it doesn't remove nor null and that's a problem.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Well, no, because he needs to store the regions to globals.

But the theory is correct.

Poot, yea, but I guess if you make a custom one with a local rect and turning that into a region I must remove the rect and set it to null... But yea I actually tried that thing, to remove it, and guess what it didnt work.
That would be like removing a location then attempting to move someone there.
 
regions are not rects...

A region is effectively a "rect group"

A rect is what GUI and the "Region Palette" refer to as a Region.

Therefore, if you store each rect in a separate region and then use the regions in globals you could make use of said function.

that's wrong, a region is a conbination of game cells, we just determine regions by using rects. What it does is that it adds every cell within the rect to the region.
 
Status
Not open for further replies.
Top