I wanted to make a countdown button to activate between race end and racerestart and tried this method
It sort of worked, but missed a couple of # in the countdown. After searching around I found that this is a bug, so I tried several different approaches.
Many of them failed
Finally I came up with this for a test private button: Part 1
every iteration to make sure all text and buttons finished exactly at the same time.
I have a couple of questions:
1. Is there a more elegant way of coding this?
2. Where abouts do I put this code so it will be visible between races? (races already restart automatically with $AutoRestartRaceSec = 10; )
There is a much shorter way (see below) but the problem is, it just runs the whole for-loop at once. I can't figure out how to make it wait a little while, but maybe someone else can finish it:
Thanks for the heads up on the FOR loop.
I have tried several ways to create a delay but it seems you cannot break out of a loop to backcall a sub. The backcall still works but only AFTER the loop has finished.
Have messed about with DelayedCommand with no good results.
Yisc's is a more elegant solution, but why didn't you do something like
My sub numbering and cmdLFS might be wrong.
The -1 in the button time in Sub SC1 keeps it open until you close the buttons at end (Sub SC9).
And if you're doing timer for restart, shouldn't you be using global buttons (openGlobalButton) rather than private buttons?
Also, maybe a neat thing to do, would be having the countdown text move on same line from left to right, right to left, left to right, etc, and change text colour every time you change text direction?
Ah yes , I should have thought of leaving all the buttons open during the count then close them all at the end. Was so wrapped up trying to get them all to timout at the same time I forgot about that feature :tired::doh:
The only reason I wasnt using global buttons for the test was that I didnt want to annoy the visitors on my test server with constant timers popping up, but still wanted them there to comment on other aspects of the lapper functions I had implemented.
I'm still struggling to delay the FOR loop so the countdown doesnt happen all at once tho'.
Ok, I have managed to get a working timer that counts down evenly and does not miss any numbers.
The problem with the above method is that, as backcalls use keyflags, the mouse shows on the racing screen while the buttons are active.
So I tried a different method.
This solved the problem of the mouse cursor showing, but the timing is very poor. Some numbers stay visible longer than others during the countdown.
QUESTIONS:
1. Is it possible to show globalbuttons using backcalls and not have the mouse cursor visible?
2. Is it possible to use the delayedcommand method without the timing issues?
3. I have called this event from:-
But although it starts the countdown from the first racer to finish, it also starts a new countdown for anyone else finishing withing the 60 seconds. Anyway to fix that?
I do indeed have Z28.
Let me clarify whats happening.
When in race and the timer is NOT showing, the mouse remains hidden.
When in race and timer IS showing , because the countdown button has a backcall, the mouse becomes visible and the button is clickable until timer runs out, then the mouse returns to its hidden state. The mouse will not hide while the button is active.
SHIFT+Z shows and hides the mouse normally once the buttons are closed.
That's because buttons were initialy created to click on, so you need a mouse for that. In Lapper you can have buttons on which clicking isn't needed, so it would be nice if insim (that's something Scawen has to add) would have an option which indicates a button doesn't need clicking.
1: When a button is clickable ( when you use -1 ) and using a backcall you always get the mouse cursor.
2: I use the delayedcommand method in mine scripts and mostly it works ok, very some time it skips a number but mine server is not the fasted one.(P4 1.5Gz 512Mb) so maybe its that why it skips sometimes a number at mine server.
3: In case of using the Event OnFinish( $userName ) you have to use
Event OnResult( $userName,$flagConfirm ) # Player event IF(GetCurrentPlayerVar("FinishedPos")==1) THEN $delay=60; DelayedCommand( $delay, start_countdown ); ENDIF EndEvent
If you want to start the restart counter as the last driver finish the race you have to count all drivers at the start of race and when someone leave the race its number of drivers - 1 .
At the end of the race just count how many people are finisished the race and by the last start the restart counter. ( and set no mid race join )
I think a non clickable button (or a flag to state clickable on/off in global and private buttons that use backcalls) might be usefull, will post into the request thread.
I'm running a quad core 2.8Ghz with almost no unnecessary tasks running on startup and I still get the odd number missing or uneven timing in the countdown delay scripts or %cpt% functions . I think it has to do with the way lapper handles time.
Thank you for your replies, they are most welcome. I was close to getting it right, after finishing reading all the changelog.txt and playervars.txt. The only thing I was missing was the $flagconfirm , what is this for? I cannot find any reference to it in any of the files I have other than where it is used in lpr files.
Example:
If a player have a 30 second penalty the $flagConfirm must be 16 (CONF_PENALTY_30) + 2 (CONF_CONFIRMED) = 18
If a player have a 45 second penalty the $flagConfirm must be 32 (CONF_PENALTY_45) + 2 (CONF_CONFIRMED) = 34
Event OnResult( $userName,$flagConfirm ) # Player event
SWITCH( GetCurrentPlayerVar("FinishedPos") ) CASE 1: IF( $flagConfirm == 2 || $flagConfirm == 18 || $flagConfirm == 34 ) THEN show and give points