Looping Pvars - 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: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Looping Pvars (
/showthread.php?tid=139494)
Looping Pvars -
Dark_Kostas - 05.04.2010
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
Re: Looping Pvars -
Babul - 05.04.2010
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));
Re: Looping Pvars -
biltong - 05.04.2010
You don't need to make any variables with PVars, so where you use
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);
}
Re: Looping Pvars -
Dark_Kostas - 05.04.2010
Quote:
Originally Posted by biltong
You don't need to make any variables with PVars, so where you use 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
Re: Looping Pvars -
Babul - 06.04.2010
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