HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How Does Lag Affect This?

07-03-2006, 08:49 PM#1
Karawasa
Hey Guys,

I have a trigger that creates creeps and then orders them to move toward a certain region.

This trigger works 100% fine when playing with up to 3 other people. When more then 4 people are in the game, the creeps start tripping over each other, stopping, lagging, bugging out etc.

Here is the code:

Collapse JASS:
function Trig_Start_Level_Func008002001 takes nothing returns boolean
    return ( udg_Player_Lives[( GetConvertedPlayerId(GetFilterPlayer()) - 1 )] > 0 )
endfunction

function Trig_Start_Level_Func009Func002002001002001 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_Start_Level_Func009Func002002001002002001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_ANCIENT) == false )
endfunction

function Trig_Start_Level_Func009Func002002001002002002 takes nothing returns boolean
    return ( GetUnitUserData(GetFilterUnit()) == GetConvertedPlayerId(GetEnumPlayer()) )
endfunction

function Trig_Start_Level_Func009Func002002001002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Start_Level_Func009Func002002001002002001(), Trig_Start_Level_Func009Func002002001002002002() )
endfunction

function Trig_Start_Level_Func009Func002002001002 takes nothing returns boolean
    return GetBooleanAnd( Trig_Start_Level_Func009Func002002001002001(), Trig_Start_Level_Func009Func002002001002002() )
endfunction

function Trig_Start_Level_Func009A takes nothing returns nothing
    call DisplayTimedTextToForce( GetForceOfPlayer(GetEnumPlayer()), 5.00, ( "Level " + ( I2S(udg_Level) + ( ": " + ( GetUnitName(GroupPickRandomUnit(GetUnitsOfTypeIdAll(udg_Spawns[( udg_Level - 1 )]))) + ( " " + ( udg_Extra + ( " - " + ( I2S(( 15 + ( ( udg_Difficulty[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] + 0 ) * 3 ) )) + " spawns" ) ) ) ) ) ) ) ) )
    set udg_Creeps_Left[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] = CountUnitsInGroup(GetUnitsOfPlayerMatching(Player(11), Condition(function Trig_Start_Level_Func009Func002002001002)))
    set udg_Creeps_Left[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] = ( udg_Creeps_Left[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] + ( 15 + ( udg_Difficulty[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] * 3 ) ) )
endfunction

function Trig_Start_Level_Func011Func002002001 takes nothing returns boolean
    return ( udg_Player_Lives[( GetConvertedPlayerId(GetFilterPlayer()) - 1 )] > 0 )
endfunction

function Trig_Start_Level_Func011Func003Func001C takes nothing returns boolean
    if ( not ( udg_Spawn_Loop <= ( 15 + ( udg_Difficulty[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] * 3 ) ) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Start_Level_Func011Func003A takes nothing returns nothing
    if ( Trig_Start_Level_Func011Func003Func001C() ) then
        set udg_Temp_Point = GetRectCenter(udg_Region_Spawn[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )])
        call CreateNUnitsAtLoc( 1, udg_Spawns[( udg_Level - 1 )], Player(11), udg_Temp_Point, 270.00 )
        call RemoveLocation(udg_Temp_Point)
        call SetUnitUserData( GetLastCreatedUnit(), GetConvertedPlayerId(GetEnumPlayer()) )
        call SetUnitLifePercentBJ( GetLastCreatedUnit(), ( 50.00 + ( I2R(( udg_Difficulty[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] - 1 )) * 12.50 ) ) )
        set udg_Temp_Point = GetRectCenter(udg_Region_Leak[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )])
        call IssuePointOrderLocBJ( GetLastCreatedUnit(), "move", udg_Temp_Point )
        call RemoveLocation(udg_Temp_Point)
    else
    endif
endfunction

function Trig_Start_Level_Actions takes nothing returns nothing
    set udg_Between_Levels = false
    call DestroyTimerDialogBJ( GetLastCreatedTimerDialogBJ() )
    set udg_Level = ( udg_Level + 1 )
    call LeaderboardSetLabelBJ( udg_Scoreboard, ( "Level " + I2S(udg_Level) ) )
    set udg_Extra = ( "(" + ( udg_Level_Desc[( udg_Level - 1 )] + ")" ) )
    call CreateNUnitsAtLoc( 1, udg_Spawns[( udg_Level - 1 )], Player(11), GetPlayerStartLocationLoc(Player(11)), 270.00 )
    call RemoveUnit( GetLastCreatedUnit() )
    set udg_Player_Group = GetPlayersMatching(Condition(function Trig_Start_Level_Func008002001))
    call ForForce( udg_Player_Group, function Trig_Start_Level_Func009A )
    call DestroyForce(udg_Player_Group)
    set udg_Spawn_Loop = 1
    loop
        exitwhen udg_Spawn_Loop > 30
        call TriggerSleepAction( 0.30 )
        set udg_Player_Group = GetPlayersMatching(Condition(function Trig_Start_Level_Func011Func002002001))
        call ForForce( udg_Player_Group, function Trig_Start_Level_Func011Func003A )
        call DestroyForce(udg_Player_Group)
        set udg_Spawn_Loop = udg_Spawn_Loop + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Start_Level takes nothing returns nothing
    set gg_trg_Start_Level = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Start_Level, udg_Generic_Timer )
    call TriggerAddAction( gg_trg_Start_Level, function Trig_Start_Level_Actions )
endfunction

Here is the GUI version in case it is easier to read.

Trigger:
Start Level
Collapse Events
Time - Generic_Timer expires
Conditions
Collapse Actions
Set Between_Levels = False
Countdown Timer - Destroy (Last created timer window)
Set Level = (Level + 1)
Leaderboard - Change the title of Scoreboard to (Level + (String(Level)))
Set Extra = (( + (Level_Desc[(Level - 1)] + )))
Unit - Create 1 Spawns[(Level - 1)] for Player 12 (Brown) at (Player 12 (Brown) start location) facing 270.00 degrees
Unit - Remove (Last created unit) from the game
Set Player_Group = (All players matching (Player_Lives[((Player number of (Matching player)) - 1)] Greater than 0))
Collapse Player Group - Pick every player in Player_Group and do (Actions)
Collapse Loop - Actions
Game - Display to (Player group((Picked player))) for 5.00 seconds the text: (Level + ((String(Level)) + (: + ((Name of (Random unit from (Units of type Spawns[(Level - 1)]))) + ( + (Extra + ( - + ((String((15 + ((Difficulty[((Player number of (Picked player)) - 1)] + 0) x 3)))) + spawns))))))))
Set Creeps_Left[((Player number of (Picked player)) - 1)] = (Number of units in (Units owned by Player 12 (Brown) matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is An Ancient) Equal to False) and ((Custom value of (Matching unit)) Equal to (Player number of (Picked player)))))))
Set Creeps_Left[((Player number of (Picked player)) - 1)] = (Creeps_Left[((Player number of (Picked player)) - 1)] + (15 + (Difficulty[((Player number of (Picked player)) - 1)] x 3)))
Custom script: call DestroyForce(udg_Player_Group)
Collapse For each (Integer Spawn_Loop) from 1 to 30, do (Actions)
Collapse Loop - Actions
Wait 0.30 seconds
Set Player_Group = (All players matching (Player_Lives[((Player number of (Matching player)) - 1)] Greater than 0))
Collapse Player Group - Pick every player in Player_Group and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Spawn_Loop Less than or equal to (15 + (Difficulty[((Player number of (Picked player)) - 1)] x 3))
Collapse Then - Actions
Set Temp_Point = (Center of Region_Spawn[((Player number of (Picked player)) - 1)])
Unit - Create 1 Spawns[(Level - 1)] for Player 12 (Brown) at Temp_Point facing 270.00 degrees
Custom script: call RemoveLocation(udg_Temp_Point)
Unit - Set the custom value of (Last created unit) to (Player number of (Picked player))
Unit - Set life of (Last created unit) to (50.00 + ((Real((Difficulty[((Player number of (Picked player)) - 1)] - 1))) x 12.50))%
Set Temp_Point = (Center of Region_Leak[((Player number of (Picked player)) - 1)])
Unit - Order (Last created unit) to Move To Temp_Point
Custom script: call RemoveLocation(udg_Temp_Point)
Else - Actions
Custom script: call DestroyForce(udg_Player_Group)


What can be done with this trigger to prevent this problem?

Thanks!
07-03-2006, 09:09 PM#2
Captain Griffen
How long is the generic timer by the way?

Anyway, replace the wait with a game time wait, and see if that solves it (never use normal waits, except for stuff like wait 0.00).
07-03-2006, 09:32 PM#3
Rising_Dusk
Generic_Timer is a global.
Make sure it isn't tripping over itself and that you're not starting it too many times before it expires the first time.

Starting the same timer several times before the first iteration has completed can usually lead to lag and other issues.
I realize that starting a started timer simply restarts it, but if you do it too many times (possible dependent on creeps), then it will never run properly.

Other than that, what Griff said.
Polled Waits, not TriggerSleeps. :P
07-04-2006, 08:28 AM#4
Karawasa
Changed the wait, reduced lag slightly but the lag is still a big problem. This is the trigger for the generic timer, I don't think thats the problem.

Trigger:
Start Timer
Events
Conditions
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Level Not equal to 60
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Level Equal to 0
Collapse Then - Actions
Countdown Timer - Start Generic_Timer as a One-shot timer that will expire in 25.00 seconds
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level mod 5) Equal to 0
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level mod 10) Equal to 0
Collapse Then - Actions
Trigger - Run Adjust Difficulty <gen> (ignoring conditions)
Else - Actions
Trigger - Turn off Random <gen>
Trigger - Turn on Random After Lv 5 <gen>
Countdown Timer - Start Generic_Timer as a One-shot timer that will expire in 20.00 seconds
Player - Set the current research level of HP Bonus to ((Level - 1) / 5) for Player 12 (Brown)
Set Player_Group = (All players matching (Player_Lives[((Player number of (Matching player)) - 1)] Greater than 0))
Collapse Player Group - Pick every player in Player_Group and do (Actions)
Collapse Loop - Actions
Game - Display to (Player group((Picked player))) the text: You've just receive...
Player - Add 1 to (Picked player) Current lumber
Custom script: call DestroyForce(udg_Player_Group)
Trigger - Run Random Bosses <gen> (ignoring conditions)
Collapse Else - Actions
Countdown Timer - Start Generic_Timer as a One-shot timer that will expire in Start_Timer_Modifier seconds
Set Start_Timer_Modifier = 8.00
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
Level Equal to 51
Level Equal to 56
Collapse Then - Actions
Set Player_Group = (All players matching (Player_Lives[((Player number of (Matching player)) - 1)] Greater than 0))
Collapse Player Group - Pick every player in Player_Group and do (Actions)
Collapse Loop - Actions
Game - Display to (Player group((Picked player))) the text: |cffffaacc+++++++++...
Unit - Create 1 Elemental Essence for (Picked player) at (((Picked player) start location) offset by ((775.00 + ((Real(elemental_count[((Player number of (Picked player)) - 1)])) x 75.00)), 880.00)) facing 270.00 degrees
Unit - Make (Last created unit) Invulnerable
Unit - Pause (Last created unit)
Set elemental_count[((Player number of (Picked player)) - 1)] = (elemental_count[((Player number of (Picked player)) - 1)] + 1)
Custom script: call DestroyForce(udg_Player_Group)
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Level Equal to 5
Collapse Then - Actions
Game - Display to (All players) the text: (Be forewarned, Lev...
Else - Actions
Countdown Timer - Create a timer window for Generic_Timer with title (Level + ((String((Level + 1))) + in: ))
Countdown Timer - Show (Last created timer window)
Set Between_Levels = True
Collapse Else - Actions
-------- GAME OVER --------
Collapse For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Creeps_Left[((Integer A) - 1)] Equal to 0
Player_Lives[((Integer A) - 1)] Greater than 0
Game_Over Equal to False
Elimination_Mode Equal to False
Collapse Then - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Living_Players Equal to 1
Collapse Then - Actions
Game - Display to (All players) the text: (Congradulations + (Name of (Player((Integer A)))))
Game - Display to (All players) the text: You're the sole sur...
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Difficulty[((Integer A) - 1)] Less than 5
Collapse Then - Actions
Game - Display to (All players) the text: You should try on a...
Collapse Else - Actions
Game - Display to (All players) the text: And to top it off, ...
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Random_Element[((Integer A) - 1)] Equal to False
Collapse Then - Actions
Game - Display to (All players) the text: You should play on ...
Collapse Else - Actions
Game - Display to (All players) the text: Plus you were on ra...
Set Game_Over = True
Countdown Timer - Start End_Game_Timer as a One-shot timer that will expire in 30.00 seconds
Countdown Timer - Create a timer window for End_Game_Timer with title Game will end in:
Countdown Timer - Show (Last created timer window)
Trigger - Turn off (This trigger)
Collapse Else - Actions
Trigger - Turn off (This trigger)
Trigger - Run Start Elimination Round Timer <gen> (ignoring conditions)
Set Elimination_Mode = True
Else - Actions

Any other possible problems?
07-04-2006, 09:15 AM#5
Pheonix-IV
Trigger:
Countdown Timer - Start Generic_Timer as a One-shot timer that will expire in Start_Timer_Modifier seconds
Set Start_Timer_Modifier = 8.00

You realise your setting Start_Timer_Modifier after you try to use it?
07-04-2006, 05:41 PM#6
Karawasa
Quote:
Originally Posted by Pheonix-IV
Trigger:
Countdown Timer - Start Generic_Timer as a One-shot timer that will expire in Start_Timer_Modifier seconds
Set Start_Timer_Modifier = 8.00

You realise your setting Start_Timer_Modifier after you try to use it?

Ya this code is outdated since the timer is supposed to be 6 seconds and not 8. Silly to have left it in there I suppose :). Not my code though, I would never whip up something that shitty or redudant. I don't think the new trigger even uses that line.

Anyway, been tinkering around with the trigger some more, but to no avail :(.
07-04-2006, 06:00 PM#7
Captain Griffen
That loop will mess up. Only decent solution is to use a JASS loop, using a local integer.

At start:

local integer i = 1

Then instead of For each integer A...:

loop
exitwhen i > 30

Then at the end of the loop:

set i = i + 1
endloop
07-04-2006, 06:06 PM#8
Karawasa
I have no clue what a JASS loop is. So my next two questions are, what is the difference between the loops (why is this JASS one better?), and would anyone create this JASS loop for me or tell me what to do.
07-04-2006, 06:26 PM#9
PipeDream
There's a very large selection of JASS tutorials on this site. In particular Vex's and Blade's are valuable for beginners.

You seem to be frequently running into the places where GUI goes from merely tedious to jumping naked into a dumpster full of syringes discarded by an AIDS clinic. These things don't have to be hard, give learning JASS a shot.
07-04-2006, 06:29 PM#10
Captain Griffen
JASS loops are better as they use locals not globals, so you won't get the collisions you get.

Trigger:
Start Level
Collapse Events
Time - Generic_Timer expires
Conditions
Collapse Actions
Custom script: local integer i = 1
Set Between_Levels = False
Countdown Timer - Destroy (Last created timer window)
Set Level = (Level + 1)
Leaderboard - Change the title of Scoreboard to (Level + (String(Level)))
Set Extra = (( + (Level_Desc[(Level - 1)] + )))
Unit - Create 1 Spawns[(Level - 1)] for Player 12 (Brown) at (Player 12 (Brown) start location) facing 270.00 degrees
Unit - Remove (Last created unit) from the game
Set Player_Group = (All players matching (Player_Lives[((Player number of (Matching player)) - 1)] Greater than 0))
Collapse Player Group - Pick every player in Player_Group and do (Actions)
Collapse Loop - Actions
Game - Display to (Player group((Picked player))) for 5.00 seconds the text: (Level + ((String(Level)) + (: + ((Name of (Random unit from (Units of type Spawns[(Level - 1)]))) + ( + (Extra + ( - + ((String((15 + ((Difficulty[((Player number of (Picked player)) - 1)] + 0) x 3)))) + spawns))))))))
Set Creeps_Left[((Player number of (Picked player)) - 1)] = (Number of units in (Units owned by Player 12 (Brown) matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is An Ancient) Equal to False) and ((Custom value of (Matching unit)) Equal to (Player number of (Picked player)))))))
Set Creeps_Left[((Player number of (Picked player)) - 1)] = (Creeps_Left[((Player number of (Picked player)) - 1)] + (15 + (Difficulty[((Player number of (Picked player)) - 1)] x 3)))
Custom script: call DestroyForce(udg_Player_Group)
Collapse Custom script: loop
Custom script: exitwhen i > 30
Wait 0.30 seconds
Set Player_Group = (All players matching (Player_Lives[((Player number of (Matching player)) - 1)] Greater than 0))
Collapse Player Group - Pick every player in Player_Group and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Spawn_Loop Less than or equal to (15 + (Difficulty[((Player number of (Picked player)) - 1)] x 3))
Collapse Then - Actions
Set Temp_Point = (Center of Region_Spawn[((Player number of (Picked player)) - 1)])
Unit - Create 1 Spawns[(Level - 1)] for Player 12 (Brown) at Temp_Point facing 270.00 degrees
Custom script: call RemoveLocation(udg_Temp_Point)
Unit - Set the custom value of (Last created unit) to (Player number of (Picked player))
Unit - Set life of (Last created unit) to (50.00 + ((Real((Difficulty[((Player number of (Picked player)) - 1)] - 1))) x 12.50))%
Set Temp_Point = (Center of Region_Leak[((Player number of (Picked player)) - 1)])
Unit - Order (Last created unit) to Move To Temp_Point
Custom script: call RemoveLocation(udg_Temp_Point)
Else - Actions
Custom script: call DestroyForce(udg_Player_Group)
Custom script: set i = i + 1
Custom script: endloop
07-04-2006, 10:25 PM#11
emjlr3
exactly, there are only two loops you can do in GUI, for loop A and loop B

if you use either of these at the same tiem as another, just the same as a global variable, they will cancel each other out and not work

in JASS, what you can do is create a local integer, and loop through that

its easy enough to understand, for ex.

Collapse JASS:
local integer i = 0

loop
    exitwhen i>10
    call DO_ISH
    set i = i + 1
endloop

not only can you loop through something like that, but you can also loop until something is true or false, etc.

for ex.

Collapse JASS:
local unit u = GetTriggerUnit()

loop
    exitwhen GetUnitState(u, UNIT_STATE_LIFE)<50
    call PolledWait(.2)
endloop
call Do_ISH

set u = null

all MUI

this is just another reason in the beggining of understanding why JASS is soo much better then GUI, hope you start taking learning is serious
07-05-2006, 03:30 AM#12
Karawasa
Collapse JASS:
local integer i = 1
loop
        exitwhen i > 30
        call PolledWait( 0.375 )
        set udg_Player_Group = GetPlayersMatching(Condition(function Trig_Start_Level_Func011Func002002001))
        call ForForce( udg_Player_Group, function Trig_Start_Level_Func011Func003A )
        call DestroyForce(udg_Player_Group)
        set i = i + 1
endloop

Well apparently I can, since it saved and looks to work. If for some reason I fucked something up, let me know please. Will test later to determine if this fixes problem.
07-06-2006, 01:24 AM#13
Karawasa
One problem cropped up and that was with this part:

Collapse JASS:
if ( not ( udg_Spawn_Loop <= ( 15 + ( udg_Difficulty[( GetConvertedPlayerId(GetEnumPlayer()) - 1 )] * 3 ) ) ) ) then

When using the JASS loop this condition doesn't fire at all and it produces 30 creeps regardless of difficulty level. Can someone please fix that condition?

Basically, the old loop used udg_spawn_loop and the condition stopped the loop once it reached a certain value, with that value being dependant on udg_difficulty.

This new loop doesn't use that variable and thus the condition isn't doing shit since udg_spawn_loop isn't being used.

Post 2:

Hulk strikes again. SOlved the problem, only testing will tell if this solved Lag.

Edited by Blade.dk. Reason: Double posting..
07-07-2006, 02:34 AM#14
Daxtreme
Quote:
Originally Posted by emjlr3
exactly, there are only two loops you can do in GUI, for loop A and loop B

if you use either of these at the same tiem as another, just the same as a global variable, they will cancel each other out and not work

Can't you use for example one Integer variable for each player specific for this trigger ?

Example : Red_Integer, Blue_Integer, Teal_Integer... and so on.

So since you use one for each player they never can mess up, and since you also use them only in that trigger they won't mess up again...

no?
07-07-2006, 03:47 AM#15
emjlr3
this is true, but again much easier in JASS, no globals needed