Hpl2:Resources:script modules:smallvars
This article needs to be cleaned up to conform to a higher standard of quality because: This is very obscure, it's hard to tell what this is for and how to use it. The formatting needs work, too
|
These functions are intended to provide variable & debug message support through the HPL2 API in a compact form and with increased flexibility at the expense of clarity in their naming conventions. It is suggested that you do not use these functions unless you are dealing with a lot of variables via the API. Since the function names are small and exposed to the entire script, make sure you do not create any functions that have the same name as any of the smallvars.
Below is an uncommented and compressed version of the functions. You can copy & paste it into the source over into your script file. Documentation is at the end of the page.
int lvi(string &in name, int val) { SetLocalVarInt(name, val); return GetLocalVarInt(name); } int lvi(string &in name) { return GetLocalVarInt(name); } int alvi(string &in name, int aval) { AddLocalVarInt(name, aval); return GetLocalVarInt(name); } int ddlvi(string &in name) { AddLocalVarInt(name, -1); return GetLocalVarInt(name); } int lvidd(string &in name) { AddLocalVarInt(name, -1); return (GetLocalVarInt(name) + 1); } int pplvi(string &in name) { AddLocalVarInt(name, 1); return GetLocalVarInt(name); } int lvipp(string &in name) { AddLocalVarInt(name, 1); return (GetLocalVarInt(name)-1); } int lvia(string &in name, int aval) { AddLocalVarInt(name, aval); return (GetLocalVarInt(name)-aval); }
int gvi(string &in name, int val) { SetGlobalVarInt(name, val); return GetGlobalVarInt(name); } int gvi(string &in name) { return GetGlobalVarInt(name); } int ddgvi(string &in name) { AddGlobalVarInt(name, -1); return GetGlobalVarInt(name); } int gvidd(string &in name) { AddGlobalVarInt(name, -1); return (GetGlobalVarInt(name) + 1); } int ppgvi(string &in name) { AddGlobalVarInt(name, 1); return GetGlobalVarInt(name); } int gvipp(string &in name) { AddGlobalVarInt(name, 1); return (GetGlobalVarInt(name)-1); } int agvi(string &in name, int aval) { AddGlobalVarInt(name, aval); return GetGlobalVarInt(name); } int gvia(string &in name, int aval) { AddGlobalVarInt(name, aval); return (GetGlobalVarInt(name)-aval); }
float lvf(string &in name, float val) { SetLocalVarFloat(name, val); return GetLocalVarFloat(name); } float lvf(string &in name) { return GetLocalVarFloat(name); } float alvf(string &in name, float aval) { AddLocalVarFloat(name, aval); return GetLocalVarFloat(name); } float lvfa(string &in name, float aval) { AddLocalVarFloat(name, aval); return (GetLocalVarFloat(name)-aval); }
float gvf(string &in name, float val) { SetGlobalVarFloat(name, val); return GetGlobalVarFloat(name); } float gvf(string &in name) { return GetGlobalVarFloat(name); } float agvf(string &in name, float aval) { AddGlobalVarFloat(name, aval); return GetGlobalVarFloat(name); } float gvfa(string &in name, float aval) { AddGlobalVarFloat(name, aval); return (GetGlobalVarFloat(name) - aval); }
string lvs(string &in name, string &in val) { SetLocalVarString(name, val); return GetLocalVarString(name); } string lvs(string &in name) { return GetLocalVarString(name); } string alvs(string &in name, string &in val) { AddLocalVarString(name, val); return GetLocalVarString(name); } string lvsa(string &in name, string &in val) { string retstr = GetLocalVarString(name); AddLocalVarString(name, val); return retstr; }
string gvs(string &in name, string &in val) { SetGlobalVarString(name, val); return GetGlobalVarString(name); } string gvs(string &in name) { return GetGlobalVarString(name); } string agvs(string &in name, string &in aval) { AddGlobalVarString(name, aval); return GetGlobalVarString(name); } string gvsa(string &in name, string &in aval) { string outstr = GetGlobalVarString(name); AddGlobalVarString(name, aval); return outstr; }
void db(float val) { AddDebugMessage(""+val, false); } void db(string &in msg) { AddDebugMessage(""+msg, false); } void db(int val) { AddDebugMessage(""+val, false); } void db(int[] arr) { string outmsg=""; for(int i=1;i<=arr.length()-1;i++) outmsg+=arr[i-1]+", "; outmsg+=arr[arr.length()-1]; AddDebugMessage(outmsg, false); } void db(float[] arr) { string outmsg=""; for(int i=1;i<=arr.length()-1;i++) outmsg+=arr[i-1]+", "; outmsg+=arr[arr.length()-1]; AddDebugMessage(outmsg, false); } void db(string[] arr) { string outmsg=""; for(int i=1;i<=arr.length()-1;i++) outmsg+=arr[i-1]+", "; outmsg+=arr[arr.length()-1]; AddDebugMessage(outmsg, false); } void dbli(string &in varname) { db(lvi(varname)); } void dblf(string &in varname) { db(lvf(varname)); } void dbls(string &in varname) { db(lvs(varname)); } void dbgi(string &in varname) { db(gvi(varname)); } void dbgf(string &in varname) { db(gvf(varname)); } void dbgs(string &in varname) { db(gvs(varname)); }
<– SmallVar Documentation –>
<SCOPES>
l :: local
g :: global
<OTHER>
v :: variable
<TYPES>
f :: float
s :: string
i :: integer
<OPERATIONS>
pp :: increment (++)
dd :: decrement (–)
a :: add
db :: debug
Above is the legend. Use the letters found there to figure out what each smallvar function does. To call a function, pick a scope, l or g – l meaning local, g meaning global, then add on v for variable, and i, f, or s for which data type the function uses.
Below is a list of examples with a short description – the same structure applies to all three types. First argument is the name of the variable, and the second is the value. Some functions do not apply for all types – e.g. you cannot increment a string variable.
- returns value
int lvi(string&);
- sets value, then returns it
int lvi(string&, int);
- pre-fixed increment, returns incremented value
int pplvi(string&);
- post-fixed increment, returns original value, but true value has been incremented
int lvipp(string&);
- pre-fixed addition, returns summed value
int alvi(string&, int);'
- post-fixed addition, returns original value, but true value has been changed
int lvia(string&, int);
- debug message "smallvars" – no support for repetition suppression
'db(int);
db(int[]);
db(string&);
db(float);