Comparing integers
#1

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.
Reply
#2

It could be due to you going over the actual number of organisations in your MySQL table. Maybe add some sort of limit.
Reply
#3

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?
Reply
#4

Might be accessing 'oInfo' out of bounds. In fact I'm %99 sure you are.
Reply
#5

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.
Reply
#6

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?
Reply
#7

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
Reply
#8

Show us your global "oInfo" array from top of the script and definition of the limit if there is any.
Reply
#9

Код:
enum orgInfo
{
	OID,
	Name[14],
	Type,
	Color[7],
	Skins[3],
	Weapons[2],
}
new oInfo[MAX_ORGS][orgInfo];
MAX_ORGS is defined to 15.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)