View Single Post
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-17-2016 , 12:42   [INC] nVault Array
Reply With Quote #1

nVault Array

This include provides the ability to store arrays in nVault. Out of the box, nVault allows you to only save data as a single string. This is cumbersome when you need to store multiple pieces of data because you first need to convert it to a single sting before saving. On top of that, when retrieving the data you then need to parse each value out of the string and then convert it back to an integer and/or copy it back to a string/float variable. This include file solves this problem by allowing you to save and retrieve data directly to and from an array. Data of various types (int, bool, string, float) can all be stored in a single array by using an enum sized array (see example plugin).

Note: This include file requires that you use a fixed version of the nVault module. During the development of these new functions, a bug was discovered in the nVault module that will result in invalid values and possibly errors. This fixed module is attached below and is also available in AMX-X dev builds >= 4589. Thanks to Arkshine for fixing this so quickly for me.

Functions
  • nvault_set_array() - Save an array to vault.
  • nvault_get_array() - Read an array from vault.
  • nvault_arraysize() - Returns size of array stored.
  • nvault_isarray() - Returns true/false for if data is an array.
Note: This include file uses the nVault handle returned from nvault_open(). It does NOT use the nvault_util_open() file handle used by nVault Utility. This include file has no dependency on nVault Utility. nVault Utility does, however, provide the ability to read all array entries. For nvault_util_read_array()/nvault_util_readall_array(), you would use the nvault_util_open() file handle as with all functions in nVault Utility.

Descriptions
  • nvault_set_array( vault , key , array[] , size )
    This function saves an array to vault. The largest array that can be saved is 500 cells; you can increase this by increasing the constant _NVAULT_ARRAY_MAXARRAYSIZE in the include file. Multidimensional arrays are not directly supported, but if you use an enum to size your array, it can be accomplished. Arrays are stored in a binary format with encoding to prevent null bytes from being included in the output string .. which means you cannot edit/view arrays saved in nVault with an nVault viewer application.
    Code:
    vault - Vault handle.
    key - Key for entry.
    array[] - Array to store in vault.
    size - Size of array.
  • nvault_get_array( vault , key , array[] , size )
    This function reads an array from vault. This will only read arrays that were stored in the vault using nvault_set_array().
    Code:
    vault - Vault handle.
    key - Key for entry.
    array[] - Array to read data in to.
    size - Size of array.
  • nvault_arraysize( vault , key )
    This function returns the size of the array data stored in nvault. It will return 0 if the record does not exist or if the data in the nVault record is not an array. It will otherwise return the size of the array in cells.
    Code:
    vault - Vault handle.
    key - Key for entry.
  • nvault_isarray( vault , key )
    This function determines whether or not the data is an array.
    Code:
    vault - Vault handle.
    key - Key for entry.
nVault Array Example
Spoiler
Attached Files
File Type: zip nvault_amxx_fixed.zip (148.2 KB, 1130 views)
File Type: inc nvault_array.inc (7.6 KB, 1796 views)
__________________

Last edited by Bugsy; 12-22-2018 at 10:37.
Bugsy is offline