[Tutorial] Simple way to reset enums - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Simple way to reset enums (
/showthread.php?tid=560318)
Simple way to reset enums -
pellstrike - 28.01.2015
Hi guys. Here's my first tutorial that will show you simple way to reset variable that creates with enum.
First, the way we usually do is:
Код:
enum E_PLAYER_DATA
{
ply_Password[129],
ply_Gender,
ply_Age
// ...
}
new ply_Data[MAX_PLAYERS][E_PLAYER_DATA];
// ...
public OnPlayerConnect(playerid)
{
ply_Data[playerid][Password][0] = EOS;
ply_Data[playerid][Gender] = 0;
ply_Data[playerid][Age] = 0;
// ...
return 1;
}
looks like this.
But, there is a simple way to do this. In pawno, when you create a variable, it resets themselves as a 0(integer) or false(boolean). So the 'simple way' is:
Код:
enum E_PLAYER_DATA
{
ply_Password[129],
ply_Gender,
ply_Age
// ...
}
new ply_Data[MAX_PLAYERS][E_PLAYER_DATA];
// ...
public OnPlayerConnect(playerid)
{
new tmp[E_PLAYER_DATA];
ply_Data[playerid] = tmp;
return 1;
}
This. What we just did was simply copy value of tmp(which is 0 or false) to ply_Data[playerid]. Simple, isn't it?
But you might want to set the default value of single content of this variable. Then what you have to is just set the value of tmp.
Like this:
Код:
enum E_PLAYER_DATA
{
ply_Password[129],
ply_Gender,
ply_Age,
ply_Admin // default is -1
// ...
}
new ply_Data[MAX_PLAYERS][E_PLAYER_DATA];
// ...
public OnPlayerConnect(playerid)
{
new tmp[E_PLAYER_DATA];
tmp[ply_Data] = -1; // got it!
ply_Data[playerid] = tmp;
return 1;
}
That's it
Thanks for watching my tutorial. See you
Re: Simple way to reset enums -
TheRaGeLord - 28.01.2015
Nice, It may help some newbies..