Questions.
#1

I have been looking about for information about enumerators and return statements, but can't really find a very detailed explanation on either. I was hoping that someone could explain what enumerators are and how to use them and also, all I know about return statements is that they close the previous statement, but I don't see the difference between the return values, such as return 1 or return 0 if someone could explain either of these or both, it would be very appreciated.
Reply
#2

Sure, it's quite simple to use in most cases, while the absolute range is quite wide.

enumerations are like a set of constants, but more like predefined values.
Their usage is mostly used for creating struct like arrays - arrays that contain different information about a certain structure, for instance, a player.
Simple example :
pawn Код:
enum Player {
 cash,
 bool:logged_in,
 Float:other_info
}; // Note ";" is optional as it comes from C but can't be used the same way.
Now to have an array for a player, you'd define it like this :
pawn Код:
new Array[Player];
And you could access it's data in this form :
pawn Код:
Array[cash]=5;
Array[logged_in]=false; // Note the bool: in enum, that means that this value should only be boolean - with bool tag!
Array[other_info]=0.999; // The same with Float.
This works in a way that cash=1 logged_in=2 and other_info=3, so it's like a normal array - almost...
Other, or C/C++ use is more for constants, for instance, as far as I remember, in pawn, if you'd do this:
pawn Код:
new Player:Enumerated;
You could only use the values defined in Player enumeration, so that means, if you'd for example have a value that only must be 0 or 1 or -1 (troolean) then you could define it with enumeration.
So another example as this :
pawn Код:
enum troolean {
positive=1,
zero=0,
negative=-1 } // Note that making an array with this would be... very.. very bad. (Even if it'd work somehow)
new troolean:result;
result=negative;
So here, result can only be 1, 0, -1, but here's an exception :
pawn Код:
result=troolean:1337; // Result becomes 1337
And that weakens the meaning of it, but, of course, if someone does that, he knows he's doing something wrong or specific.
And in it applies for arrays to, for instance, the array created before has dimension that's actually tagged with player, so if you'd use :
pawn Код:
Array[1]
you'd get a warning from compiler. To avoid warning (if you KNOW what you're doing) :
pawn Код:
Array[Player:1]
OR :
pawn Код:
enum _:Player { ...
The second example means that the array's dimension will be tagged as int - normal.
For advanced concepts such as changing incrementation in enum, read pawn_lang.pdf (****** it)

Return is the keyword for every function which indicates that function has done it's job, and if it's not used as :
pawn Код:
return;
then there's the return value, a value that's passed back to the calling function, for example :
pawn Код:
FunctionOne {
new a=FunctionTwo();
}
FunctionTwo { return 5; }
So "a" becomes 5. And i'm not sure will you need advanced concepts of this, but you can do a lot of specific things with return, but the things remains - it's just a return to the main function with a value.
Again, pawn_lang.pdf is your friend.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)