SA-MP Forums Archive
Loop stops suddenly - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop stops suddenly (/showthread.php?tid=474162)



Loop stops suddenly - ||123|| - 06.11.2013

I'm making something using Textdraws. It uses a loop to TextdrawSetString for 6 textdraws. It has to hide the ones which value = 0. Somehow the code below stops the loop after hiding only one of the textdraws. The loop stops unexpectedly. It should hide all the 6 textdraws.


pawn Код:
if(playertextid == call[playerid][16])
    {
        if(PlayerInfo[playerid][pPhone] == 1)
        {
            if(PlayerCallScreen[playerid] == 17)
            {
                PageNumber[playerid] += 1;
                for(new i = 0; i<6; i++)
                {
                    if(PlayerCallNumber[playerid][PageNumber[playerid]*6+i] == 0)
                    {
                        PlayerTextDrawHide(playerid, call[playerid][i+10]); // This get's called once and the whole loop stops
                    }
                    PlayerTextDrawSetString(playerid, call[playerid][i+10], PlayerCallName[playerid][PageNumber[playerid]*6+i]);
                }
            }
        }
    }



Re: Loop stops suddenly - Konstantinos - 06.11.2013

I'm sure the index is out of bounds, therebefore the code stops working.

Load crashdetect plugin. Goto pawno folder and create a file pawn.cfg
Open it and write in it:
pawn Код:
-d3
Save it and re-compile your script. Run the server (the plugin must be loaded - you should add it into server.cfg file, plugins line at the end). Let it loop again and if it does not work properly, check the console/server log. Did it print anything?


Re: Loop stops suddenly - ||123|| - 06.11.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I'm sure the index is out of bounds, therebefore the code stops working.

Load crashdetect plugin. Goto pawno folder and create a file pawn.cfg
Open it and write in it:
pawn Код:
-d3
Save it and re-compile your script. Run the server (the plugin must be loaded - you should add it into server.cfg file, plugins line at the end). Let it loop again and if it does not work properly, check the console/server log. Did it print anything?
I've checked it thoroughly, the code is working okay as far as I know. If the code would've stopped or 'crashed' I would had recieved a message like Server: Unknown Command. Plus I have a hunch that I'm probably doing something wrong in the script. The code works okay when I'm In game testing too.


Re: Loop stops suddenly - SuperViper - 06.11.2013

Show me where you create the variable call.


Re: Loop stops suddenly - ||123|| - 07.11.2013

I checked and yes the index sometimes goes out of bounds. How do I stop it? or maybe any other way to do the code


Re: Loop stops suddenly - Emmet_ - 07.11.2013

Show us how you declare these arrays:

PlayerCallNumber
call


Re: Loop stops suddenly - DeStunter - 07.11.2013

If you create an array with 16 index's, the index bounds are 0-15 not 1-16.
PlayerTextDrawHide(playerid, call[playerid][i+10]);
PlayerTextDrawHide(playerid, call[playerid][i+9]);

That way when the loop runs the code 6 times it will call 9-15 which is within your bounds.


Re: Loop stops suddenly - ||123|| - 07.11.2013

pawn Код:
new PlayerCallName[MAX_PLAYERS][20][20];
new PlayerCallNumber[MAX_PLAYERS][20];
new PlayerText:call[MAX_PLAYERS][31];
new PageNumber[MAX_PLAYERS];