SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 24/05/2020, 07:38 PM   #1
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Error 022: must be lvalue (non-constant)

Problem again guys. i will put the code here:

Compile:
Code:
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(886) : warning 225: unreachable code
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2743) : warning 219: local variable "Level" shadows a variable at a preceding level
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2745) : error 022: must be lvalue (non-constant)
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2752) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2752) : warning 206: redundant test: constant expression is non-zero
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2756) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2758) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2759) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2761) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2764) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2743) : warning 203: symbol is never used: "Level"
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(3871) : warning 219: local variable "Angle" shadows a variable at a preceding level
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(3980) : warning 219: local variable "Angle" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Lanes/CMD:
Code:
dcmd_sal(playerid,params[])
{
	new Level,TargetID,file[256];
	new tmp[256], tmp2[256], Index,str[50],str2[50];
	tmp = strtok(params,Index),tmp2 = strtok(params,Index),TargetID = strval(tmp),Level = strval(tmp2);
	format(file,sizeof(file),"ZeroAdmin/Accounts/%s.ini",GetName(TargetID));

	if(Account[playerid][Level] < 5 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_ERROR,"* You need be Level 5 to use this command!");

	if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid, COLOR_ERROR, "{6EF83C}Usage:{FFFFFF} /setadminlevel [playerid] [Level]");

	if(Level > 5 ) return SendClientMessage(playerid,COLOR_ERROR,"Incorrect Level");

	if(!IsPlayerConnected(TargetID))return SendClientMessage(playerid,COLOR_ERROR,"Player is not connected!");

	Account[TargetID][Level] = Level;

	dini_IntSet(file,"Level",Level);
	format(str,sizeof(str),"* You have set %s's AdminLevel to %d *",GetName(TargetID),Level);
	SendClientMessage(playerid,COLOR_ERROR,str);
	format(str2,sizeof(str2),"* Admin %s has made you AdminLevel %d *",GetName(playerid),Level);
	SendClientMessage(TargetID,COLOR_ERROR,str2);
	new string[256];
	format(string,sizeof(string),"* Admin %s has made %s AdminLevel %d *",GetName(playerid),GetName(TargetID),Level);

	SaveLogs("SetLevelLog",string);
	print(string);
	return 1;
}
XBRSAKOSKYX is offline   Reply With Quote
Old 24/05/2020, 08:03 PM   #2
Miqueias Barros
Gangsta
 
Miqueias Barros's Avatar
 
Join Date: May 2010
Location: Brazil 🇧🇷
Posts: 725
Reputation: 31
Default Re: Error 022: must be lvalue (non-constant)

What line?
__________________
Gamemode está no substantivo masculino que traduzido quer dizer "modo de jogo", portanto a expressão não é: "essa gamemode, a gamemode..." e sim: "esse gamemode, o gamemode...".
Miqueias Barros is offline   Reply With Quote
Old 24/05/2020, 08:05 PM   #3
hopeonxanny
Huge Clucker
 
hopeonxanny's Avatar
 
Join Date: Apr 2020
Location: SA-MP Awesomeness: 1998
Posts: 238
Reputation: 4
Default Re: Error 022: must be lvalue (non-constant)

PHP Code:
warning 219local variable "Angle" shadows a variable at a preceding level 
but in your command is no angle.

... umm..
which lines are which? point them...

copy and paste to -> www.pastebin.com
screenshot and upload to -> www.imgur.com
__________________
hopeonxanny is offline   Reply With Quote
Old 24/05/2020, 08:09 PM   #4
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Error 022: must be lvalue (non-constant)

Quote:
Originally Posted by hopeonxanny View Post
PHP Code:
warning 219local variable "Angle" shadows a variable at a preceding level 
but in your command is no angle.

... umm..
which lines are which? point them...

copy and paste to -> www.pastebin.com
screenshot and upload to -> www.imgur.com
The warnings and the error are showing on this cmd:
The angle warning is not a problem, i need to solve the problem with the error & warnings that is showing on this line
This line is the cmd:
Code:
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2743) : warning 219: local variable "Level" shadows a variable at a preceding level
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2745) : error 022: must be lvalue (non-constant)
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2752) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2752) : warning 206: redundant test: constant expression is non-zero
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2756) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2758) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2759) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2761) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2764) : warning 213: tag mismatch
C:\Users\David\Desktop\SAMPserver\gamemodes\testing.pwn(2743) : warning 203: symbol is never used: "Level"
Code:
dcmd_sal(playerid,params[])
{
	new Level, TargetID, file[256];
	new tmp[256], tmp2[256], Index,str[50],str2[50];
	tmp = strtok(params,Index),tmp2 = strtok(params,Index),TargetID = strval(tmp),Level = strval(tmp2);
	format(file,sizeof(file),"ZeroAdmin/Accounts/%s.ini",GetName(TargetID));

	if(Account[playerid][Level] < 5 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_ERROR,"* You need be Level 5 to use this command!");

	if(!strlen(tmp) || !strlen(tmp2)) return SendClientMessage(playerid, COLOR_ERROR, "{6EF83C}Usage:{FFFFFF} /setadminlevel [playerid] [Level]");

	if(Level > 5 ) return SendClientMessage(playerid,COLOR_ERROR,"Incorrect Level");

	if(!IsPlayerConnected(TargetID))return SendClientMessage(playerid,COLOR_ERROR,"Player is not connected!");

	Account[TargetID][Level] = Level;

	dini_IntSet(file,"Level",Level);
	format(str,sizeof(str),"* You have set %s's AdminLevel to %d *",GetName(TargetID),Level);
	SendClientMessage(playerid,COLOR_ERROR,str);
	format(str2,sizeof(str2),"* Admin %s has made you AdminLevel %d *",GetName(playerid),Level);
	SendClientMessage(TargetID,COLOR_ERROR,str2);
	new string[256];
	format(string,sizeof(string),"* Admin %s has made %s AdminLevel %d *",GetName(playerid),GetName(TargetID),Level);

	SaveLogs("SetLevelLog",string);
	print(string);
	return 1;
}
XBRSAKOSKYX is offline   Reply With Quote
Old 24/05/2020, 08:18 PM   #5
Miqueias Barros
Gangsta
 
Miqueias Barros's Avatar
 
Join Date: May 2010
Location: Brazil 🇧🇷
Posts: 725
Reputation: 31
Default Re: Error 022: must be lvalue (non-constant)

What line the command error
Miqueias Barros is offline   Reply With Quote
Old 24/05/2020, 08:26 PM   #6
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Error 022: must be lvalue (non-constant)

https://imgur.com/a/8YwZtUi

Here are some pics of the lines. If anyone could help me solve this would be awessome!
XBRSAKOSKYX is offline   Reply With Quote
Old 24/05/2020, 08:45 PM   #7
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Error 022: must be lvalue (non-constant)

I tried couple of solutions by my self, and finally fixed it! SOLVED!
XBRSAKOSKYX is offline   Reply With Quote
Old 24/05/2020, 09:58 PM   #8
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,712
Reputation: 1671
Default Re: Error 022: must be lvalue (non-constant)

1) https://wiki.sa-mp.com/wiki/Strtok :
Quote:
This function is deprecated and use of it should be avoided where possible.
Better alternatives like sscanf are available for you to use.
2) You should use something like Y_COMMANDS or Pawn.CMD instead of dcmd, it's highly outdated aswell

3) You should use something like Y_INI or MySQL (best choice) instead of Dini, it's also highly outdated. This whole piece of code could be from 2009

4) Did you solve áll warnings? Or only the error? If you only solved the error, consider this (see texts below the quotes with the warnings):
Quote:
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(886) : warning 225: unreachable code
unreachable code: Some of your code will never run ingame. You probably used a return somewhere, and code proceeded after it. Here is an example:
pawn Code:
main()
{
    print("Hello world! You can see this in the console and/or server log!");
    return; //return breaks the function. Using "return 1" you break the function and send value 1 with it (which is used by a calling function (eg. new int = GetPlayerInterior(playerid) ;; GetPlayerInterior() returns a value), or it's used to determine if a certain callback must be called by other scripts (eg. returning 0 in OnPlayerConnect() will block the callback in every other script).
// No function calls main() like that, so returning a value in main() is not needed.
    print("Hello nobody! This will never be printed in the console and/or server log!");
}
Quote:
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(2743) : warning 219: local variable "Level" shadows a variable at a preceding level
Let me explain what this is in a (non making sense) code:
pawn Code:
new myVariable; //variable at a preceding level
myFunction()
{
    new myVariable; //local variable
    new otherVariable;
   //code
}
The local variable should be used instead of the global one (or atleast the one at a preceding level). Not sure because I always avoided this. But you should avoid it too because you could now get things getting mixed up. Since you're getting multiple warnings (and even an error) on lines where "Level" is used, this could cause the issue aswell. And looking at those very same warnings, "Level" is involved all the time.
Quote:
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(2752) : warning 206: redundant test: constant expression is non-zero
It tells you an expression is useless (that's what redundant basically means). This occasially happens if you're doing something like this:
pawn Code:
#define THIS_INT 5
if (THIS_INT == 5) //reduntant, because THIS_INT is 5. Pre-processor changes that to the value of the define so this becomes: if (5 == 5)
Since this warning was shown on the "if (Level...)" line, there really is something wrong with Level. But the compiler already told you that so act on it!!
Quote:
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(2756) : warning 213: tag mismatch
Tag mismatch. Example:
pawn Code:
new MyTag:myVariable = 5, myArray[50];
printf("%d", myVariable); //Tag mismatch: printf() excpects either Float or _ tags, not MyTag.
myVariable = 6; //Tag mismatch: "6" is the same as "_:6". myVariable expects tag MyTag, so this should be "myVariable = MyTag:6";
Above examples couldn't do much harm but it's best to avoid tag mismatches anyway. If it's a more severe problem it's likely to result in an error (eg. wrong parameter usage of a function, like using an array instead of an integer).
Quote:
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(2743) : warning 203: symbol is never used: "Level"
Can't cause issues so easily, but since it was used it is possible that the "Level" at the preceding level was used in your function.
Quote:
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(3871) : warning 219: local variable "Angle" shadows a variable at a preceding level
C:\Users\David\Desktop\SAMPserver\gamemodes\testin g.pwn(3980) : warning 219: local variable "Angle" shadows a variable at a preceding level
See same comment as the other warning with "Level".
Quote:
>> must be lvalue (non-constant) << (the main problem you asked for)
It literally tells you that it bust me a non-constant. Defines (or a variable created with 'const') are constants. It tells you that here. It is likely now that you did define "Level" or something.


You may think warnings aren't that bad, because they are warnings but not errors. They really can be! All those warnings indicated that there is a problem with 'Level'. The whole lvalue error is probably caused by this (I don't have your full code so I can't say for certain). The warnings already told you what was going on.
Don't ignore warnings, they are there for a reason.


p.s.
This could also indicate you forgot a bracket somewhere. But I don't think that's so in this case.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009

Last edited by Kwarde; 24/05/2020 at 10:50 PM.
Kwarde 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 022: must be lvalue (non-constant) AlexMSK Scripting Help 1 30/11/2017 01:56 AM
error 022: must be lvalue (non-constant) 2k16 Scripting Help 0 27/08/2016 05:36 AM
error 022: must be lvalue (non-constant) SandKing94 Scripting Help 3 22/05/2015 01:26 PM
error 022: must be lvalue (non-constant) Voxel Scripting Help 7 10/11/2013 02:53 PM
error 022: must be lvalue (non-constant) BLAbla93 Scripting Help 3 07/03/2012 07:22 AM


All times are GMT. The time now is 11:07 AM.


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