While Loop Problem -
ToiletDuck - 05.01.2017
I wondered why this loop doesnt work well on Large Value Imean damn its really hard to explain. Im having a hard time for this bug damn, At first Small/Medium Max slot it really works well but then when it comes to Large slot the loop doesnt work well it doesnt read or execute the last digit. it always stucked at 148 it doesnt execute after that count I wondered why
Small = 49 (Works perfectly)
Medium = 99 (works perfectly)
Large = 149 (Even i change the value of it still it doesnt execute the last count, Stucked at 148 Count and it doesnt shows the damn Dialog)
GetHouseFurnitureMax returns the max value of of slot. Simply return Small, return Medium
Code:
strcat(bigstring, "House Furnitures:\tStatus:");
while(fPage[playerid] < GetHouseFurnitureMaxSlot(hID)) {
fPage[playerid]++;
for(new u;u<sizeof(FurnituresData);u++)
{
if(FurnitureInfo[hID][fPage[playerid]][FModel] == INVALID_FURNITURE_ID) {
format(string, sizeof(string), "%d - {FF6347}Empty",fPage[playerid] ,FurnituresData[u][fName]);
}
else {
if(FurnituresData[u][fObject] == FurnitureInfo[hID][fPage[playerid]][FModel])
{
format(name, sizeof(name), "%s", FurnituresData[u][fName]);
}
if(FurnitureInfo[hID][fPage[playerid]][FPosX] != 0.0) format(string, sizeof(string), "%d - %s\t{33AA33}in house", fPage[playerid], name); // Edit
else format(string, sizeof(string), "%d - %s\t{0000FF}in storage", fPage[playerid], name); // Place
}
}
format(bigstring, sizeof(bigstring), "%s\n%s", bigstring, string);
format(string, sizeof(string), "Furniture Count: %d", fPage[playerid]); //debug print
SendClientMessageEx(playerid, COLOR_YELLOW, string);
if(++slotcount == 10)
{
strcat(bigstring, "\nBack Page");
strcat(bigstring, "\nNext Page");
format(titlestring, sizeof(titlestring), "{33AA33}House Furnitures{FFFFFF} Slot (%d/%d)",HouseInfo[hID][FCount], GetHouseFurnitureMaxSlot(hID));
ShowPlayerDialog(playerid, DIALOG_EDIT_FURNITURE, DIALOG_STYLE_TABLIST_HEADERS, titlestring, bigstring, "Select", "Cancel");
break;
}
}
format(string, sizeof(string), "Furniture Count: %d", fPage[playerid]); //debug print
SendClientMessageEx(playerid, COLOR_NEWS, string);
This is the log print of Large Max Slot (149 value)
It always stuck at 148 it doesn't execute further more that makes the code bug after that it doesnt show the Dialog
And this is the log print of Medium Max Slot (99 Value)
This one works perfectly it does execute at the last count
Re: While Loop Problem -
ToiletDuck - 05.01.2017
Oh damn i think I just posted in a wrong section. any Moderator can move this? Thanks.
one more thing does my code wrong? or anyone encounter this issue? I dont really get it I just though it was the While loop bug or just my error. (Sorry for this bump)
Re: While Loop Problem -
Stinged - 05.01.2017
I'm on my phone so I can't really read the code and find the error, but do you have crashdetect installed?
Here's an example of what I mean:
Code:
new array[5];
for (new i = 0; i <= 5; i++)
{
array[i] = i;
printf("%i", array[i]);
}
print("Success");
Without crashdetect it would look like this (in the console):
(No "success" printed).
But with crashdetect it would tell you that the index you're trying to access is out of bounds (5 here)
Re: While Loop Problem -
Kar - 06.01.2017
Show your GetHouseFurnitureMaxSlot.
Re: While Loop Problem -
ToiletDuck - 06.01.2017
Quote:
Originally Posted by Stinged
I'm on my phone so I can't really read the code and find the error, but do you have crashdetect installed?
Here's an example of what I mean:
Code:
new array[5];
for (new i = 0; i <= 5; i++)
{
array[i] = i;
printf("%i", array[i]);
}
print("Success");
Without crashdetect it would look like this (in the console):
(No "success" printed).
But with crashdetect it would tell you that the index you're trying to access is out of bounds (5 here)
|
I mean the loops works fine but then when its on Large MAx slot loops doesnt work well
Quote:
Originally Posted by Kar
Show your GetHouseFurnitureMaxSlot.
|
Code:
#define MAX_FURNITURE_SMALL 49
#define MAX_FURNITURE_MEDIUM 99
#define MAX_FURNITURE_LARGE 149
stock GetHouseFurnitureMaxSlot(houseid) {
switch(HouseInfo[houseid][hSize])
{
case 1: return MAX_FURNITURE_SMALL;
case 2: return MAX_FURNITURE_MEDIUM;
case 3: return MAX_FURNITURE_LARGE;
default: return -1;
}
return 0;
}
Re: While Loop Problem -
PrO.GameR - 06.01.2017
it obviously crashes somewhere around here
FurnitureInfo[hID][
fpage[playerid] ]as I'm assuming size of this is also MAX_FURNITURE_LARGE?
It crashes because you use 149 as index number, when it only allows from 0-148.
I also believe it doesn't use FurnitureInfo[hID][0][FModel] at all due to your code, can you confirm that it's empty or not?
my solution is just move your fpage[playerid]++ to the end of loop or just remove it and change the while condition to (++fpage[playerid]< GetHouseFurnitureMaxSlot(hID))
Re: While Loop Problem -
azzerking - 17.01.2017
Please tell us what
GetHouseFurnitureMaxSlot( house_id ) returns and what
FurnituresData size is.
Remember that if you have an enum that holds 150 objects at max, then you can only loop through 149. 0 - 149.