index was outside the bounds of the array
#1

Hey, I'm running a SA-MP Server Query script based on C# given here - https://sampwiki.blast.hk/wiki/Query_Mechanism/Csharp

When I integrate the script in my SA-MP Custom client and run it, I get thrown with this error.

"Index was outside the bounds of the array"

The error occurs when query is sent and received to update playersonline count.

Any help would be appreciated.

Code:

Code:
string[] serverInfo;

            Query.Query sQuery = new Query.Query("XX.XX.XX.XX", 7777);
            sQuery.Send('i');
            int count = sQuery.Receive();
            serverInfo = sQuery.Store(count);
            PlayersOnline.Text = serverInfo[1];
Reply
#2

Not sure about that, but the error is caused by accessing the serverInfo array, which is 0 in size, as the sQuery.Store didn't populate the array.

You need to checkout the output of sQuery.Store
Reply
#3

Quote:
Originally Posted by ShihabSoft
View Post
Not sure about that, but the error is caused by accessing the serverInfo array, which is 0 in size, as the sQuery.Store didn't populate the array.

You need to checkout the output of sQuery.Store
The code isn't modified, it's the same as given in official SA-MP wiki (in link I mentioned). Could you take a look at it?

Also serverInfo array for 'i' has 5 elements in it. I'm accessing the 2nd element in it which is Online Player Count. It's displaying and updating accurately. I've added a timer on the form.cs so that it loads the form every 10seconds. The server query is set to trigger on form load so every 10seconds it receives info from the server and updates it on the form. It's all working fine, just that I get this index was outside the bounds of the array issue.
Reply
#4

Any help? Unable to sort it out.
Reply
#5

Quote:
Originally Posted by OscarMike
View Post
The code isn't modified, it's the same as given in official SA-MP wiki
Doesn't matter. The wiki is freely editable by everyone. This code is not wrong per se but it assumes the server to be reachable. If the server is unreachable you won't get any information and hence errors will show up.
Reply
#6

Quote:
Originally Posted by Vince
View Post
Doesn't matter. The wiki is freely editable by everyone. This code is not wrong per se but it assumes the server to be reachable. If the server is unreachable you won't get any information and hence errors will show up.
It is reachable, hence I am able to query it and get PlayersOnline list.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)