Pawno crashing with the function "random" - 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: Pawno crashing with the function "random" (
/showthread.php?tid=503481)
Pawno crashing with the function "random" -
davve95 - 29.03.2014
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.
Re: Pawno crashing with the function "random" -
Konstantinos - 29.03.2014
"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.
Re: Pawno crashing with the function "random" -
davve95 - 29.03.2014
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!.
Re: Pawno crashing with the function "random" -
Konstantinos - 29.03.2014
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);
}
Re: Pawno crashing with the function "random" -
davve95 - 29.03.2014
Thanks a lot! I'll try it out.