So in my map I have a game mode where the "element picks" (costs a vespene gas) are selected at random for the player. A variant of this is where all players get the same random pick. This is called Same Random Mode. The problem I am running into is when this trigger tries to handle more than one vespene. In other words, the first "random" pick works great. Subsequent ones are different for each player, defeating the purpose. This only applies when I try and do more than one at around the same time (for instance Short Mode starts the player with 3 vespene). If I only progress one at a time with ample time between them then it does not malfunction. I have tried adding a vespene, running trigger, waiting for it to finish, then adding another and repeating. This for some reason does not solve the problem.
Can you describe the problem more clearly ? For eg,In the first one, random rolls 5 and everyone get 5, the next one everyone get different upgrade ? (1346 etc ...)
Yes, the first one always works. When not doing Short or Extra Short Mode, the subsequent ones also work just fine. I believe the problem may lie with the recursion. When there is 3 or 6 vespene to get rid of at the same time, everything after the first is different for each player.
What he said. Just use local variables to get the random stuff, and then parse them through with a cross-check. Wow I really don't want to explain what I just said arg.... Basically have 3 variables, 2 global and 1 local. Have the 2 global ones being "equal" to each other, using one as a reference. At the end of the trigger, if the two global variables aren't the same anymore (AKA another thread accessed them first) then reset the values, and then start the thread over again. Use the local variable for any local modifications, changes, references, etc.
As a technical side note, this is an incredibly simplified version of how Java locks threads.
I resisted the urge to type it out in galaxy, but since I don't know GUI, this is the best pseudo-trigger I could be motivated to write.
// Pseudo trigger// variablesRandomelementSetuserplayergroup// because variables are cheaper than calling the same functions all the time// actionsWhile(getlastplayerinuserplayergroup)vespene>0// you can afford to make this assumption, because you're calling this right after you give the players vespeneSetrandomelementPickeachplayerinuserplayergroupIssuetheordertotheplayerelementstoretopurchasetherandomelement// append to the end, don't replace, or it won't have time for the order to execute
Changing it from recursion to iteration has solved the problem. My hat is off to you. Note, a 0.0 second wait was required at the beginning of the loop. Thanks! Here is the code;
RandomBossesEventsLocalVariablesfinish=true<Boolean>random=0<Integer[15]>
same = 0 <Integer>
Conditions
Actions
General - While (Conditions) are true, do (Actions)
Conditions
(Player (Player (Number of players in Active Player Group) from Active Player Group) Vespene) > 0
Actions
General - Wait 0.0 Game Time seconds
General - If (Conditions) then do (Actions) else do (Actions)
If
Same Random Mode On == false
Then
Player Group - Pick each player in Active Player Group and do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
(Player (Picked player) Vespene) > 0
player Random[(Pickedplayer)] == true
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
(Interest count for player (Picked player), counting Complete) < 1ThenVariable-Setrandom[(Pickedplayer)] =(Randomintegerbetween0and6)ElseVariable-Setrandom[(Pickedplayer)] =(Randomintegerbetween1and6)General-If(Conditions)thendo(Actions)elsedo(Actions)Ifrandom[(Pickedplayer)] ==0ThenUnit-Ordercenterunit[(Pickedplayer)]to(Interest)(ReplaceExistingOrders)ElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfOrConditions(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete)==0AndConditions(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete)==1CurrentWave>= 20
And
Conditions
(Element Upgrade[random[(Pickedplayer)]] count for player (Picked player), counting Complete) == 2
Current Wave >= 40
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
Extra Short Mode On == true
Current Wave == 30
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
(Player (Picked player) Vespene) < 3ThenUnit-Ordercenterunit[(Pickedplayer)]to((GetUpgrade(ElementUpgrade[random[(Pickedplayer)]],(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete))))(ReplaceExistingOrders)ElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete)==0ThenUnit-Ordercenterunit[(Pickedplayer)]to((GetUpgrade(ElementUpgrade[random[(Pickedplayer)]],(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete))))(ReplaceExistingOrders)ElseElseUnit-Ordercenterunit[(Pickedplayer)]to((GetUpgrade(ElementUpgrade[random[(Pickedplayer)]],(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete))))(ReplaceExistingOrders)ElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete)==3ThenUnit-Ordercenterunit[(Pickedplayer)]to(PureEssence)(ReplaceExistingOrders)ElseElseElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfOrConditions(Interestcountforplayer1,countingComplete)>= 1
(Interest count for player 2, counting Complete) >= 1
(Interest count for player 3, counting Complete) >= 1
(Interest count for player 4, counting Complete) >= 1
(Interest count for player 5, counting Complete) >= 1
(Interest count for player 6, counting Complete) >= 1
(Interest count for player 7, counting Complete) >= 1
(Interest count for player 8, counting Complete) >= 1
Then
Variable - Set same = (Random integer between 0 and 6)
Else
Variable - Set same = (Random integer between 1 and 6)
Player Group - Pick each player in Active Player Group and do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
(Player (Picked player) Vespene) > 0
player Random[(Pickedplayer)] == true
Then
Variable - Set random[(Pickedplayer)] = same
General - If (Conditions) then do (Actions) else do (Actions)
If
random[(Pickedplayer)] == 0
Then
Unit - Order center unit[(Pickedplayer)] to ( Interest) (Replace Existing Orders)
Else
General - If (Conditions) then do (Actions) else do (Actions)
If
Or
Conditions
(Element Upgrade[random[(Pickedplayer)]] count for player (Picked player), counting Complete) == 0
And
Conditions
(Element Upgrade[random[(Pickedplayer)]] count for player (Picked player), counting Complete) == 1
Current Wave >= 20
And
Conditions
(Element Upgrade[random[(Pickedplayer)]] count for player (Picked player), counting Complete) == 2
Current Wave >= 40
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
Extra Short Mode On == true
Current Wave == 30
Then
General - If (Conditions) then do (Actions) else do (Actions)
If
(Player (Picked player) Vespene) < 3ThenUnit-Ordercenterunit[(Pickedplayer)]to((GetUpgrade(ElementUpgrade[random[(Pickedplayer)]],(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete))))(ReplaceExistingOrders)ElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete)==0ThenUnit-Ordercenterunit[(Pickedplayer)]to((GetUpgrade(ElementUpgrade[random[(Pickedplayer)]],(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete))))(ReplaceExistingOrders)ElseElseUnit-Ordercenterunit[(Pickedplayer)]to((GetUpgrade(ElementUpgrade[random[(Pickedplayer)]],(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete))))(ReplaceExistingOrders)ElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(ElementUpgrade[random[(Pickedplayer)]]countforplayer(Pickedplayer),countingComplete)==3ThenUnit-Ordercenterunit[(Pickedplayer)]to(PureEssence)(ReplaceExistingOrders)ElseElse
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
So in my map I have a game mode where the "element picks" (costs a vespene gas) are selected at random for the player. A variant of this is where all players get the same random pick. This is called Same Random Mode. The problem I am running into is when this trigger tries to handle more than one vespene. In other words, the first "random" pick works great. Subsequent ones are different for each player, defeating the purpose. This only applies when I try and do more than one at around the same time (for instance Short Mode starts the player with 3 vespene). If I only progress one at a time with ample time between them then it does not malfunction. I have tried adding a vespene, running trigger, waiting for it to finish, then adding another and repeating. This for some reason does not solve the problem.
Can you describe the problem more clearly ? For eg,In the first one, random rolls 5 and everyone get 5, the next one everyone get different upgrade ? (1346 etc ...)
@progammer: Go
Yes, the first one always works. When not doing Short or Extra Short Mode, the subsequent ones also work just fine. I believe the problem may lie with the recursion. When there is 3 or 6 vespene to get rid of at the same time, everything after the first is different for each player.
Can you post how you recursvie this ? Like how does this trigger get called and repeated
If random is a global variable then calling it in multiple threads can cause undesirable bugs. Either make it local or turn it into an array.
Also, if the player still has vespene when the trigger is called, it won't work, right? Because of this condition, I mean:
In that case you might be better off making these non-threaded action definitions and calling them in sequence.
What he said. Just use local variables to get the random stuff, and then parse them through with a cross-check. Wow I really don't want to explain what I just said arg.... Basically have 3 variables, 2 global and 1 local. Have the 2 global ones being "equal" to each other, using one as a reference. At the end of the trigger, if the two global variables aren't the same anymore (AKA another thread accessed them first) then reset the values, and then start the thread over again. Use the local variable for any local modifications, changes, references, etc.
As a technical side note, this is an incredibly simplified version of how Java locks threads.
Great to be back and part of the community again!
I resisted the urge to type it out in galaxy, but since I don't know GUI, this is the best pseudo-trigger I could be motivated to write.
@JademusSreg: Go
Changing it from recursion to iteration has solved the problem. My hat is off to you. Note, a 0.0 second wait was required at the beginning of the loop. Thanks! Here is the code;