The online racing simulator
[Solved] RegisterScheduleAction - FOREACH
Problem:
1. Every second the timer is supposed to execute, it only executes once on lapper start.
2. $mList - It reports as 0 entries even though I'm online.
3. Even if I remove every line except the first one ( to report the time ) it only runs once.
#. Error logs say nothing Frown

Has anyone encountered this problem before? it works for me for scheduled actions of 1 minute tho...


CatchEvent OnLapperStart()
# Some functions ... #
RegisterScheduleAction( "* * * * * * *", Second_Timer ); # Execute every second.
EndCatchEvent

Sub Second_Timer() # Timer #
writeline( "RSB_Time timer " . GetLapperVar( "longtime" ) );
$mList = GetListOfPlayers();
$mListCount = arrayCount( $mList ); # Reports as 0 entries.
writeline( "RSB_Time $mList: " . $mListCount . " entries: " . $mList[0] . ", " . $mList[1] . "." );
FOREACH ( $maVar IN $mList )
writeline( "RSB_Time FOREACH" );
IF ( GetPlayerVar( $maVar["value"] , "UserName" ) != "" ) # Not Host #
THEN
# DO SOMETHING #
writeline( "RSB_Time Username exists" );
IF ( GetPlayerVar( $maVar["value"] , "Delivery" ) != "" )
THEN
$distance = ToNum( trackuserdistance( GetPlayerVar( $maVar["value"] , "Delivery" ) , $maVar["value"] ));
IF ( $distance < 5 )
THEN
SetPlayerVar( $maVar["value"] , "DeliveryTick" , ToNum( GetPlayerVar( $maVar["value"] , "DeliveryTick" ) + 1 ) );
$TickCount = ToNum(GetPlayerVar( $maVar["value"] , "DeliveryTick" ));
IF ( $TickCount >= 3 )
THEN
SetPlayerVar( $maVar["value"] , "DeliveryStatus" , "1" );
$DeliverToUserID = GetPlayerVar( GetPlayerVar( $maVar["value"] , "Delivery" ) , "UserID" ); #Get Receiving Player UCID.
FOREACH ( $CompanyArray IN $Companies )
$OrderVar = ToString( "UserName_Order_" . $CompanyArray["value"] . "_" . $DeliverToUserID );
$OrderCompany = ToString( $CompanyArray["value"] );
IF ( GetStoredValue( $OrderVar ) != "" )
THEN
$DeliverToNickName = GetPlayerVar( GetStoredValue( "UserName_Number_" . $DeliverToUserID ) , "NickName" );
PrivMsg( $maVar["value"] , "^7You have ^2successfully delivered ^7to " . $DeliverToNickName );
Delivery_Order_Delivered( $OrderCompany , $DeliverToUserID );
ENDIF
ENDFOREACH
ENDIF
ENDIF
ENDIF
ENDIF
ENDFOREACH
EndSub

Temp fix: wrote a RegisterScheduleAction for every second from 00 to 59 T_T
** Best answer **
i'm not sure if lapper suppose to execute RegisterScheduleAction() every second when all parameters are disabled.

In my Idle/AFK script, i have done it like this:
Basically i also set every second aswell, like you did


<?php 
CatchEvent OnLapperStart
()
     
##Set first second (0)
    
GlobalVar $IdleAFKTimer$IdleAFKTimer "0 * * * * * * ";
     
##Create a string from second (1) to second (59)  0 * * * * * * : 1 * * * * * * : 2 * * * * * * etc
    
FOR($i=1;$i<60;$i=$i+1)
        
$IdleAFKTimer $IdleAFKTimer " : ".$i." * * * * * *";
    ENDFOR
     
##Set Registeraction with the string you created above 
    
RegisterScheduleAction"".$IdleAFKTimer.""RSA_IdleTimer);
EndCatchEvent
?>


The internal codes for RegisterScheduleAction() has been changed, because when Lapper hangs up for a second(when someone is leaving the pitbox), a created loop couldnt continue, because the set seconds didnt matched with the real time.
Thanks, it actually looks much cleaner than setting RegisterScheduleAction 60 times lel.

Can't believe I hadn't thought of this Face -> palm
This thread is closed

[Solved] RegisterScheduleAction - FOREACH
(3 posts, closed, started )
FGED GREDG RDFGDR GSFDG