[UNSOLVED] Two loops on one command is not working. -
KnooL - 23.01.2010
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;
}
Re: [UNSOLVED] Two loops on one command is not working. -
silvan - 23.01.2010
sorry bro, i'm not familiar with dcmd
Re: [UNSOLVED] Two loops on one command is not working. -
KnooL - 23.01.2010
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.
Re: [UNSOLVED] Two loops on one command is not working. -
silvan - 24.01.2010
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?
Re: [UNSOLVED] Two loops on one command is not working. -
mansonh - 24.01.2010
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?
Re: [UNSOLVED] Two loops on one command is not working. -
Simon - 24.01.2010
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 "<"..
Re: [UNSOLVED] Two loops on one command is not working. -
KnooL - 24.01.2010
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?
Re: [UNSOLVED] Two loops on one command is not working. -
KnooL - 25.01.2010
bump
Re: [UNSOLVED] Two loops on one command is not working. -
On_Top_Non_Stop - 25.01.2010
No it won't matter but it is a good idea to keep MAX_HOUSES? as close to the amount you have.
Re: [UNSOLVED] Two loops on one command is not working. -
KnooL - 25.01.2010
sorry for the bump, didn't yet test the reply code out.. so no results yet.