[UNSOLVED] Two loops on one command is not working.
#1

As the title says,

explanation: command /enter does only work for houses and not for the businesses, /test does work with the same code. but just one loop. what is going on here?

pawn Код:
dcmd_enter(playerid,params[]) {
    #pragma unused params
        for(new h = 0; h <= MAX_HOUSES; h++){
          if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
            new Level = HouseInfo[h][hLevel];
            if(HouseInfo[h][hLocked] == 1 && strcmp(HouseInfo[h][hName],PlayerName(playerid), false ) != 0) return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: This house has been locked by the owner.");
            SetPlayerPos(playerid, HousesCoords[Level][0], HousesCoords[Level][1], HousesCoords[Level][2]);
                SetPlayerInterior(playerid, HousesLevels[Level][0]); SetPlayerVirtualWorld(playerid, HouseInfo[h][hVirtualWorld]);
            } }

        for(new i = 0; i <= MAX_BUSINESSES; i++){
                if (PlayerToPoint(1.0, playerid,Business[i][EnterX], Business[i][EnterY], Business[i][EnterZ]))
                {
                    if(GetPlayerVirtualWorld(playerid) == Business[i][EnterWorld])
                    {
                      SetPlayerInterior(playerid,Business[i][ExitInterior]);
                                SetPlayerPos(playerid,Business[i][ExitX],Business[i][ExitY],Business[i][ExitZ]);
                                SetPlayerVirtualWorld(playerid,i);
                                SetPlayerFacingAngle(playerid,Business[i][EnterAngle]);
                    } } }
    return 1;
}

dcmd_test(playerid,params[]) {
for(new i = 0; i <= MAX_BUSINESSES; i++){
                if (PlayerToPoint(1.0, playerid,Business[i][EnterX], Business[i][EnterY], Business[i][EnterZ]))
                {
                    if(GetPlayerVirtualWorld(playerid) == Business[i][EnterWorld])
                    {
                      SetPlayerInterior(playerid,Business[i][ExitInterior]);
                                SetPlayerPos(playerid,Business[i][ExitX],Business[i][ExitY],Business[i][ExitZ]);
                                SetPlayerVirtualWorld(playerid,i);
                                SetPlayerFacingAngle(playerid,Business[i][EnterAngle]);
                    } } }
    return true;
}
Reply
#2

sorry bro, i'm not familiar with dcmd
Reply
#3

I'm not talking about DCMD, I'm talking about LOOPS that are not working. If I'd put the same on strcmp, it'll do the same. And honestly I don't care if you don't have experience with DCMD, quit spam.
Reply
#4

is this variable saving interior code or cordinates?
Код:
HousesCoords[Level][0]
The thing you didn't said is what is not working all of the code?
Reply
#5

Quote:
Originally Posted by silvan
is this variable saving interior code or cordinates?
Код:
HousesCoords[Level][0]
The thing you didn't said is what is not working all of the code?
Yah, what is the problem with your code?
Reply
#6

Looks like an out of bounds error. Your loops run under the condition <= MAX_*, I'm assuming that is your array size too.. This means on the last itteration the index will be too high when you try to access your array.

e.g.

pawn Код:
#define ARRAY_SIZE 3

new my_array[ARRAY_SIZE]; // This array is 3 indices large, but the indices start from 0. So that means 0, 1, 2 are valid indices, NOT 3!

for (new i = 0; i <= ARRAY_SIZE; i++) // continue looping if i is less than OR equal to ARRAY_SIZE
  my_array[i] = 1337; // This loop will do 0, 1, 2, 3 (notice that there is 4 indices! This is the incorrect way)

for (new i = 0; i < ARRAY_SIZE; i++) // continue looping only if i is less than ARRAY_SIZE
  my_array[i] = 1337; // This loop will do 0, 1, 2 (notice that there is 3 indices! This is the correct way)
So change your "<=" to just a "<"..
Reply
#7

Quote:
Originally Posted by silvan
is this variable saving interior code or cordinates?
Код:
HousesCoords[Level][0]
The thing you didn't said is what is not working all of the code?
it has nothing to do with it, does only work for houses quit the spam please.
Quote:
Originally Posted by Simon
Looks like an out of bounds error. Your loops run under the condition <= MAX_*, I'm assuming that is your array size too.. This means on the last itteration the index will be too high when you try to access your array.

e.g.

pawn Код:
#define ARRAY_SIZE 3

new my_array[ARRAY_SIZE]; // This array is 3 indices large, but the indices start from 0. So that means 0, 1, 2 are valid indices, NOT 3!

for (new i = 0; i <= ARRAY_SIZE; i++) // continue looping if i is less than OR equal to ARRAY_SIZE
  my_array[i] = 1337; // This loop will do 0, 1, 2, 3 (notice that there is 4 indices! This is the incorrect way)

for (new i = 0; i < ARRAY_SIZE; i++) // continue looping only if i is less than ARRAY_SIZE
  my_array[i] = 1337; // This loop will do 0, 1, 2 (notice that there is 3 indices! This is the correct way)
So change your "<=" to just a "<"..
Thank you for your explanation and time, I'll try it out, I have MAX_BUS... and MAX_H.. defined at 100 actually i don't have 100 houses / businesses created does it matter?
Reply
#8

bump
Reply
#9

No it won't matter but it is a good idea to keep MAX_HOUSES? as close to the amount you have.
Reply
#10

sorry for the bump, didn't yet test the reply code out.. so no results yet.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)