private variables
#1

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:
pawn Код:
new iVariable = 0;

GetVariable()
{
    return iVariable;
}
Then in the main script:
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;
I know PAWN can't utilise the "private" keyword, so I went searching. The SA-MP wiki says:

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.

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:
pawn Код:
private int iVariable = 5;

public int getVariable() {
    return this.iVariable;
}
Thank you in regards.
Reply


Messages In This Thread
private variables - by Sinner - 17.05.2013, 09:05
Re: private variables - by RajatPawar - 17.05.2013, 09:10
Re: private variables - by Sinner - 17.05.2013, 09:15
Re: private variables - by Vince - 17.05.2013, 10:47
Re: private variables - by Djole1337 - 17.05.2013, 10:55
Re: private variables - by Slice - 17.05.2013, 12:03
Re: private variables - by Sinner - 17.05.2013, 15:14
Re: private variables - by Slice - 17.05.2013, 15:29
Re: private variables - by Emmet_ - 17.05.2013, 15:33

Forum Jump:


Users browsing this thread: 4 Guest(s)