| 01-12-2006, 07:45 PM | #1 |
Will this run ok without adding any delays between loops. I just started using loops rather than unitgroups when I can so I want to make sure I'm doing it all right. JASS:function Trig_Rax_Bonus_Actions takes nothing returns nothing local integer i local integer j=1 local integer k=0 loop exitwhen j>3 if j==1 then set i=(3*CountUnitsInGroup(udg_BarracksGroup[j])) loop exitwhen k>2 call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop elseif j==2 then set i=(3*CountUnitsInGroup(udg_BarracksGroup[j])) loop exitwhen k>5 call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop elseif j==3 then set i=(3*CountUnitsInGroup(udg_BarracksGroup[j])) loop exitwhen k>8 call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop endif set j=j+1 endloop endfunction //=========================================================================== function InitTrig_Rax_Bonus takes nothing returns nothing set gg_trg_Rax_Bonus = CreateTrigger( ) call TriggerRegisterTimerEventPeriodic( gg_trg_Rax_Bonus, 20.00 ) call TriggerAddAction( gg_trg_Rax_Bonus, function Trig_Rax_Bonus_Actions ) endfunction |
| 01-12-2006, 07:48 PM | #2 |
Why are you using the outer loop at all? You could eliminate the loop and if statements and just set j=1 before the first part, j=2 before the second, and j=3 before the last and your code would be much shorter, easier to understand, and would run faster. Loops are for when you want to do the same thing multiple times, but your code uses if statements to do a completely different thing each time through the outer loop. |
| 01-12-2006, 07:56 PM | #3 |
Thanks. Don't know what I was thinking. I'm also assuming I don't need to set k each time since after this first loop it would end up on 3 and then 6 for the last loop. |
| 01-12-2006, 08:01 PM | #4 |
Actually, looking at what he is doing, the loop is fine there, its the if j == (1,2,3) that are unneccesary. It could be refined to: JASS:local integer i local integer j=1 local integer k=0 loop exitwhen j>3 set i=(3*CountUnitsInGroup(udg_BarracksGroup[j])) loop exitwhen k>(3*j-1) call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop set j=j+1 endloop |
| 01-12-2006, 08:06 PM | #5 | |
Quote:
|
| 01-12-2006, 08:08 PM | #6 |
I changed it to this JASS:function Trig_Rax_Bonus_Actions takes nothing returns nothing local integer i local integer k=0 set i=(3*CountUnitsInGroup(udg_BarracksGroup[1])) loop exitwhen k>2 call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop set i=(3*CountUnitsInGroup(udg_BarracksGroup[2])) loop exitwhen k>5 call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop set i=(3*CountUnitsInGroup(udg_BarracksGroup[3])) loop exitwhen k>8 call AdjustPlayerStateBJ( i, Player(k), PLAYER_STATE_RESOURCE_LUMBER ) call AdjustPlayerStateBJ( i*10, Player(k), PLAYER_STATE_RESOURCE_GOLD ) set k=k+1 endloop endfunction //=========================================================================== function InitTrig_Rax_Bonus takes nothing returns nothing set gg_trg_Rax_Bonus = CreateTrigger( ) call TriggerRegisterTimerEventPeriodic( gg_trg_Rax_Bonus, 20.00 ) call TriggerAddAction( gg_trg_Rax_Bonus, function Trig_Rax_Bonus_Actions ) endfunction |
| 01-12-2006, 08:16 PM | #7 |
The best way would be ShadowDragon's code. |
| 01-12-2006, 09:31 PM | #8 |
Further optimization can be achieved by replacing AdjustPlayerStateBJ with the native equivalent. |
| 01-12-2006, 10:48 PM | #9 |
And the native equivalent would be? |
| 01-13-2006, 12:01 AM | #10 |
Look it up in blizzard.j and figure out how to do the same thing with the native SetPlayerState. Thats no bad joke. This is a learning process and its better you try to look yourself. I might help you at a later point, but for now I want you to look yourself. |
| 01-13-2006, 01:28 AM | #11 |
Good lord that file is so damn big. It's easier to ask and find if no one knows, but since you don't want to tell me, ok. |
| 01-13-2006, 01:32 AM | #12 |
even the most primitive text editors have (like notepad) a find function, just make it look for the name of that bj function. but if you want thigs fast: http://jass.sourceforge.net/doc/api/...rce.shtml#7129 |
| 01-13-2006, 10:54 AM | #13 |
or you could download jassshoppro, it automaticly shows if a function is native or bj and shows you the function if it is bj. |
| 01-13-2006, 06:45 PM | #14 |
Ok, maybe this helps you more than nothing Lets look at the function first: http://www.wc3jass.com/viewtopic.php?t=985 See what it does? It also adds the same amount to the respective "gathered" fields. Now the question is, if you need that. If no, its really simple. If yes, its still simple This function calls another non-native (how evil): http://www.wc3jass.com/viewtopic.php?t=984 This function is a one liner, meaning its easy to just copy the function body, paste it and edit it to fit your needs. A call to AdjustPlayerStateBJ would turn to something like this: JASS:call SetPlayerState(Player(k), PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Player(k), PLAYER_STATE_RESOURCE_LUMBER) + i) //only needed when you need "gathered" too; otherwise, leave it out call SetPlayerState(Player(k), PLAYER_STATE_LUMBER_GATHERED, GetPlayerState(Player(k), PLAYER_STATE_LUMBER_GATHERED) + i) For gold its the same, just edit the state names. I hope that helped you. |
