SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 17/12/2019, 04:30 PM   #1
gui13
Little Clucker
 
Join Date: Jun 2018
Posts: 11
Reputation: 1
Default warning 239: literal array/string passed to a non-const parameter

How to solve it?

Warning "warning 239: literal array/string passed to a non-const parameter"
Code:
ShowPlayerMessage(playerid, "Hello! Welcome.", 5);
"ShowPlayerMessage"
Code:
ShowPlayerMessage(playerid, message[], seconds = 0, sound = 0)
{
	KillTimer(PLAYER_TEMP[playerid][pt_TIMERS][17]);
	for(new len = strlen(message), pos; pos < len; pos ++)
	{
		switch(message[pos])
		{
			case '': message[pos] = 151;
			case '': message[pos] = 152;
			case '': message[pos] = 153;
			case '': message[pos] = 154;
			case '': message[pos] = 128;
			case '': message[pos] = 129;
			case '': message[pos] = 130;
			case '': message[pos] = 131;
			case '': message[pos] = 157;
			case '': message[pos] = 158;
			case '': message[pos] = 159;
			case '': message[pos] = 160;
			case '': message[pos] = 134;
			case '': message[pos] = 135;
			case '': message[pos] = 136;
			case '': message[pos] = 137;
			case '': message[pos] = 161;
			case '': message[pos] = 162;
			case '': message[pos] = 163;
			case '': message[pos] = 164;
			case '': message[pos] = 138;
			case '': message[pos] = 139;
			case '': message[pos] = 140;
			case '': message[pos] = 141;
			case '': message[pos] = 165;
			case '': message[pos] = 166;
			case '': message[pos] = 167;
			case '': message[pos] = 168;
			case '': message[pos] = 142;
			case '': message[pos] = 143;
			case '': message[pos] = 144;
			case '': message[pos] = 145;
			case '': message[pos] = 169;
			case '': message[pos] = 170;
			case '': message[pos] = 171;
			case '': message[pos] = 172;
			case '': message[pos] = 146;
			case '': message[pos] = 147;
			case '': message[pos] = 148;
			case '': message[pos] = 149;
			case '': message[pos] = 174;
			case '': message[pos] = 173;
			case '': message[pos] = 64;
			case '': message[pos] = 175;
			case '`': message[pos] = 177;
			case '&': message[pos] = 38;
			default:  message[pos] = message[pos];
		}
	}
	
	PlayerTextDrawSetString(playerid, PlayerTextdraws[playerid][ptextdraw_MESSAGE], message);
	PlayerTextDrawShow(playerid, PlayerTextdraws[playerid][ptextdraw_MESSAGE]);
	
	if(seconds) PLAYER_TEMP[playerid][pt_TIMERS][17] = SetTimerEx("HidePlayerMessage", seconds * 1000, false, "i", playerid);
	if(sound) PlayerPlaySoundEx(playerid, sound, 0.0, 0.0, 0.0);
	return 1;
}
gui13 is offline   Reply With Quote
Old 17/12/2019, 04:53 PM   #2
Deflect
Little Clucker
 
Deflect's Avatar
 
Join Date: May 2019
Posts: 22
Reputation: 10
Default Re: warning 239: literal array/string passed to a non-const parameter

Quote:
Originally Posted by gui13
"ShowPlayerMessage"
There's your problem, try using https://wiki.sa-mp.com/wiki/SendClientMessage that's all.
__________________
^^ CLICK TO JOIN OUR DISCORD ^^
Deflect is offline   Reply With Quote
Old 17/12/2019, 04:53 PM   #3
Ermanhaut
Gangsta
 
Ermanhaut's Avatar
 
Join Date: Apr 2016
Location: Brazil
Posts: 653
Reputation: 47
Default Re: warning 239: literal array/string passed to a non-const parameter

Code:
ShowPlayerMessage(playerid, const message[], seconds = 0, sound = 0)
__________________
try, try and try again
Ermanhaut is offline   Reply With Quote
Old 17/12/2019, 05:00 PM   #4
gui13
Little Clucker
 
Join Date: Jun 2018
Posts: 11
Reputation: 1
Default Re: warning 239: literal array/string passed to a non-const parameter

Quote:
Originally Posted by Ermanhaut View Post
Code:
ShowPlayerMessage(playerid, const message[], seconds = 0, sound = 0)
Code:
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38666) : error 022: must be lvalue (non-constant)
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38666) : error 036: empty statement
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : error 014: invalid statement; not in switch
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : warning 215: expression has no effect
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : error 001: expected token: ";", but found ":"
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : error 029: invalid expression, assumed zero
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : fatal error 107: too many error messages on one line
line 38666 - 38667
Code:
case '': message[pos] = 151;
case '': message[pos] = 152;
gui13 is offline   Reply With Quote
Old 17/12/2019, 06:16 PM   #5
B3x7K
Big Clucker
 
B3x7K's Avatar
 
Join Date: Aug 2017
Location: 惑星黒トカゲ
Posts: 75
Reputation: 3
Default Re: warning 239: literal array/string passed to a non-const parameter

Why you not using
https://wiki.sa-mp.com/wiki/GameTextForPlayer

Sorry to say but your code seems terrible.
__________________

HOW TO ENGLISH?!
AAAAAAAAAAAAAAAA

B3x7K is offline   Reply With Quote
Old 17/12/2019, 06:18 PM   #6
B3x7K
Big Clucker
 
B3x7K's Avatar
 
Join Date: Aug 2017
Location: 惑星黒トカゲ
Posts: 75
Reputation: 3
Default Re: warning 239: literal array/string passed to a non-const parameter

Quote:
Originally Posted by gui13 View Post
Code:
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38666) : error 022: must be lvalue (non-constant)
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38666) : error 036: empty statement
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : error 014: invalid statement; not in switch
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : warning 215: expression has no effect
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : error 001: expected token: ";", but found ":"
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : error 029: invalid expression, assumed zero
C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn(38667) : fatal error 107: too many error messages on one line
line 38666 - 38667
Code:
case '': message[pos] = 151;
case '': message[pos] = 152;
You inserting a constant value, thats why the compiler give you error.

Try recompile using older pawn compiler on github.com/pawn-lang
__________________

HOW TO ENGLISH?!
AAAAAAAAAAAAAAAA

B3x7K is offline   Reply With Quote
Old 17/12/2019, 11:25 PM   #7
RoboN1X
Huge Clucker
 
RoboN1X's Avatar
 
Join Date: Feb 2011
Location: Indonesia
Posts: 406
Reputation: 95
Default Re: warning 239: literal array/string passed to a non-const parameter

copy your argument to a new string that you can modify

either this
pawn Code:
ShowPlayerMessage(playerid, const text[1024], seconds = 0, sound = 0)
{
    new message[1024];
    message = text;

or
pawn Code:
ShowPlayerMessage(playerid, const text[], seconds = 0, sound = 0)
{
    new message[1024];
    strcat(message, text);
did not test, im on mobile right now

EDIT: nvm, give "const" in text, i forgot you would still use the message[] in textdraw anyway
__________________
Need Help? Use Search, WIKI, and FAQ
RoboN1X is offline   Reply With Quote
Old 18/12/2019, 08:52 AM   #8
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 958
Reputation: 167
Default Re: warning 239: literal array/string passed to a non-const parameter

Using an older version of the compiler is not a solution, the behavior is still incorrect.

A literal string is a const array. The function modifies `message` array. It cannot modify a literal string.

Create a local string to store the literal string before calling `ShowPlayerMessage` or copy text from `message` to another local string in `ShowPlayerMessage` function and modify that.
__________________
Calisthenics 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
warning 239: literal array/string passed to a non-const parameter StRaphael Scripting Help 8 04/01/2020 10:34 AM
literal array/string passed to a non-const parameter DuyDang2412 Scripting Help 3 08/07/2019 03:24 AM
ShowPlayerDialog - literal array/string passed to a non-const parameter kaZax Scripting Help 9 18/02/2019 04:49 PM


All times are GMT. The time now is 02:36 PM.


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