Loop stops suddenly
#1

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]);
                }
            }
        }
    }
Reply
#2

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?
Reply
#3

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.
Reply
#4

Show me where you create the variable call.
Reply
#5

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
Reply
#6

Show us how you declare these arrays:

PlayerCallNumber
call
Reply
#7

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.
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)