Scope of variables in PAWN?
#1

Does PAWN has variables scope? For example Local Variables and Global Variables.
Reply
#2

Yes.

pawn Код:
new global_var;

function()
{
    new local_var;
    if(true)
    {
        new even_more_local_var;
    }
}
Reply
#3

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.
Reply
#4

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

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

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

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.
Reply
#8

Probably via amx_GetAddr and amx_GetString, in C++ with the Pawn/SA-MP libraries.
Reply
#9

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.
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)