error 008: must be a constant expression; assumed zero - 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: error 008: must be a constant expression; assumed zero (
/showthread.php?tid=656984)
error 008: must be a constant expression; assumed zero -
3417512908 - 29.07.2018
Don't ask me such as question:"Why don't you direct use 'cmdtext' ?"
I have own reason.
Code:
public OnPlayerCommandReceived(playerid,cmdtext [])
{
new cmd[] = cmdtext;//error 008: must be a constant expression; assumed zero
strdel(cmd, 0, 0);
for(new i = 1; i < MAX_TELEPORT; i++)
{
if(!strcmp(cmd, TeleportData[i][CMD], false) && !isnull(TeleportData[i][CMD]) && !isnull(cmd))
{
SetPlayerPos(playerid,TeleportData[i][PosY],TeleportData[i][PosX],TeleportData[i][PosZ]);
break;
}
}
return 1;
}
Help,please.
Re: error 008: must be a constant expression; assumed zero -
Rufio - 29.07.2018
You can not initiliaze a variable with another variable unless it's a constant and cmdtext isn't a constant variable.
Declare a size for your cmd array like this
Change the size to fit your needs.
Re: error 008: must be a constant expression; assumed zero -
3417512908 - 29.07.2018
Quote:
Originally Posted by Rufio
You can not initiliaze a variable with another variable unless it's a constant and cmdtext isn't a constant variable.
Declare a size for your cmd array like this
Change the size to fit your needs.
|
And what's wrong now:
Code:
new cmd[20];
cmd = cmdtext; //error 047: array sizes do not match, or destination array is too small
Re: error 008: must be a constant expression; assumed zero -
Rufio - 29.07.2018
The array size you've defined is too small for cmdtext to fit, cmd's size is 20, therefore cmdtext must be defined as 20 or below. As we don't have a size for cmdtext, you can't tell PAWN that cmd is equal to cmdtext, it just won't work.
You need to use format.
https://sampwiki.blast.hk/wiki/Format
Also, I don't recommend using 20 for CMD, it was just an example to tell you how it works.
Re: error 008: must be a constant expression; assumed zero -
3417512908 - 29.07.2018
Quote:
Originally Posted by Rufio
The array size you've defined is too small for cmdtext to fit, cmd's size is 20, therefore cmdtext must be defined as 20 or below. As we don't have a size for cmdtext, you can't tell PAWN that cmd is equal to cmdtext, it just won't work.
You need to use format.
https://sampwiki.blast.hk/wiki/Format
Also, I don't recommend using 20 for CMD, it was just an example to tell you how it works.
|
Why I forget it?Thank you!