21.08.2012, 13:52
Introduction:
I've seen Incognito's GVar Plugin a while ago, and I had the idea implementing GVars by using properties (core.inc).
GVars are like PVars, but global.
They are global variables which can be created/deleted/altered dynamically.
I also added some functions to store/load hexadecimal, boolean and binary values.
Note: I couldn't find a good way to implement three functions which are:
GetGVarNameAtIndex,
GetGVarType,
GetGVarsUpperIndex.
Once I find a good way of implementing them, I'll release it for sure.
Version:
• GVar v1.0 - Initial Release.
Known Bugs:
- None, if you do find a bug please make sure you report it to me so I can fix it!
Functions:
Installing:
Like any other include, put it in your includes folder and add it to your script:
Should look like this:
Speed:
Worried about speed?
I have done some benchmarks using Slice's code: https://sampforum.blast.hk/showthread.php?tid=218491
Here are the results for each function:
Downloads:
- GVar v1.0 - http://www.solidfiles.com/d/4ae6e76669/
(Please do not make any mirrors or upload to pastebin, thanks)
So that's about it, using it is very simple, just like PVars.
If you have any suggestions about improving the code, let me know!
I've seen Incognito's GVar Plugin a while ago, and I had the idea implementing GVars by using properties (core.inc).
GVars are like PVars, but global.
They are global variables which can be created/deleted/altered dynamically.
I also added some functions to store/load hexadecimal, boolean and binary values.
Note: I couldn't find a good way to implement three functions which are:
GetGVarNameAtIndex,
GetGVarType,
GetGVarsUpperIndex.
Once I find a good way of implementing them, I'll release it for sure.
Version:
• GVar v1.0 - Initial Release.
Known Bugs:
- None, if you do find a bug please make sure you report it to me so I can fix it!
Functions:
pawn Code:
SetGVarString(varname[], value[], id = 0);
SetGVarInt(varname[], value, id = 0);
SetGVarFloat(varname[], Float:value, accuracy = 6, id = 0);
SetGVarBool(varname[], bool:value, id = 0);
SetGVarHex(varname[], value, id = 0);
SetGVarBin(varname[], value, id = 0);
GetGVarString(varname[], id = 0);
GetGVarStringEx(varname[], dest[], size = sizeof dest, bool:pack = false, id = 0);
GetGVarInt(varname[], id = 0);
Float:GetGVarFloat(varname[], id = 0);
bool:GetGVarBool(varname[], id = 0);
GetGVarBin(varname[], id = 0);
GetGVarHex(varname[], id = 0);
DeleteGVar(varname[], id = 0);
Like any other include, put it in your includes folder and add it to your script:
pawn Code:
#include <gvar>
pawn Code:
#include <a_samp>
#include <gvar>
Worried about speed?
I have done some benchmarks using Slice's code: https://sampforum.blast.hk/showthread.php?tid=218491
Here are the results for each function:
Code:
Bench for SetGVarInt: executes, by average, 801.36 times/ms. Bench for SetGVarFloat:: executes, by average, 717.23 times/ms. Bench for SetGVarString: executes, by average, 906.33 times/ms. Bench for SetGVarBool: executes, by average, 913.14 times/ms. Bench for SetGVarHex: executes, by average, 785.13 times/ms. Bench for SetGVarBin: executes, by average, 741.88 times/ms. Bench for GetGVarInt: executes, by average, 749.38 times/ms. Bench for GetGVarFloat:: executes, by average, 487.21 times/ms. Bench for GetGVarString: executes, by average, 806.46 times/ms. Bench for GetGVarBool: executes, by average, 708.75 times/ms. Bench for GetGVarHex: executes, by average, 517.23 times/ms. Bench for GetGVarBin: executes, by average, 534.33 times/ms. Bench for DeleteGVar: executes, by average, 1139.07 times/ms.
- GVar v1.0 - http://www.solidfiles.com/d/4ae6e76669/
(Please do not make any mirrors or upload to pastebin, thanks)
So that's about it, using it is very simple, just like PVars.
If you have any suggestions about improving the code, let me know!