| 02-27-2005, 01:05 AM | #1 |
ok, im just curious if this will create lag, delays, or even if another trigger would be better. Heres what i did with if/then/else >Event: A unit dies >Action: >>IF owner of dying unit = player 1(red) >>THEN Revive dying unit at region XXX >>ELSE >>>IF owner of dying unit = player 2(blue) >>>THEN revive dying unit at region XXX >>>ELSE >>>>IF owner of dying unit = player 3(teal) >>>>THEN revive dying unit at region XXX >>>>ELSE >>>>>IF owner of dying unit = player 4(purple) >>>>>THEN revive dying unit at region XXX >>>>>ELSE ........................................ and it goes for 8 players, i was wondering if maybe the below trigger would be better to do or if the above way would mess up the game Event: >A unit dies Action: >IF owner of dying unit = player 1(red) >THEN revive dying unit at region XXX >ELSE do nothing >IF owner of dying unit = player 2(blue) >THEN revive dying unit at region XXX >ELSE do nothing and i do this for all players, which is better??thanx guys |
| 02-27-2005, 01:18 AM | #2 |
Guest | Checks to see if the dying unit is one of players 1-8's units then revives it. Code:
Untitled Trigger 001 Events Unit - A unit Dies Conditions Actions For each (Integer A) from 1 to 8, do (Actions) Loop - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Owner of (Triggering unit)) Equal to (Player((Integer A))) Then - Actions Hero - Instantly revive (Triggering unit) at (Center of (Playable map area)), Show revival graphics Else - Actions |
| 02-27-2005, 01:46 AM | #3 |
Guest | Zandose did well on that, anytime you think of repeating things like that, in any kind of programming, do loops. If/Then/Else would work, but it's boring doing all that stuff, if you can use a loop, like is a repeating sequence that changes only a integer number, USE loops, saves time. I Can't be sure that the actions you did will lag, i guess one and only may not lag, but if you do, more and more of them... then only god and nerds know of it. Use zandose's trigger, it's pretty handy ;) |
| 02-27-2005, 05:42 AM | #4 |
thanx, but i dont know how to do loops :( thanx for helping me though |
| 02-27-2005, 08:38 AM | #5 |
as far as if/else goes, conditionals take very very little time to process technically the first way is more efficient, since it will check conditions until one is true and then stop the if/else sequence, but the + is very miniscule ie: if X, no else, if Y, no else, if Z, yes, stop vs if X, no if Y, no if Z, yes if AA, no if BB, no etc... if you ask me, the second way is more appealing to read of course i'm not endorsing either way, just stating the stuff behind it but yeah, go with the loop the only thing is you'll likely want a region array [1-8] so it revives them at the right region instead of all at the center of the map |
| 02-27-2005, 09:02 AM | #6 |
Loops are the FOR action into triggers. It will repeat a stuff a determined number of times. However, you won't find a real loop into trigger like the while() in c++. You will need to use JASS for such a loop. And loops simply repeat a stuff a determined number of times. Keep in mind though that the repeating process is done step by step. So the number of loops won't happen at the same time but one after another. So if you have the following loop Loop (Integer A) for 1 to 5 do actions - Wait 5.00 seconds - Remove Unit(Unit_Group[Integer A]) endloop this won't remove all the units into your Unit_Group after 5 seconds. It will wait 5 seconds, then it will remove the first unit. Then it will wait another 5 seconds after that removing the second unit and so on up to the fifth unit. To make it remove them instantly you could use the following sequence: Wait 5 seconds Loop (Integer A) for 1 to 5 do actions - Remove Unit(Unit_Group[Integer A]) endloop Loops will not reduce the lag. They will only reduce the size of the trigger and make it faster. But your code shouldn't cause any lag. You can however check if number of (Owner of (Picked Unit)) less than or equal to 8. Each player has a number. There are 16 players (1-12, Neutral Passive, Neutral Hostile and other two Neutrals) and so, if you want only players owner by a player and not by a Neutral, just go for players with number less than or equal to 12. ~Daelin |
| 02-27-2005, 07:31 PM | #7 |
Well, I know for a fact that loop triggers do cause some lag. I have 42 if/then/else that gives different abilities to specific units, as long as you own them. Therefore, no possibility for a For loop, because everything is different. When the trigger runs, it creates quite tangebal lag, even in single player. But it's only for a moment... |
| 02-27-2005, 09:33 PM | #8 | |
Quote:
you're mixing things up, the lag isn't created by the loop itself (at least no additional lag (or negligable) compared to regular sequential programming), but possibly the actions inside it since loading spells can do that if you took those actions outside of a loop it would have the same effect in terms of lag (note: if you're running the loop more than 2000 times in 1 go i might say differently then -- or if u simply have a slow computer) and actually there is a possibilty for looping if you put everything into arrays before hand |
| 02-27-2005, 09:39 PM | #9 | |
Quote:
Exactly... Its a complicated topic but its elegant programming. And I've tried copy/pasting 2000 if/then/else statements and ran them all with NO lag, so if/then/else doesnt really make any lag at all. |
| 02-27-2005, 09:46 PM | #10 | |
Quote:
well i was infering that the loop was ran 2000 times so that would be 2000 x 48 i/t/e statements which is ~100000 comparisons which might lag a little bit |
| 02-27-2005, 10:10 PM | #11 |
I must say, however, that it is, INDEED, the If/then/else command that is causing some of the lag. If I run 42 if/then/else's and only 7 out of those are true, then how can it cause such great lag, if there is only about 3-4 actions for each. That's only about 24 actions or so, nowhere near deadly enough to cause lag. But neither should an I/T/E command, but it takes time to check each of those 84 individual conditions(2 for each). Not long, but long enough that I can see the lag. I'd say about 2 seconds. |
| 02-28-2005, 06:44 AM | #12 | |
Quote:
like i said before, its probably the actions of loading up all the spells that lags i have maps where a periodical runs every 0.05 seconds doing at least 20 i/t/e statements looped 200 times, and the actions are mostly mathematical and set statements and that doesn't lag at all |
