| 08-08-2004, 03:12 AM | #1 |
This is how to make a timer system, (for example in Wilderness Survival at the end it tells you how much time it took you to reach the town). Create three integer variables labelled SECONDS, MINUTES, HOURS. Make sure their beginning value is 0. Code:
[color=DarkRed]New Trigger[/color] Events: Time - Periodic Event every 1.00 seconds. Conditions: None Actions: Set Variable (SECONDS) to (SECONDS + 1). [color=DarkRed]New Trigger[/color] Events: Time - Periodic Event every 0.01 seconds. Conditions: If SECONDS is greater than or equal to 60. Actions: Set Variable (MINUTES) to (MINUTES + 1). Set Variable (SECONDS) to 0. [color=DarkRed]New Trigger[/color] Events: Time - Periodic Event every 0.01 seconds. Conditions: If MINUTES is greater than or equal to 60. Actions: Set Variable (HOURS) to (HOURS + 1). Set Variable (MINUTES) to 0. Take a look at the attached map if you wish to read the Triggers directly. |
| 08-08-2004, 03:48 AM | #2 |
Errr why not just use a timer? edit: Oh I see it counts up not down. Still it would be better to use a 1 second repeating timer as a basis for your timer, then you only need to use the "1 second repeating timer" expires event rather than 0.01 periodics... |
| 08-08-2004, 03:49 AM | #3 |
Yeah... a timer works better than that. Plus, that example above is screaming memory leak. |
| 08-08-2004, 01:21 PM | #4 |
I experienced no problems with it...worked just fine for me. |
| 08-08-2004, 07:25 PM | #5 |
Ummm, there might not be any problems, but it's still a poor way to make a timer. It also has massive memory leak if a person stays in the game long enough. |
| 08-08-2004, 09:25 PM | #6 |
A 1 second periodic is the same thing as a 1 second repeating timer internally. (They both use a timer) Personally, if this time is never displayed until the events completion just use a ridiculously huge number 200,000 for istance, and when the event is done just get the time elapsed. MysticGeneral maybe smoking some crack. There is no memory leak, there is however intensive thread generation (every 100th of a second). It may cause lag when the game starts running for about an hour, and should probably never be used in high player multiplayer due to fact that syncronizing at such a low time scale numerous threads is a nightmare. Jass is a multithreaded langauge. It works by a system of parrallel threading, but in actuality it can only really compute one thread at a time. Before it can thrash a thread in multiplayer it must concur that the thread ran to completition on everyones computer...Because the thread queue must be equal on all players machine. (Which is why you can NOT run a trigger only for one player; you may be thinking but what about a thread which only runs for one player, that is entirely different they reach completition at the instance the thread starts for the other players) Since it has a queue of sorts, they keep piling up and before your triggers fire all currently running threads have to finish up. THis creates that multiplayer lag effect. Compiled with poorly written code and bad memory management and after an hour or so of play the game may be desyncing and running like ass. War3 also has to sync up handles. When you leak memory you leave a handle out in memory. Even though the handle may not be referenced at all, it still must sync it and make sure all players have it meaning more time wasted. I.e. "excellent ping" in mplayer is around 100 miliseconds. Assuming the worst case conditions up to ten versions of this thread could be running at once. "good ping" in a multiplayer game is anywhere 100-300 ms. Assuming the worst case condition and you now have up to 30 threads at any given time. "poor ping" in a multiplayer is ussually sub 700 ping and you have about 70 threads at once. "unplayable lag" in a multiplayer game is about a 1 second or more. With a 100 threads running at the best case. A thread queue overflow ussually will crash war3 or hard lock it at about 500 or so. Now due to the fact that even most jass masters still leak (very little but leaking) handles and due to the fact that you want a game that lasts more then a minute. You suddenly have a factor of latency detrigration. Under a generous assumption will assume the average leak is only 20 handles per minute, and you now can in unplayable lag have a 120 things that need to be synced which after an hour can jump to an insane 1300 things that need to be synced. having to sync 1300 objects will probably cause your lag to go from unplayable to total disconnect (should probably happen sooner for some), and probably causing those with crappy memory or low amounts of it to crash war3 and possibly blue screen. In singleplayer though, this is perfectly fine. You not having to sync a damn thing will be able to churn through that thread queue well before it even has two instances of this trigger in it. |
| 08-08-2004, 09:35 PM | #7 |
Real numbers cause memory leak. Everytime a event is used with a real in it, it causes minor memory leak. IIRC. I've been gone for quite a while. |
| 08-08-2004, 09:46 PM | #8 |
Reals do not leak. Reals are primitives. Primitives by thier nature can NOT leak. |
| 08-09-2004, 02:11 AM | #9 |
Oh... I thought they did. Oh well. |
| 09-12-2004, 07:35 PM | #10 |
Real variables, unlike other variables clean themselves up at the end of every trigger. So, it wouldn't cause that bad of lag. But I think the Minute and Hour trigger might(every 0.01 seconds tends to do that at times). I think the following would be better. Variables Secondss - Real Array Minutes - Real Array Hours - Real Array Code:
[color=SlateGray]Time[/color]
[color=red][b]Events:[/b][/color]
Time - Periodic Event every 1.00 seconds
[color=green][b]Conditions:[/b][/color]
[color=gray][b]Actions:[/b][/color]
Pick Every Player in (All Players) and do Actions
Loop (Actions)
Set (Seconds[(Player Number of (Picked Player))]) = (Seconds[(Player Number of (Picked Player))]) + 1.00))
If/Then/Else (Mutliple Actions)
If (Conditions)
(Seconds[(Player Number of (Picked Player))]) Greater than or Equal to 60
Then (Actions)
Set (Minutes[(Player Number of (Picked Player))]) = (Minutes[(Player Number of (Picked Player))]) + 1.00))
Set (Seconds[(Player Number of (Picked Player))]) = 0.00)
If/Then/Else (Multiple Actions)
If (Condtions)
(Minutes[(Player Number of (Picked Player))]) Greater than or Equal to 60
Then (Actions)
Set (Hours[(Player Number of (Picked Player))]) = (Hours[(Player Number of (Picked Player))]) + 1.00))
Set (Minutes[(Player Number of (Picked Player))]) = 0.00)
Else (Actions)
Do Noting
Else (Actions)
Do Nothing
Or is that just me? |
| 09-12-2004, 08:10 PM | #11 | |
Quote:
Where the hell did you hear that? real variables cleaning themselves? they are global variables still they won't clean themselves. Now if you mean that they don't leak, then you are right |
| 09-13-2004, 11:57 PM | #12 | |
Quote:
Yea, thats basicly what I meant. The person I heard from just said it like that so more people could understand it. I just do the same thing basicly for simplicity. |
| 09-14-2004, 10:57 AM | #13 |
First, I don't think the every 0.1 seconds triggers would lagg since the functions used are only some simple math. Second I heard in one of your other posts that you dont know Jass(?), why do you try explaining others such things then? I don't think you know to much about memory leaks when you don't know Jass (well)! And to your version, it it possible, but there are a few more ways you can do it and we don't need to post all here... Just a thought because I don't like when threads blow up because of pretty useless posts... |
| 09-14-2004, 10:19 PM | #14 | |
Quote:
This and like one other forum are the only places I've posted so far. I don't know where I said I know little JASS. I think I know where, and by that I meant, I don't know many functions in JASS that arn't in GUI besides local variables and memory leak prevention stuff. |
