SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/07/2018, 12:29 PM   #1
3417512908
Big Clucker
 
3417512908's Avatar
 
Join Date: Feb 2018
Location: China
Posts: 123
Reputation: 14
Default error 008: must be a constant expression; assumed zero

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.
3417512908 is offline   Reply With Quote
Old 29/07/2018, 12:33 PM   #2
Rufio
Huge Clucker
 
Join Date: May 2011
Location: Turkey
Posts: 412
Reputation: 40
Default Re: error 008: must be a constant expression; assumed zero

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.
Rufio is offline   Reply With Quote
Old 29/07/2018, 12:39 PM   #3
3417512908
Big Clucker
 
3417512908's Avatar
 
Join Date: Feb 2018
Location: China
Posts: 123
Reputation: 14
Default Re: error 008: must be a constant expression; assumed zero

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
3417512908 is offline   Reply With Quote
Old 29/07/2018, 12:45 PM   #4
Rufio
Huge Clucker
 
Join Date: May 2011
Location: Turkey
Posts: 412
Reputation: 40
Default Re: error 008: must be a constant expression; assumed zero

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.
Rufio is offline   Reply With Quote
Old 29/07/2018, 12:50 PM   #5
3417512908
Big Clucker
 
3417512908's Avatar
 
Join Date: Feb 2018
Location: China
Posts: 123
Reputation: 14
Default Re: error 008: must be a constant expression; assumed zero

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.

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!
3417512908 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error 008: must be a constant expression; assumed zero AnoTek Scripting Help 2 16/07/2015 02:29 AM
error 008: must be a constant expression; assumed zero TheKnown Scripting Help 7 20/10/2014 11:56 AM
error 008: must be a constant expression; assumed zero Noliax8 Scripting Help 3 04/07/2014 05:58 PM
Error: Must be a constant expression; assumed zero CTAntonio Scripting Help 3 21/07/2013 09:25 PM
error 008: must be a constant expression; assumed zero ShawnMiller1337 Scripting Help 2 27/08/2012 06:24 PM


All times are GMT. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.