Hello there.
Still working on converting my map from Jass2 to Lua, and I am currently experiencing a strange difference of behavior between Jass2 and Lua.
The attacking creeps (Balls) in my TD follow a path of 8 WayPoints.
These WayPoints are destructables with a model displaying their number. When I create all WayPoints after Map Init, I attach a trigger with the entering region event, the region containing just a rect around the waypoint. WayPoint coordinates are saved in 2 global real arrays WPx and WPy.
The Last WayPoint is at the center of the map and has the number 50 (same for all players).
So when the Ball spawns, I save the first waypoint number (11 for player 1, 21 for player 2, etc...) as Destination[*ball number*]. The Ball number being stored in the Ball 's UnitUserData.
Destination is as you have guessed, a global integer Array. Then I order the Ball to move towards the coordinates of the first waypoint, so :
Now here was my NextWayPoint trigger action function in Jass2 that used to work perfectly :
and now the translated version in Lua :
Notice the print to display values, I use the same print when I spawn the Ball.
As I said, in Jass this worked perfectly, and when the Ball reaches the waypoint, the event fires and the Ball is ordered to do to the next waypoint.
But in Lua something strange happens, the event fires repeatedly until the Ball leaves the region !!!!
Here are a couple of screenshots to illustrate what happens :
Before entering first waypoint region :
When the Ball enters the region, it triggers repeatedly, with the destination growing constantly (but also constantly being reset to 50 everytime its modulo 10 value gets over 8) :
Of course, there would be a fix : saving a boolean in a global table indexed with the Ball unit, that would be set to false until the Ball leaves the region, but then of course this would mean adding another trigger with an event for units leaving the regions. Anyways I am sure I could find a way out of this problem without too much trouble, but that is not my question.
Here are my questions :
- Is it ,normal that the ENTER_REGION event behaves differently in Jass2 and Lua ?
What can cause such a difference ?
- Are there other events suffering from the same differences ?
Thanks for your help.
Still working on converting my map from Jass2 to Lua, and I am currently experiencing a strange difference of behavior between Jass2 and Lua.
The attacking creeps (Balls) in my TD follow a path of 8 WayPoints.
These WayPoints are destructables with a model displaying their number. When I create all WayPoints after Map Init, I attach a trigger with the entering region event, the region containing just a rect around the waypoint. WayPoint coordinates are saved in 2 global real arrays WPx and WPy.
The Last WayPoint is at the center of the map and has the number 50 (same for all players).
So when the Ball spawns, I save the first waypoint number (11 for player 1, 21 for player 2, etc...) as Destination[*ball number*]. The Ball number being stored in the Ball 's UnitUserData.
Destination is as you have guessed, a global integer Array. Then I order the Ball to move towards the coordinates of the first waypoint, so :
IssuePointOrder(b, "move", WPx[wpNb], WPy[wpNb])
, b being the Ball and wpNb as you can imagine is this first waypoint number.Now here was my NextWayPoint trigger action function in Jass2 that used to work perfectly :
JASS:
function NextWayPointActions takes nothing returns boolean
local unit ball=GetEnteringUnit()
local player owner=GetOwningPlayer(ball)
local integer ballNb
local integer dest
local integer moduloDest
if ( owner == BallsMaster ) then
set ballNb=GetUnitUserData(ball)
set dest=Destination[ballNb]
if IsUnitInRegion(WPRegion[dest], ball) then
set dest=dest + 1
set moduloDest=Modulo(dest , 10)
if moduloDest > 8 then
set dest=50 // Go to the citadel
else
if ( moduloDest == 2 ) then
if ( GetUnitAbilityLevel(ball, BuffID[12]) > 0 ) then // Removing the Going Back Home buff
call UnitRemoveAbility(ball, BuffID[12])
endif
endif
endif
set Destination[ballNb]=dest
call IssuePointOrder(ball, "move", WPx[dest], WPy[dest])
endif
endif
set owner=null
set ball=null
return false
endfunction
and now the translated version in Lua :
Lua:
TriggerAddAction(NextWayPoint[wn], function ()
local b=GetEnteringUnit()
if (GetOwningPlayer(b)==BallsMaster) then
local bn=GetUnitUserData(b)
local d=Destination[bn]
if IsUnitInRegion(WPRegion[d], b) then
d=d+1
if (math.fmod(d, 10)>8) then
d=50 -- got to final destination
else
if (GetUnitAbilityLevel(b, BuffID[9])>0) then -- Removing Going Back Home buff
UnitRemoveAbility(b, BuffID[9])
end
end
Destination[bn]=d
IssuePointOrder(b, "move", WPx[d], WPy[d])
print(bn.."->"..d)
end
end
end)
Notice the print to display values, I use the same print when I spawn the Ball.
As I said, in Jass this worked perfectly, and when the Ball reaches the waypoint, the event fires and the Ball is ordered to do to the next waypoint.
But in Lua something strange happens, the event fires repeatedly until the Ball leaves the region !!!!
Here are a couple of screenshots to illustrate what happens :
Before entering first waypoint region :
When the Ball enters the region, it triggers repeatedly, with the destination growing constantly (but also constantly being reset to 50 everytime its modulo 10 value gets over 8) :
Of course, there would be a fix : saving a boolean in a global table indexed with the Ball unit, that would be set to false until the Ball leaves the region, but then of course this would mean adding another trigger with an event for units leaving the regions. Anyways I am sure I could find a way out of this problem without too much trouble, but that is not my question.
Here are my questions :
- Is it ,normal that the ENTER_REGION event behaves differently in Jass2 and Lua ?
What can cause such a difference ?
- Are there other events suffering from the same differences ?
Thanks for your help.