Comparing integers -
CloudLEL - 28.04.2016
Hi,
I've got a stupid question that's been stumbelling me for days.
I'm comparing two integers to see if they're the same and if they're the same, returning true, if not returning false.
This works fine, however if the value "orgid" goes above 15 it returns Server: Unknown Command when I use it as a check in my command.
Код:
DoesOrgExistID(orgid)
{
new bool: orgExist = false;
if(orgid == oInfo[orgid][OID])
{
orgExist = true;
printf("Org does exist");
}
return orgExist;
}
EDIT: It actually sometimes makes the server unresponsive for some seconds.
Re: Comparing integers -
Luis- - 28.04.2016
It could be due to you going over the actual number of organisations in your MySQL table. Maybe add some sort of limit.
Re: Comparing integers -
CloudLEL - 28.04.2016
Quote:
Originally Posted by Luis-
It could be due to you going over the actual number of organisations in your MySQL table. Maybe add some sort of limit.
|
I only have 5 in my database, is that a problem?
Re: Comparing integers -
iggy1 - 28.04.2016
Might be accessing 'oInfo' out of bounds. In fact I'm %99 sure you are.
Re: Comparing integers -
Luis- - 28.04.2016
It could very well be, try doing some form of check, for example, checking if it works when you load the fifth organisation and seeing what happens if you attempt to load a sixth.
Re: Comparing integers -
CloudLEL - 28.04.2016
Quote:
Originally Posted by iggy1
Might be accessing 'oInfo' out of bounds. In fact I'm %99 sure you are.
|
What would you suggest to fix this issue?
Re: Comparing integers -
CloudLEL - 28.04.2016
Quote:
Originally Posted by Luis-
It could very well be, try doing some form of check, for example, checking if it works when you load the fifth organisation and seeing what happens if you attempt to load a sixth.
|
I deleted all of the organizations from the table. Now when I go to create one, for example:
/createorg 16
It's checks if that ID already exists with the above function, and it shouldn't have a problem with it because the ID doesn't exist, but instead it just says
Server: Unknown Command
Re: Comparing integers -
CrossUSAAF - 28.04.2016
Show us your global "oInfo" array from top of the script and definition of the limit if there is any.
Re: Comparing integers -
CloudLEL - 28.04.2016
Код:
enum orgInfo
{
OID,
Name[14],
Type,
Color[7],
Skins[3],
Weapons[2],
}
new oInfo[MAX_ORGS][orgInfo];
MAX_ORGS is defined to 15.
Re: Comparing integers -
iggy1 - 28.04.2016
Haven't written a line of pawn for years (apart from bits of help on here) can't remember how sizeof(array) works on multidimensional arrays/enum, so here's a crap example i hope you can adapt.
Код:
DoesOrgExistID(orgid)
{
if(orgid < 15)
{
new bool: orgExist = false;
if(orgid == oInfo[orgid][OID])
{
orgExist = true;
printf("Org does exist");
}
}
else
printf(<"Error> DoesOrgExistID 'oInfo' out of bounds index is %d but size is 15, orgid);
return orgExist;
}
EDIT: Removed sizeof for above reasons.
If you get the error printed, then go back to where you call 'DoesOrgExistID' and make sure you dont use an index over 14.