PDA

View Full Version : error 008: must be a constant expression; assumed zero


3417512908
29/07/2018, 12:29 PM
Don't ask me such as question:"Why don't you direct use 'cmdtext' ?"
I have own reason.

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.

Rufio
29/07/2018, 12:33 PM
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

new cmd[20];

Change the size to fit your needs.

3417512908
29/07/2018, 12:39 PM
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

new cmd[20];

Change the size to fit your needs.
And what's wrong now:
new cmd[20];
cmd = cmdtext; //error 047: array sizes do not match, or destination array is too small

Rufio
29/07/2018, 12:45 PM
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.

http://wiki.sa-mp.com/wiki/Format

Also, I don't recommend using 20 for CMD, it was just an example to tell you how it works.

3417512908
29/07/2018, 12:50 PM
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.

http://wiki.sa-mp.com/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!:D