[HELP] Optimize Code
#1

Hello,
I returned to program pawn a few days and I'm trying to make a code but can not find a solution to optimize it if someone can help me with what function to use for this would be great.

I need to show the player some PlayerTextDraw, but as it is registered or not, takes leave of showing a PlayerTextDraw, as are many did a loop but in time to remove this single PlayerTextDraw not know how to do.


Not optimally, I not found a solution to my problem to optimize it.
PHP код:
for(new i!= 24i++) {
        if(
DOF2_FileExists(File)) {
            
PlayerTextDrawShow(playeridText_Login[0]);
            
PlayerTextDrawShow(playeridText_Login[1]);
            
PlayerTextDrawShow(playeridText_Login[2]);
            
PlayerTextDrawShow(playeridText_Login[3]);
            
PlayerTextDrawShow(playeridText_Login[4]);
            
PlayerTextDrawShow(playeridText_Login[5]);
            
PlayerTextDrawShow(playeridText_Login[6]);
            
PlayerTextDrawShow(playeridText_Login[7]);
            
PlayerTextDrawShow(playeridText_Login[8]);
            
PlayerTextDrawShow(playeridText_Login[9]);
            
PlayerTextDrawShow(playeridText_Login[10]);
            
PlayerTextDrawShow(playeridText_Login[11]);
            
PlayerTextDrawShow(playeridText_Login[12]);
            
PlayerTextDrawShow(playeridText_Login[13]);
            
PlayerTextDrawShow(playeridText_Login[14]);
            
PlayerTextDrawShow(playeridText_Login[15]);
            
PlayerTextDrawShow(playeridText_Login[16]);
            
PlayerTextDrawShow(playeridText_Login[17]);
            
PlayerTextDrawShow(playeridText_Login[18]);
            
PlayerTextDrawShow(playeridText_Login[19]);
            
PlayerTextDrawShow(playeridText_Login[20]);
            
PlayerTextDrawShow(playeridText_Login[21]);
            
PlayerTextDrawShow(playeridText_Login[22]);
            
//PlayerTextDrawShow(playerid, Text_Login[i]);
        
} else {
            
PlayerTextDrawShow(playeridText_Login[0]);
            
PlayerTextDrawShow(playeridText_Login[1]);
            
PlayerTextDrawShow(playeridText_Login[2]);
            
PlayerTextDrawShow(playeridText_Login[3]);
            
PlayerTextDrawShow(playeridText_Login[4]);
            
PlayerTextDrawShow(playeridText_Login[5]);
            
PlayerTextDrawShow(playeridText_Login[6]);
            
PlayerTextDrawShow(playeridText_Login[7]);
            
PlayerTextDrawShow(playeridText_Login[8]);
            
PlayerTextDrawShow(playeridText_Login[9]);
            
PlayerTextDrawShow(playeridText_Login[10]);
            
PlayerTextDrawShow(playeridText_Login[11]);
            
PlayerTextDrawShow(playeridText_Login[12]);
            
PlayerTextDrawShow(playeridText_Login[13]);
            
PlayerTextDrawShow(playeridText_Login[14]);
            
PlayerTextDrawShow(playeridText_Login[15]);
            
PlayerTextDrawShow(playeridText_Login[16]);
            
PlayerTextDrawShow(playeridText_Login[17]);
            
PlayerTextDrawShow(playeridText_Login[18]);
            
PlayerTextDrawShow(playeridText_Login[19]);
            
PlayerTextDrawShow(playeridText_Login[20]);
            
PlayerTextDrawShow(playeridText_Login[22]);
            
PlayerTextDrawShow(playeridText_Login[23]);
            
//PlayerTextDrawShow(playerid, Text_Login[i]);
        

Sorry for my english.
Reply
#2

I believe this is what you're trying.
Remove the for loop that you put in, it is not placed correctly.
PHP код:
        if(DOF2_FileExists(File)) {
            for(new 
i=0!= 22i++){
                
PlayerTextDrawShow(playeridText_Login[i]);
             }
        } else {
            
Pfor(new i=0!= 23i++){
                
PlayerTextDrawShow(playeridText_Login[i]);
             }
        } 
Reply
#3

pawn Код:
for(new i; i != 24; i++) {
        if(DOF2_FileExists(File)) {
            PlayerTextDrawShow(playerid, Text_Login[i]);
        } else {
            PlayerTextDrawShow(playerid, Text_Register[i]);
        }
Reply
#4

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
pawn Код:
for(new i; i != 24; i++) {
        if(DOF2_FileExists(File)) {
            PlayerTextDrawShow(playerid, Text_Login[i]);
        } else {
            PlayerTextDrawShow(playerid, Text_Register[i]);
        }
You could do this too, but it would be more demanding since every loop it would check the if statement again and again.
If you use the code I posted, it will only run the loop inside the if statement.
Reply
#5

Thank you, I managed to find a way to solve my problem, the two ways mentioned would not work the way I wanted, because a PlayerTextDraw would stay on top of the other, managed to solve the problem with this code:
PHP код:
    if(DOF2_FileExists(GetDataPlayer(playerid))) for(new i!= 23i++) PlayerTextDrawShow(playeridText_Login[playerid][i]);
    else {
        for(new 
i!= 24i++) {
            if(
== 21) continue;
            
PlayerTextDrawShow(playeridText_Login[playerid][i]);
        }
    } 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)