Difference between revisions of "DataPacks"
m (Updated to 1.7 Syntax) |
(Updated to 1.7 Syntax) |
||
Line 27: | Line 27: | ||
==WritePackCell== | ==WritePackCell== | ||
Syntax: | Syntax: | ||
− | <pawn>native WritePackCell(Handle | + | <pawn>native void WritePackCell(Handle pack, int cell); |
</pawn> | </pawn> | ||
Line 34: | Line 34: | ||
Syntax: | Syntax: | ||
− | <pawn>native WritePackFloat(Handle | + | <pawn>native void WritePackFloat(Handle pack, float val); |
</pawn> | </pawn> | ||
Line 41: | Line 41: | ||
Syntax: | Syntax: | ||
− | <pawn>native WritePackString(Handle | + | <pawn>native void WritePackString(Handle pack, const char[] str); |
</pawn> | </pawn> | ||
==ReadPackCell== | ==ReadPackCell== | ||
Syntax: | Syntax: | ||
− | <pawn>native ReadPackCell(Handle | + | <pawn>native any ReadPackCell(Handle pack); |
</pawn> | </pawn> | ||
Line 53: | Line 53: | ||
Syntax: | Syntax: | ||
− | <pawn>native | + | <pawn>native float ReadPackFloat(Handle pack); |
</pawn> | </pawn> | ||
Line 60: | Line 60: | ||
Syntax: | Syntax: | ||
− | <pawn>native ReadPackString(Handle | + | <pawn>native void ReadPackString(Handle pack, char[] buffer, maxlen); |
</pawn> | </pawn> | ||
Line 67: | Line 67: | ||
Syntax: | Syntax: | ||
− | <pawn>native ResetPack(Handle | + | <pawn>native void ResetPack(Handle pack, bool clear=false); |
</pawn> | </pawn> | ||
Line 74: | Line 74: | ||
Syntax: | Syntax: | ||
− | <pawn>native GetPackPosition(Handle | + | <pawn>native int GetPackPosition(Handle pack); |
</pawn> | </pawn> | ||
Line 81: | Line 81: | ||
Syntax: | Syntax: | ||
− | <pawn>native SetPackPosition(Handle | + | <pawn>native void SetPackPosition(Handle pack, int position); |
</pawn> | </pawn> | ||
Revision as of 20:22, 13 August 2015
DataPacks are a way to store and move around various types of data in SourceMod Scripting. Since some things are not possible in SourcePawn, such as a function consuming a String, DataPacks help us get these Strings and other items where they need to go.
Contents
Example of using a DataPack
Syntax:
//writing DataPack pack = CreateDataPack(); pack.WriteCell(23); pack.WriteString("I'm a little teapot."); //reading pack.Reset(); //resets the index to the beginning, necessary for read. int cellValue = pack.ReadCell(); char buffer[1024]; pack.ReadString(buffer, 1024);
Creating a DataPack
Creating a DataPack is very simple; all you need is a Handle to write to.
Datapack dataPackHandle = CreateDataPack();
For more information on using Handles, see Handle API (SourceMod).
DataPack Functions
On you have created your DataPack, you can use a variety of functions to manage the DataPack.
WritePackCell
Syntax:
native void WritePackCell(Handle pack, int cell);
WritePackFloat
This function can be used to write a Float to a DataPack.
Syntax:
native void WritePackFloat(Handle pack, float val);
WritePackString
This function can be used to write a String to a DataPack.
Syntax:
native void WritePackString(Handle pack, const char[] str);
ReadPackCell
Syntax:
native any ReadPackCell(Handle pack);
ReadPackFloat
This function can be used to read a Float from a DataPack.
Syntax:
native float ReadPackFloat(Handle pack);
ReadPackString
This function can be used to read a String from a DataPack.
Syntax:
native void ReadPackString(Handle pack, char[] buffer, maxlen);
ResetPack
This function resets your position in the DataPack.
Syntax:
native void ResetPack(Handle pack, bool clear=false);
GetPackPosition
This function gets your current position in the DataPack.
Syntax:
native int GetPackPosition(Handle pack);
SetPackPosition
This function sets your current position in the DataPack.
Syntax:
native void SetPackPosition(Handle pack, int position);
Disposing of a DataPack
To dispose of a DataPack, all you have to do is close its Handle.
Example:
CloseHandle(dataPackHandle);