Scope of variables in PAWN? - T0pAz - 28.12.2011
Does PAWN has variables scope? For example Local Variables and Global Variables.
Re: Scope of variables in PAWN? -
CaHbKo - 28.12.2011
Yes.
pawn Код:
new global_var;
function()
{
new local_var;
if(true)
{
new even_more_local_var;
}
}
Re: Scope of variables in PAWN? -
randomkid88 - 28.12.2011
Yes. Variables declared outside of a callback are considered Global (all functions/callbacks can access them). Anything declared inside a function is local, and only usable by that function.
Re: Scope of variables in PAWN? - T0pAz - 28.12.2011
What is it's memory allocation? For example if I do
pawn Код:
//At Top
new A;
//At OnGameModeInit CB
A = 2;
//At OnPlayerSpawn CB
print(A); // Is the variable's A value still 2?
Edit: When will the memory get destroyed?
Re: Scope of variables in PAWN? -
Calgon - 28.12.2011
The value will remain the same regardless of which scope you change it in, as long as it's a global variable.
pawn Код:
new var;
public OnGameModeInit() {
var = 2;
}
//var is always 2 unless changed now
Re: Scope of variables in PAWN? -
Tannz0rz - 28.12.2011
Quote:
Originally Posted by T0pAz
What is it's memory allocation? For example if I do
pawn Код:
//At Top new A;
//At OnGameModeInit CB A = 2;
//At OnPlayerSpawn CB print(A); // Is the variable's A value still 2?
Edit: When will the memory get destroyed?
|
I don't know for sure, but I'd imagine when the program exits.
Re: Scope of variables in PAWN? - T0pAz - 28.12.2011
Quote:
Originally Posted by Calgon
The value will remain the same regardless of which scope you change it in, as long as it's a global variable.
pawn Код:
new var;
public OnGameModeInit() { var = 2; }
//var is always 2 unless changed now
|
Last question. Is there a way to know the memory address of a specific variable? Like using pointers or anything.
Re: Scope of variables in PAWN? -
Calgon - 28.12.2011
Probably via amx_GetAddr and amx_GetString, in C++ with the Pawn/SA-MP libraries.
Re: Scope of variables in PAWN? - T0pAz - 28.12.2011
Quote:
Originally Posted by Calgon
Probably via amx_GetAddr and amx_GetString, in C++ with the Pawn/SA-MP libraries.
|
Anyway to use it on PAWN?
Edit: I need it to prevent hacking.
Re: Scope of variables in PAWN? -
Ash. - 28.12.2011
Quote:
Originally Posted by T0pAz
Anyway to use it on PAWN?
Edit: I need it to prevent hacking.
|
Nope.
+ How on earth are you planning on doing that just by getting the memory addresses?