Help regarding a loop issue.
#1

I'm making a 911 system for the police where they can view all the calls. It seems to constantly replace all 15 slots.

pawn Код:
if(PoliceCall[0][pol_rl] > 0)
            {
                for(new x = 0; x < MAX_POLICECALLS -1; x++)
                {
                    PoliceCall[x + 1][pol_rl] = PoliceCall[x][pol_rl];
                    PoliceCall[x + 1][pol_tih] = PoliceCall[x][pol_tih];
                    PoliceCall[x + 1][pol_tim] = PoliceCall[x][pol_tim];
                    format(PoliceCall[x + 1][pol_loc], 32, "%s", PoliceCall[x][pol_loc]);
                    format(PoliceCall[x + 1][pol_in], 64, "%s", PoliceCall[x][pol_in]);
                    format(PoliceCall[x + 1][pol_nm], 24, "%s", PoliceCall[x][pol_nm]);
                    printf("%s", PoliceCall[x][pol_in]);
                }
            }
            format(PoliceCall[0][pol_loc], 32, "%s", GetLocation(playerid));
            format(PoliceCall[0][pol_in], 64, "%s", PoliceCallP[playerid][pol_in]);
            PoliceCall[0][pol_rl] = PoliceCallP[playerid][pol_rl];
            PoliceCall[0][pol_tih] = THrs;
            PoliceCall[0][pol_tim] = TMins;
I create the new entry afterwards. I replace the [0] slot and move the 0 slot to the next slot, could anyone assist?

Thanks.
Reply
#2

Yeah I mentioned you might need to re-work some logic now I am looking at it the problem is you are shifting the values in the wrong order. You need to start from the last entry and shift the previous entry.

Example

Код:
for(new x = MAX_POLICECALLS - 1; x > 0; x--)
{
	PoliceCall[x][pol_rl] = PoliceCall[x - 1][pol_rl];
	...
}
If you start at the start of the array then you are going to just copy all the data of the first index to every other index instead of shifting it. This will trash any data in the last index.
Reply
#3

I thought the x++ part was where it increased the x and therefore adds one to it each time so it's copying the last?

I may be confused.

Will the example above work?

Thanks again. I'm seriously confused right now.
Reply
#4

yeah it should be x-- my fault LOL!
Reply
#5

Thank you, will give that a try.
Reply
#6

It's fixed the order but I'm still having an issue with the Name, it copies to the first one (as in 0 and 1.) Everything else is correct, though.
Reply
#7

Still unresolved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)