| 08-23-2009, 01:35 PM | #1 |
Heya. I'm currently learning vJass and have run into a problem which I cannot solve. The compiler complains about the variable CurDwarfGrp being undeclared, but it is, so I have no clue as to what the problem is. Anyways, any help would be greatly appreciated, thanks in advance. New problem: Compiles fine, but when I test the map via NewGen, the map crashes once it finishes loading. This does not happen when the following trigger is disabled: JASS:scope EngageDwarves initializer Init globals private integer CurDwarfGrp = 0 private region r = CreateRegion() endglobals function PlayerFilter takes nothing returns boolean return GetOwningPlayer(GetEnteringUnit()) == Player(0) endfunction function Actions takes nothing returns nothing if (CurDwarfGrp == 0) then set CurDwarfGrp = 1 call RegionClearRect(r,gg_rct_test) call BJDebugMsg("TEST") elseif (CurDwarfGrp == 1) then set CurDwarfGrp = 2 call RegionClearRect(r,gg_rct_second) call BJDebugMsg("SECOND") endif endfunction function Init takes nothing returns nothing local trigger t = CreateTrigger() call RegionAddRect(r,gg_rct_test) call RegionAddRect(r,gg_rct_second) call TriggerRegisterEnterRegion(t,r,Condition(function PlayerFilter)) call TriggerAddAction(t,function Actions) endfunction endscope |
| 08-23-2009, 01:38 PM | #2 |
CurDwarfGrp is actually a local variable, meaning its only a valid variable inside the function it was declared in. Youll need a global variable to do what you want. |
| 08-23-2009, 01:43 PM | #3 |
Oh, I thought it was valid inside the entire scope it was declared in. Thanks a lot. |
| 08-23-2009, 02:15 PM | #4 |
do you perhaps have one unit in each rect? Then that could explain the crash: A unit enters the first rect. That rect gets removed and the second rect gets added, but because theres already a unit in it, the trigger fires instantly, this time exchanging the second rect for the first rect, then firing again because a unit is in the first rect, and so on. |
| 08-23-2009, 02:22 PM | #5 |
Actually, there isn't a unit in either of the two rects at the map's start. |
| 08-23-2009, 02:28 PM | #6 |
try initializing r in your Init function. |
| 08-23-2009, 02:30 PM | #7 |
That wouldn't work, as it needs to be a global variable since I communicate with it in the Actions function. |
| 08-23-2009, 02:42 PM | #8 |
let me just show you what i mean: JASS:scope EngageDwarves initializer Init globals private integer CurDwarfGrp = 0 private region r // changed endglobals function PlayerFilter takes nothing returns boolean return GetOwningPlayer(GetEnteringUnit()) == Player(0) endfunction function Actions takes nothing returns nothing if (CurDwarfGrp == 0) then set CurDwarfGrp = 1 call RegionClearRect(r,gg_rct_test) call BJDebugMsg("TEST") elseif (CurDwarfGrp == 1) then set CurDwarfGrp = 2 call RegionClearRect(r,gg_rct_second) call BJDebugMsg("SECOND") endif endfunction function Init takes nothing returns nothing local trigger t = CreateTrigger() set r=CreateRegion() // added call RegionAddRect(r,gg_rct_test) call RegionAddRect(r,gg_rct_second) call TriggerRegisterEnterRegion(t,r,Condition(function PlayerFilter)) call TriggerAddAction(t,function Actions) endfunction endscope |
| 08-23-2009, 02:46 PM | #9 |
Doesn't crash, but doesn't work either, in fact, whenever a unit owned by player 1 enters either of the regions, nothing happens at all. |
| 08-23-2009, 03:18 PM | #10 |
try exchanging GetEnteringUnit() in your PlayerFilter function for GetFilterUnit() |
| 08-23-2009, 03:36 PM | #11 |
Works very well, thanks a lot for your help. |
