Issue with variables
#1

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

Show the code.
Reply
#3

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;
}

Reply
#4

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)