Looping Pvars
#1

How can i create something like that with PVars?(Int)

pawn Code:
for(new i;i<10;i++)
{
    if(i == 0) SetPVarInt(playerid, "Car[i]", 600);
    else if(i == 5) SetPVarInt(playerid, "Car[i]", 560);
    else SetPVarInt(playerid, "Car[i]", 0);
}
for(new i;i<10;i++)
{
    printf("Number %d Value %d", i, GetPVarInt(playerid, "Car[i]"));
}
How can i do something like that? It will print always "0" as it is the Set that will be used. I dont want to do it manually Car1 Car2 up to Car10
Reply
#2

using the SetPVar like this wont work, just format your PVariable string (its name) like u would for accessing a file:
Code:
	format(pvarstring,sizeof(pvarstring),"Car%d",carID);
then you can use that formatted name instead of the "Car[i]" to get being processed in any way:
Code:
	SetPVarInt(playerid,pvarstring,123)
	format(line,sizeof(line),"%s %d\r\n",pvarstring,GetPVarInt(TargetID,pvarstring));
Reply
#3

You don't need to make any variables with PVars, so where you use
Code:
Car[i]
is wrong. A simple loop would look like:
pawn Code:
for(new i; i < MAX_PLAYERS; i++)
{
    new string[64];
    format(string, sizeof(string), "Your variable: %i", GetPVarInt(i, "YourVariable");
    SendClientMessage(i, 0xFFFFFFFF, string);
}
Reply
#4

Quote:
Originally Posted by biltong
You don't need to make any variables with PVars, so where you use
Code:
Car[i]
is wrong. A simple loop would look like:
pawn Code:
for(new i; i < MAX_PLAYERS; i++)
{
    new string[64];
    format(string, sizeof(string), "Your variable: %i", GetPVarInt(i, "YourVariable");
    SendClientMessage(i, 0xFFFFFFFF, string);
}
I think you didnt understand what i wanted to do. The loop is not about max_players, but its about Car[Number]
--------------------------------------
Quote:
Originally Posted by Babul
using the SetPVar like this wont work, just format your PVariable string (its name) like u would for accessing a file:
Code:
	format(pvarstring,sizeof(pvarstring),"Car%d",carID);
then you can use that formatted name instead of the "Car[i]" to get being processed in any way:
Code:
	SetPVarInt(playerid,pvarstring,123)
	format(line,sizeof(line),"%s %d\r\n",pvarstring,GetPVarInt(TargetID,pvarstring));
thanks i bet this will work. I was thinking so much time, and it was so simple Thanks again.

EDIT: And yes it worked
Reply
#5

glad to read ^^
i faced the same problem at fiddling around with PVars, it wasnt that hard to figure out that each string can (needs) to be formatted before usage
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)