17.05.2013, 09:05
I'm trying to make variables private, so they can only be used inside the file where they are declared. The reason for this is because I only want people to access the variable through a function.
Lets say we have example.inc with the following contents:
Then in the main script:
I know PAWN can't utilise the "private" keyword, so I went searching. The SA-MP wiki says:
Could this also be applied for variables? Static variable in my experience are variables that can only be modified once, not really what I'm after, or is it?
Anyone knows how I would implement this? To give you an idea, a Java example of what I would want would be:
Thank you in regards.
Lets say we have example.inc with the following contents:
pawn Код:
new iVariable = 0;
GetVariable()
{
return iVariable;
}
pawn Код:
#include <example>
// This should NOT be possible, since iVariable cannot be accessed directly outside example.inc
iVariable = 5;
// This SHOULD be possible, since we are accessing iVariable though a public function
new iVariableCopy = GetVariable();
iVariableCopy = 5;
Quote:
You can also have static functions which can only be called from the file in which they are declared. This is useful for private style functions. |
Anyone knows how I would implement this? To give you an idea, a Java example of what I would want would be:
pawn Код:
private int iVariable = 5;
public int getVariable() {
return this.iVariable;
}