HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Integer Loop question

07-07-2006, 04:36 AM#1
Daxtreme
I've been using Integer A in my code for mass attacking and it worked. But as it's not MUI, I decided to use a global integer variable with array of size 8 (my number of players).

So after testing it proved to barely work. Remember that the trigger was perfectly working with Integer A. All that I changed was the Integer variable and suddenly the trigger to Mass Attack only looped until he sent HALF of the units.

Why didn't it send them all ?

Here's the trigger :
Trigger:
Attack Red
Collapse Events
Unit - A unit enters Attack Red <gen>
Conditions
Collapse Actions
Set Units_of_Player[(Player number of (Owner of (Entering unit)))] = (Units owned by (Owner of (Entering unit)) matching ((Unit-type of (Matching unit)) Not equal to Mass Attacker))
Set Temp_Point_Arr[(Player number of (Owner of (Entering unit)))] = (Center of AttackerSpawn[(Player number of (Owner of (Entering unit)))])
Unit - Move (Entering unit) instantly to Temp_Point_Arr[(Player number of (Owner of (Entering unit)))]
Collapse For each (Integer Integer_Var_Ar[1]) from 1 to (Number of units in Units_of_Player[(Player number of (Owner of (Entering unit)))]), do (Actions)
Collapse Loop - Actions
Wait 0.02 seconds
Set Temp_Unit_Arr[(Player number of (Owner of (Entering unit)))] = (Random unit from Units_of_Player[(Player number of (Owner of (Entering unit)))])
Set SpawnRed = (Random point in Spawn Red <gen>)
Unit - Order Temp_Unit_Arr[(Player number of (Owner of (Entering unit)))] to Attack-Move To SpawnRed
Unit Group - Remove Temp_Unit_Arr[(Player number of (Owner of (Entering unit)))] from Units_of_Player[(Player number of (Owner of (Entering unit)))]
Custom script: call RemoveLocation(udg_SpawnRed)
Custom script: call RemoveLocation(udg_Temp_Point_Arr[GetConvertedPlayerId(GetOwningPlayer(GetEnteringUnit()))])
Custom script: call DestroyGroup(udg_Units_of_Player[GetConvertedPlayerId(GetOwningPlayer(GetEnteringUnit()))])

When I change Integer_Var_Arr[Index] with Integer A everything works out perfectly. The variable Integer_Var_Arr isn't used in any other triggers : only this one (so it couldn't have been trigger interaction)

I really need to make it work with an Integer variable because using Integer A for every player won't work since if 2 players attack another one within the same minute it will bug.

Any ideas ?
07-07-2006, 05:00 AM#2
SentryIII
After the Wait action, "Entering Unit" would no longer reference the entering unit. You have to set a variable to the entering unit at the beginning of the trigger (before the Wait action), then use that variable to reference that unit. Of course if it's a global variable, other players will replace the reference to your unit with their own, so use a unit array.
07-07-2006, 05:18 AM#3
Alevice
Or a global acting as local ;)

It should be noted you hardcoded the index Integer Integer_Var_Ar to 1.

Trigger:
Attack Red
Collapse Events
Unit - A unit enters Attack Red <gen>
Conditions
Collapse Actions
Custom script: local integer udg_TriggerPlayerIndex = (Player number of (Owner of (Entering unit)))
Set Units_of_Player[TriggerPlayerIndex] = (Units owned by TriggerPlayerIndex matching ((Unit-type of (Matching unit)) Not equal to Mass Attacker))
Set Temp_Point_Arr[TriggerPlayerIndex] = (Center of AttackerSpawn[TriggerPlayerIndex])
Unit - Move (Entering unit) instantly to Temp_Point_Arr[TriggerPlayerIndex]
Collapse For each (Integer Integer_Var_Ar[TriggerPlayerIndex]) from 1 to (Number of units in Units_of_Player[TriggerPlayerIndex]), do (Actions)
Collapse Loop - Actions
Wait 0.02 seconds
Set Temp_Unit_Arr[TriggerPlayerIndex] = (Random unit from Units_of_Player[TriggerPlayerIndex])
Set SpawnRed = (Random point in Spawn Red <gen>)
Unit - Order Temp_Unit_Arr[TriggerPlayerIndex] to Attack-Move To SpawnRed
Unit Group - Remove Temp_Unit_Arr[TriggerPlayerIndex] from Units_of_Player[TriggerPlayerIndex]
Custom script: call RemoveLocation(udg_SpawnRed)
Custom script: call RemoveLocation(udg_Temp_Point_Arr[udg_TriggerPlayerIndex])
Custom script: call DestroyGroup(udg_Units_of_Player[udg_TriggerPlayerIndex])
07-07-2006, 06:42 AM#4
Daxtreme
But then why did it work with the Integer A ?? The Entering unit is still being replaced ! :D

Anyways I'll try it !
07-07-2006, 03:13 PM#5
The)TideHunter(
Quote:
Originally Posted by SentryIII
After the Wait action, "Entering Unit" would no longer reference the entering unit. You have to set a variable to the entering unit at the beginning of the trigger (before the Wait action), then use that variable to reference that unit. Of course if it's a global variable, other players will replace the reference to your unit with their own, so use a unit array.

Since when? Waits have never set GetEnteringUnit() too null before, neither have any of them.
This is either very new, or wrong.
07-07-2006, 03:45 PM#6
Jacek
Description of loops say you can't use waits in loops
07-07-2006, 04:02 PM#7
Alevice
Quote:
Originally Posted by Jacek
Description of loops say you can't use waits in loops

I thought that was only for unit groups, as I use waits on loops without trouble at all.
07-07-2006, 04:25 PM#8
Jacek
Maybe ^^
07-07-2006, 04:32 PM#9
Rising_Dusk
While on this topic...
I wrote this up earlier and tried testing it, but it kept returning prematurely and never showed the BJDebugMsg(...).
Collapse JASS:
function ITestLoops takes nothing returns nothing
    local timer tm = CreateTimer()
    local real tmrem
    
    call TimerStart(tm, 5.00, false, null)
    loop                                    //**********************************
        set tmrem = TimerGetRemaining(tm)   //*It just returns here, doesn't
        exitwhen tmrem <= 0.0               //*ever get out of the loop.
    endloop                                 //*
    call BJDebugMsg("Pass")
    call PauseTimer(tm)
    call DestroyTimer(tm)
    
    set tm = null
endfunction
Why is this happening?
I've been trying to use this as a more accurate substitute for waits in my spells, but it needs to work first. :/
07-07-2006, 04:59 PM#10
Alevice
Try slamming a BJDebugMsg(R2S(tmrem)) in the loop just too see if it is elapsing. Or try running it in a different thread. Or check how polledwait works.
07-07-2006, 05:03 PM#11
PipeDream
No game time elapses while code is running. You've got an infinite loop there that quickly hits the script execution limit.
07-07-2006, 05:12 PM#12
Rising_Dusk
Damnit...
That sucks.

So then is there an alternate way to use waits in loops or not?
07-07-2006, 05:17 PM#13
PipeDream
Nope, you've got to use timer callbacks. While it takes a few more lines the translation is straightforward.
07-07-2006, 06:03 PM#14
Daxtreme
Quote:
Originally Posted by Alevice
Or a global acting as local ;)

It should be noted you hardcoded the index Integer Integer_Var_Ar to 1.

Trigger:
Attack Red
Collapse Events
Unit - A unit enters Attack Red <gen>
Conditions
Collapse Actions
Custom script: local integer udg_TriggerPlayerIndex = (Player number of (Owner of (Entering unit)))
Set Units_of_Player[TriggerPlayerIndex] = (Units owned by TriggerPlayerIndex matching ((Unit-type of (Matching unit)) Not equal to Mass Attacker))
Set Temp_Point_Arr[TriggerPlayerIndex] = (Center of AttackerSpawn[TriggerPlayerIndex])
Unit - Move (Entering unit) instantly to Temp_Point_Arr[TriggerPlayerIndex]
Collapse For each (Integer Integer_Var_Ar[TriggerPlayerIndex]) from 1 to (Number of units in Units_of_Player[TriggerPlayerIndex]), do (Actions)
Collapse Loop - Actions
Wait 0.02 seconds
Set Temp_Unit_Arr[TriggerPlayerIndex] = (Random unit from Units_of_Player[TriggerPlayerIndex])
Set SpawnRed = (Random point in Spawn Red <gen>)
Unit - Order Temp_Unit_Arr[TriggerPlayerIndex] to Attack-Move To SpawnRed
Unit Group - Remove Temp_Unit_Arr[TriggerPlayerIndex] from Units_of_Player[TriggerPlayerIndex]
Custom script: call RemoveLocation(udg_SpawnRed)
Custom script: call RemoveLocation(udg_Temp_Point_Arr[udg_TriggerPlayerIndex])
Custom script: call DestroyGroup(udg_Units_of_Player[udg_TriggerPlayerIndex])


So this would work ?

> Custom script: local integer udg_TriggerPlayerIndex = (Player number of (Owner of (Entering unit)))

I think the editor won't handle this. Since when can you write (Player number of....) in JASS scripts ? Shouldn't it be "GetConvertedPlayerId(GetOwningPlayer(GetEnteringUnit()))"?

Remember my problem guys : this trigger works with Integer A and not with an Integer variable. That's all. The wait works with Integer A, why shouldn't it work with Integer variable? That's the whole point. I've tested it countless of times - the integer variable is bugging. Also... it is an Integer variable used nowhere else !

What alevice wrote there might work. I'll test it. Await my next reply soon

EDIT : I can't even put TriggerPlayerIndex in the variables' indexes. It's a local variable... I gotta use JASS.
07-07-2006, 06:22 PM#15
Anitarf
Quote:
Originally Posted by Daxtreme
EDIT : I can't even put TriggerPlayerIndex in the variables' indexes. It's a local variable... I gotta use JASS.
No, no, see, that's the point of this trick, you make a global variable named TriggerPlayerIndex so you can still use it in GUI, but that custom script overwrites it with a local at the start of the trigger, so when that code actualy runs it will use the local variable.