error 008: must be a constant expression; assumed zero
#1

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.
Reply
#2

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

Code:
new cmd[20];
Change the size to fit your needs.
Reply
#3

Quote:
Originally Posted by Rufio
View Post
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

Code:
new cmd[20];
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
Reply
#4

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.
Reply
#5

Quote:
Originally Posted by Rufio
View Post
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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)