SA-MP Forums Archive
PVarInts - 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)
+--- Thread: PVarInts (/showthread.php?tid=310149)



PVarInts - Snowman12 - 10.01.2012

Hey,

For my server I am completely changing everything I do. I'm bored of my old scripting methods, however I was wondering if ++ = +1 and -- doesn't work then would -1 work? Or set the int to -1, when using SetPVarInt?

Thanks in advance.

Sorry if it's a noob question normally I wouldn't use -1.

-Snowman


Re: PVarInts - Scenario - 10.01.2012

In my experience, when adding to the value of a PVar, you need to first retrieve the current value, then add the value you're trying to add (that could get confusing). Here's an example:

Instead of doing this:
pawn Код:
SetPVarInt(playerid, "(...)", Value++);
or perhaps this:
pawn Код:
SetPVarInt(playerid, "(...)", GetPVarInt(playerid, "(...)")++);
you need to do this:
pawn Код:
SetPVarInt(playerid, "(...)", GetPVarInt(playerid, "(...)")+iValue);
That's one of the various reasons I tend not to use PVar's for values that are accessed very often.


Re: PVarInts - Snowman12 - 10.01.2012

Very confusing.. How would I take away a int. Like this?

pawn Код:
SetPVarInt(playerid, "IncorrectLogin", GetPVarInt(playerid, "IncorrectLogin")-iValue);
Or is that completely wrong?

Thanks in advance,

-Snowman.


Re: PVarInts - Norck - 10.01.2012

Quote:
Originally Posted by Snowman12
Посмотреть сообщение
Very confusing.. How would I take away a int. Like this?

pawn Код:
SetPVarInt(playerid, "IncorrectLogin", GetPVarInt(playerid, "IncorrectLogin")-iValue);
Or is that completely wrong?

Thanks in advance,

-Snowman.
It's correct.
You can also use it like this:
pawn Код:
SetPVarInt(playerid, "IncorrectLogin", --GetPVarInt(playerid, "IncorrectLogin")); // IncorrectLogin = IncorrectLogin-1
and so on.


Re: PVarInts - Snowman12 - 10.01.2012

Thanks .

Off Topic:
Accept my MSN request please .


Re: PVarInts - Snowman12 - 11.01.2012

Well no nothing is 'wrong' with my code, I'm just getting bored of the old style and looking to develop into newer ways.


Re: PVarInts - Scenario - 11.01.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Why? Is there something wrong with your old code? It sounds like up till now you have been using normal variables which are MUCH better for 99% of things than PVars. They're faster and (contrary to popular belief) smaller.
The only advantage to PVars are that they use less memory, right?


Re: PVarInts - Snowman12 - 11.01.2012

I personally think they save more time and look alot better. But thats just my thinking.


Re: PVarInts - Scenario - 11.01.2012

I think I was mistaken in my post above. PVars were supposed to be more memory efficient, but that isn't the case I'm assuming?