29 December 2022 - PtokaX (20th anniversary edition) released...
11 April 2017 - PtokaX released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX for Windows 10 IoT released...
3 September 2015 - PtokaX released...
16 August 2015 - PtokaX released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX released...
13 April 2014 - PtokaX released...
23 March 2014 - PtokaX testing version build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu


Started by CrazyGuy, 26 November, 2006, 18:19:17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


a lua file which holds a set of hubsoft independent lua functions.
I called it ExtendedApi.lua

copy it into your scripts folder and start your script with:

And all functions are available
Note that there's 2 tables reserved by it, namely tTimers and tExtUserInfo so don't declare variables with that name yourself  ;)

The file's attached, here's the API

This is the Interface for ExtendedApi.lua by CrazyGuy
Current version = 1.0

Global functions:

LuaCompat()            -- Call this function to make non LUA 5.1.x functions compatible ( as much as possible )
Serialize(tTable, sTable, sTab)         -- Returns a string in Table format for storage to file
GetExtApiVer()            -- Returns this script's version number as string

Loading and Saving related functions:

LoadStringFile(fFile)            -- Loads a textfile
SaveStringFile(sString, fFile, sMode)      -- Saves a textfile. (sMode can be the LUA modes for append, overwrite, update etc)
LoadTableFile(tTable,fFile)         -- Loads a table from a file
SaveTableFile(tTable, sTable, fFile)      -- Serializes and saves a table to a file

Multi Timers related functions:           Timers are stored in a table called tTimers

AddTimer(iInterval, sTimerName)      -- Adds a timer and returns its ID or nil on error
RemoveTimer(iTimerID)         -- Removes a timer and returns 1 on success or nil on error
GetTimerByName(sTimerName)      -- Returns a timers ID or nil on error
GetTimerByID(iTimerID)         -- Returns a timers Name or nil on error
GetTimerIntByID(iTimerID)         -- Returns a timers Interval or nil on error
GetTimerValueByID(iTimerID)         -- Returns a timers current Value or nil on error
GetTimerStateByID(iTimerID)         -- Returns a timers current State (1/0) or nil on error
StartTimerByID(iTimerID)         -- Starts a timer by ID, returns 1 on success, 0 on is already started or nil on error
StopTimerByID(iTimerID)         -- Stops a timer by ID, returns 1 on success, 0 on is already stopped or nil on error
SetTimerIntByID(iTimerID, iInterval)      -- Changes a timers Interval, returns 1 on success, nil on error
SetTimerName(iTimerID, sTimerName)      -- Changes a timers Name, returns 1 on success, nil on error
ResetTimer(iTimerID)         -- Resets a timers Value back to 0, returns 1on success, nil on error

Storing additional Userinfo functions:       Userinfo is stored in a table called tExtUserInfo

AddExtUserInfo(sName,bBool,iInt,sString)   -- Stores a set of 3 variables for the specefied user
RemoveExtUserInfo(sName)         -- Removes a user from the table
GetExtUserBool(sName)         -- Returns a boolean stored for sName or nil on error
GetExtUserInt(sName)         -- Returns an integer value stored for sName or nil on error
GetExtUserText(sName)         -- Returns a string value stored for sName or nil on error
SetExtUserBool(sName, bBool)      -- Sets the boolean value for sName to bBool, returns 1 on success, 0 on already set, nil on error
SetExtUserInt(sName, iInt)         -- Sets the integer value for sName to iInt, returns 1 on success, 0 on already set, nil on error
SetExtUserText(sName, sText)      -- Sets the string value for sName to sText, returns 1 on success, nil on error

Lemmy know if something's not working correctly or any suggestions about what to add :)


Looks good mate, and even if its not used directly for scripts, it can be implemented or used to quickly debugg a script.
Ignorance is Bliss.


Thnx m8  ;D

When can we expect you back in the hub  ???


As soon as i remember my pass  ;D, i forgot it.
Ignorance is Bliss.


Everything could have been anything else and it would have just as much meaning.


Thnx guys  :)

There are many examples of the following in this script

if variable ~= nil then

better as...

if variable then

No effectual difference, just a little cleaner code

Hmm I think I did have problems with the slight difference between "if x ~= nil then"  and "if x then"
However, that was a different script, a different LUA version and a less experienced me  :P
So let's give that another try then  8)

Updated to version 1.1 on November 27th 2006
-Added table.maxn and collectgarbage to LuaCompat (Thnx Mutor)
-Cleaned up a few "~= nil" as suggested by Mutor


It depends on what pattern matching you use, something you have to check :
if user=="" then..
Ignorance is Bliss.


As im not using empty string checks, but pure nil checks, it should work out fine here then

SMF spam blocked by CleanTalk