Pawno crashing with the function "random"
#1

Hi!

I tired out the Random function for fun, for learning more Pawn.

Anyway: Pawno just crashing..

Her's the code:

pawn Код:
#define FILTERSCRIPT

#include <a_samp>

#if defined FILTERSCRIPT

#define blue 0x6709E3FF
#define green 0x0CCC19FF
#define black 0x0A0A0AFF
#define turquoise 0x6DD9F7FF



public OnFilterScriptInit()
{

    return 1;
}

#else

#endif


public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/rand", cmdtext, true, 10) == 0)
    {
        new rand = random(sizeof(random));
        return 1;
    }
    return 0;
}

new random [] [] =
{
    SendClientMessage(playerid, blue, "Blue";
    SendClientMessage(playerid, green, "Green";
    SendClientMessage(playerid, black, "Black";
    SendClientMessage(playerid, turquoise, "Tturquoise"
    GivePlayerCash(playerid, 5000);

}
Btw first time I test this function.
Reply
#2

"random" is a function from core.inc; therebefore declaring it as array and then using it in sizeof will most likely result on a crash to the editor. Use another name.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
"random" is a function from core.inc; therebefore declaring it as array and then using it in sizeof will most likely result on a crash to the editor. Use another name.
Oh, I see!..

I tired with "test" instead, it's still crashing though!.
Reply
#4

I just noticed it. You used player's functions inside the array like they were data which is incorrect. Using switch instead of an array is much better:
pawn Код:
switch (random(5))
{
    case 0: SendClientMessage(playerid, blue, "Blue");
    case 1: SendClientMessage(playerid, green, "Green");
    case 2: SendClientMessage(playerid, black, "Black");
    case 3: SendClientMessage(playerid, turquoise, "Tturquoise");
    case 4: GivePlayerCash(playerid, 5000);
}
Reply
#5

Thanks a lot! I'll try it out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)