The online racing simulator
Quote from Yisc[NL] :Don't be so harsh on your self.
If I'm right, you have just started coding within the Lapper environment, while I have many years of experience.

This piece of code is important in the OnLapperStart event:

$register_counter = ToNum( GetStoredValue( "REGISTER_COUNTER" ) );
IF ($register_counter == "")
THEN
$register_counter=0;
ENDIF

With that counter, which needs to get updated and written into the database, you can retrieve stored values from the database with something like this:

FOR ($i=0;$i<$register_counter;$i=$i+1)
IF (GetStoredValue( "logon_username_" . $i ) == $userName )
THEN
SetCurrentPlayerVar( "logon_code",GetStoredValue( "logon_code_" . $i ) );
SetCurrentPlayerVar( "logon_password",GetStoredValue( "logon_password_" . $i ) );
ENDIF
ENDFOR


Yes, I did it last night. But thanks anyway. There was a problem with sorting values by descending

how do it in Lapper.lpr?
Well i havent created any sorting for my scripts yet.

according to the internet and translating to Lapper, it should look like this.

Sub SortValues($userName)
$TempNumber = 0;
$Numbers = "3|2|10|45|21|4|5|7|9|11";
$GetNumber = SplitToArray($Numbers,"|");
$ValueCount = arrayCount( $GetNumber );

FOR ($i=0;$i<$ValueCount;$i=$i+1)
FOR ($a=1;$a<$ValueCount;$a=$a+1)
IF ($GetNumber[ToNum($i)] < $GetNumber[ToNum($a)]) THEN
$TempNumber = $GetNumber[ToNum($i)];
$GetNumber[ToNum($i)] = $GetNumber[ToNum($a)];
$GetNumber[ToNum($a)] = $TempNumber;
ENDIF
ENDFOR
ENDFOR

### Display list ###

FOR ($j=0;$j<$ValueCount;$j=$j+1)
privmsg("| ".$j." / ".$GetNumber[ToNum($j)]);
ENDFOR
EndSub

but it simply doesnt work for some reason. atm i have no time to figure it out.
I knew I had already written a sorting routine, just didn't know for which module that was, so I used the search of the Lapper sub-forum and typed: sort

Found a topic in which I presented my sessionlaps module and there it was: https://www.lfs.net/forum/post/1910499#post1910499
Then it was a quick copy/paste and voila Smile



Change the extension of the files to .lpr and add them to addonsused.lpr to be able to use it.

Can I be crowned King of the Labper Big grin (people who watch Bones will understand this)
Attached images
Capture.PNG
Attached files
sorting.txt - 2.5 KB - 149 views
Damn, never thought that this was so complicated to create a 'simple' sorting script for lapper. Schwitz

I think there must be a easier way to sort values.

But for you. You are already the Lapperguru. King of lapperscripting. Na-na
I'm feeling dumb, while i see you doing this. Schwitz

Nothing todo here.

*Flies away*
@ num13er & Yisc[NL]

I couldnt let it go, so i went finding out how to create a "simple" way to sort values in an array.

It took me some headaches but i finally came up with a solution. I hope it works also with Values from the Database etc.

Example code:

<?php 
CatchEvent OnMSO
$userName$text # Player event

    
$idxOfFirtsSpace indexOf$text" ");
    IF( 
$idxOfFirtsSpace == -THEN
      $command 
$text;
      
$argv "";
    ELSE
      
$command subStr$text,0,$idxOfFirtsSpace );
      
$argv trimsubStr$text,$idxOfFirtsSpace ) );
    ENDIF

    SWITCH( 
$command )

        CASE 
"!sort"#!sort asc or !sort desc
              
SortValues($argv);
            BREAK;
    ENDSWITCH
EndCatchEvent

Sub SortValues
($TypeSort)
    
$SaveNumber 0;
    
$Numbers "3|2|10|45|21|4|5|11|1|0|300|276|112";
    
$GetNumber SplitToArray($Numbers,"|");
    
$Count_GetNumber arrayCount$GetNumber );
    
    
#Add a '0' to the number to create a 2 or 3 digit number
    #This will also converts string to Numeric characters
        
FOR ($i=0;$i<$Count_GetNumber;$i=$i+1)
        
### Array with values from 0 - 10 ###
            
IF (ToNum($GetNumber[$i]) < 10THEN
                $GetNumber
[$i] = "00".$GetNumber[$i];
            ENDIF
        
### Array with values from 0 - 100 ###
            
IF ((ToNum($GetNumber[$i]) > 9) && (ToNum($GetNumber[$i]) < 100)) THEN
                $GetNumber
[$i] = "0".$GetNumber[$i];
            ENDIF    
        ENDFOR
    
    
###############
    ###Ascending###
    ###############
    
IF($TypeSort == "asc"THEN
        
#Sort values of array in Ascending order
        
FOR ($a=0;$a<$Count_GetNumber;$a=$a+1)
            FOR (
$i=$a;$i<$Count_GetNumber;$i=$i+1)
                    IF( 
$GetNumber[$a] > $GetNumber[$i]) THEN    
                    
                        $SaveNumber 
$GetNumber[$i]."";
                        
$GetNumber[$i] = $GetNumber[$a]."";
                        
$GetNumber[$a] = $SaveNumber."";
                        
                    ENDIF
            ENDFOR
        ENDFOR

        
privmsg("^7[Ascending sort]:");
        
#Display Values
        
FOR ($i=0;$i<$Count_GetNumber;$i=$i+1)
                
privmsg("Pos: [".$i."] = ".$GetNumber[$i]);
        ENDFOR
    ENDIF
    
    
################
    ###Descending###
    ################
    
IF($TypeSort == "desc"THEN
        
#Sort values of array in Descending order
        
FOR ($a=0;$a<$Count_GetNumber;$a=$a+1)
            FOR (
$i=$a;$i<$Count_GetNumber;$i=$i+1)
                    IF( 
$GetNumber[$a] < $GetNumber[$i]) THEN    
                    
                        $SaveNumber 
$GetNumber[$a]."";
                        
$GetNumber[$a] = $GetNumber[$i]."";
                        
$GetNumber[$i] = $SaveNumber."";
                        
                    ENDIF
            ENDFOR
        ENDFOR
        
privmsg("^7[Descending sort]:"); #New line
        #Display Values
        
FOR ($i=0;$i<$Count_GetNumber;$i=$i+1)
                
privmsg("Pos: [".$i."] = ".$GetNumber[$i]);
        ENDFOR
    ENDIF    
EndSub
?>


Attached images
Sort.jpg
Attached files
LFSLapper_Sort.txt - 2.2 KB - 129 views
Nice work Smile
The real solution would be to add sorting of arrays to the source-code of Lapper, so you might want to look into that at some point.
Quote from Bass-Driver :@ num13er & Yisc[NL]

I couldnt let it go, so i went finding out how to create a "simple" way to sort values in an array.

It took me some headaches but i finally came up with a solution. I hope it works also with Values from the Database etc.

Example code:

<?php 
CatchEvent OnMSO
$userName$text # Player event

    
$idxOfFirtsSpace indexOf$text" ");
    IF( 
$idxOfFirtsSpace == -THEN
      $command 
$text;
      
$argv "";
    ELSE
      
$command subStr$text,0,$idxOfFirtsSpace );
      
$argv trimsubStr$text,$idxOfFirtsSpace ) );
    ENDIF

    SWITCH( 
$command )

        CASE 
"!sort":
              
SortValues($argv);
            BREAK;
    ENDSWITCH
EndCatchEvent

Sub SortValues
($TypeSort)
    
$SaveNumber 0;
    
$Numbers "3|2|10|45|21|4|5|11|1|0|300|276|112";
    
$GetNumber SplitToArray($Numbers,"|");
    
$Count_GetNumber arrayCount$GetNumber );
    
    
#Add a '0' to the number to create a 2 or 3 digit number
    #This will also converts string to Numeric characters
        
FOR ($i=0;$i<$Count_GetNumber;$i=$i+1)
        
### Array with values from 0 - 10 ###
            
IF (ToNum($GetNumber[$i]) < 10THEN
                $GetNumber
[$i] = "00".$GetNumber[$i];
            ENDIF
        
### Array with values from 0 - 100 ###
            
IF ((ToNum($GetNumber[$i]) > 9) && (ToNum($GetNumber[$i]) < 100)) THEN
                $GetNumber
[$i] = "0".$GetNumber[$i];
            ENDIF    
        ENDFOR
    
    
###############
    ###Ascending###
    ###############
    
IF($TypeSort == "asc"THEN
        
#Sort values of array in Ascending order
        
FOR ($a=0;$a<$Count_GetNumber;$a=$a+1)
            FOR (
$i=$a;$i<$Count_GetNumber;$i=$i+1)
                    IF( 
$GetNumber[$a] > $GetNumber[$i]) THEN    
                    
                        $SaveNumber 
$GetNumber[$i]."";
                        
$GetNumber[$i] = $GetNumber[$a]."";
                        
$GetNumber[$a] = $SaveNumber."";
                        
                    ENDIF
            ENDFOR
        ENDFOR

        
privmsg("^7[Ascending sort]:");
        
#Display Values
        
FOR ($i=0;$i<$Count_GetNumber;$i=$i+1)
                
privmsg("Pos: [".$i."] = ".$GetNumber[$i]);
        ENDFOR
    ENDIF
    
    
################
    ###Descending###
    ################
    
IF($TypeSort == "desc"THEN
        
#Sort values of array in Descending order
        
FOR ($a=0;$a<$Count_GetNumber;$a=$a+1)
            FOR (
$i=$a;$i<$Count_GetNumber;$i=$i+1)
                    IF( 
$GetNumber[$a] < $GetNumber[$i]) THEN    
                    
                        $SaveNumber 
$GetNumber[$a]."";
                        
$GetNumber[$a] = $GetNumber[$i]."";
                        
$GetNumber[$i] = $SaveNumber."";
                        
                    ENDIF
            ENDFOR
        ENDFOR
        
privmsg("^7[Descending sort]:"); #New line
        #Display Values
        
FOR ($i=0;$i<$Count_GetNumber;$i=$i+1)
                
privmsg("Pos: [".$i."] = ".$GetNumber[$i]);
        ENDFOR
    ENDIF    
EndSub
?>



THX,but i do this)))) my way like your)
Is there no support for linked lists?
This thread is closed

[Solved]How to sort arrays
(8 posts, closed, started )
FGED GREDG RDFGDR GSFDG