Issue with variables - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Issue with variables (
/showthread.php?tid=305839)
Issue with variables -
Derryd - 24.12.2011
Hey guys, just wondering if any of you have came across this before and how you fixed it.
Basically this warning messages comes up:
local variable "sql" shadows a variable at a preceding level
OK, that's fine. But If I remove/comment out the variable, then the compiler tells me that 'sql' wasn't defined.
WTF?
Re: Issue with variables -
-Rebel Son- - 24.12.2011
Show the code.
Re: Issue with variables -
b.rock - 24.12.2011
it's because you are creating variables with the same name like:
Quote:
new sql; //top
OnPlayerConnect(playerid)
{
new sql;
}
|
to fix it just rename the variables
Quote:
new sql; //top
OnPlayerConnect(playerid)
{
new sql2;
}
|
Re: Issue with variables -
Derryd - 24.12.2011
Quote:
Originally Posted by b.rock
it's because you are creating variables with the same name like:
to fix it just rename the variables
|
Really? But I like keeping everything consistent
Re: Issue with variables -
b.rock - 24.12.2011
well if you create the variables inside callbacks you will not have problems
Quote:
public OnPlayerConnect(playerid)
{
new sql;
}
public OnPlayerDisconnect(playerid, reason)
{
new sql;
}
|
but if you create a variable anywhere in script then create another one with same name you will get that error again
Quote:
new sql: //top
public OnPlayerConnect(playerid)
{
new sql;//error
}
|
You should create the variable "sql" at top of script and not create it again on the whole script