SA-MP Forums Archive
Uncommon problem with an array - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Uncommon problem with an array (/showthread.php?tid=400652)



Uncommon problem with an array - Sasino97 - 19.12.2012

SOLVED
Hello community, I'm developing a new filterscript (the second version of Sasinosoft Houses, remade from scratch), but I have a very strange and uncommon issue.

At the beginning I defined:
pawn Code:
#define INVALID_HOUSE_ID -255
new LastHouse[MAX_PLAYERS];
Then under OnPlayerConnect I put:

pawn Code:
public OnPlayerConnect(playerid)
{
    LastHouse[playerid] = INVALID_HOUSE_ID;
        printf("LastHouse(%d) = %d", playerid, LastHouse[playerid]);
    return 1;
}
And the program will print to the console:
Code:
[19:47:10] [join] Sasino97 has joined the server (0:127.0.0.1)
[19:47:13] LastHouse(0) = 0
when it should be -255.... Another strange thing I noticed is that the second line is printed 3 seconds later.

I put the prints after noticing that error in the system.


Re: Uncommon problem with an array - Ballu Miaa - 19.12.2012

Just to debug it:

pawn Code:
#define INVALID_HOUSE_ID -1

//or

#define INVALID_HOUSE_ID 56
Show me the output. I guess MACROS does not support negative numbers bud i dont think so!


Re: Uncommon problem with an array - Sasino97 - 19.12.2012

Quote:
Originally Posted by Ballu Miaa
View Post
Just to debug it:

pawn Code:
#define INVALID_HOUSE_ID -1

//or

#define INVALID_HOUSE_ID 56
Show me the output. I guess MACROS does not support negative numbers bud i dont think so!
The same:
pawn Code:
#define INVALID_HOUSE_ID 56
Code:
[20:33:08] [join] Sasino97 has joined the server (0:127.0.0.1)
[20:33:10] LastHouse(0) = 0
EDIT:

It's not a problem with the macro, look:
pawn Code:
public OnPlayerConnect(playerid)
{
    LastHouse[playerid] = 15;
    printf("LastHouse(%d) = %d", playerid, LastHouse[playerid]);
    return 1;
}
will also print 0


Re: Uncommon problem with an array - [KHK]Khalid - 19.12.2012

Weird. Look what I got here:
Code:
[22:02:56] Incoming connection: 127.0.0.1:51685
[22:02:57] [join] HellSphinX has joined the server (0:127.0.0.1)
[22:02:57] LastHouse(0) = -255



Re: Uncommon problem with an array - Sasino97 - 19.12.2012

Quote:
Originally Posted by HellSphinX
View Post
Weird. Look what I got here:
Code:
[22:02:56] Incoming connection: 127.0.0.1:51685
[22:02:57] [join] HellSphinX has joined the server (0:127.0.0.1)
[22:02:57] LastHouse(0) = -255
Try it on a filterscript please


Re: Uncommon problem with an array - Ballu Miaa - 19.12.2012

It should work same too! Works in mine too bro!


Re: Uncommon problem with an array - [KHK]Khalid - 19.12.2012

I've already tried it on a filterscript. A gamemode as well - just the same results.


Re: Uncommon problem with an array - Sasino97 - 19.12.2012

I made a blank one for testing this:

pawn Code:
#include <a_samp>
#define DEF 256

new A[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    A[playerid] = DEF;
    printf("CONNECT: A(%d) = %d", playerid, A[playerid]);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    printf("SPAWN: A(%d) = %d", playerid, A[playerid]);
    return 1;
}
Only printed:

Code:
[21:17:35] [join] Sasino97 has joined the server (0:127.0.0.1)
[21:17:37] SPAWN: A(0) = 0
The printf on Connect is completely ignored, it makes me think that OnPlayerConnect isn't called at all...


Re: Uncommon problem with an array - [KHK]Khalid - 19.12.2012

Both CONNECT and SPAWN were printed here. And wasn't OnPlayerConnect called on your first try?


Re: Uncommon problem with an array - Sasino97 - 19.12.2012

SOLVED https://sampforum.blast.hk/showthread.php?tid=148846&page=2 look at [HLF]Southclaw's post.

Thank you guys for trying to help me, I'll add reputation to you too

There was another filterscript loaded before that didn't return anything on OnPlayerConnect and was blocking all the next FSs