Replace Thing[MAX_PLAYERS][10]; wtih PVars
#1

So how to use PVars if I need to set each player something with 10 subthings,

Now I have for example:
pawn Код:
new Thing[MAX_PLAYERS][10];

OnSomeWhere()
{
Thing[playerid][0] = 23;
Thing[playerid][1] = 34;
}
and how should I make this with PVars?
Reply
#2

Use this:

SetPVarInt(playerid, "Thing1", 23);
SetPVarInt(playerid, "Thing2", 34);
Reply
#3

Hmm.. this is only way?

because than script getting full very fast, because can't use for(new .....
Thing[playerid][i] = 0; etc
Reply
#4

So, why don't you want to use the variables? I always work with them, its easier to script with them, and better for loops.
Reply
#5

pawn Код:
for (new i = 0; i < MAX_SOMETHING; i++)
{
    new str[20];
    format(str, 20, "Thing%d", i);
    SetPVarInt(playerid, str, 0);
}
Reply
#6

Well, yeah^^, but I read in Server updates page, that its save a lot of Memory, All Variables set to 0 automaticly after player leaves server, also don't need to spam half of script with new Things many....

EDIT, Thx Dice7, I will try
Reply
#7

try to use

SetPVarInt(playerid, "Thing1", 23);
SetPVarInt(playerid, "Thing2", 34);
Reply
#8

Quote:
Originally Posted by dice7
Посмотреть сообщение
pawn Код:
for (new i = 0; i < MAX_SOMETHING; i++)
{
    new str[20];
    format(str, 20, "Thing%d", i);
    SetPVarInt(playerid, str, 0);
}
should be

pawn Код:
for (new i = 0; i < MAX_SOMETHING; i++)
{
    new str[20];
    format(str, 20, "Thing%d", i);
    SetPVarInt(i, str, 0);
}
just spotted that
Reply
#9

Only use PVars for things that need to be shared across scripts, if not, why use PVARS?

Functions are SLOWER than varibles, so the pData array would be best.
Reply
#10

Quote:
Originally Posted by iggy1
Посмотреть сообщение
should be

pawn Код:
for (new i = 0; i < MAX_SOMETHING; i++)
{
    new str[20];
    format(str, 20, "Thing%d", i);
    SetPVarInt(i, str, 0);
}
just spotted that
No.
That would do the following:

Store zero in 'Thing0' for playerid 0
Store zero in 'Thing1' for playerid 1
Store zero in 'Thing2' for playerid 2
Store zero in 'Thing3' for playerid 3
etc
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)