DiceBot Programmer mode tutorial 01.2 -Functions

in #seuntjie8 years ago (edited)

This serves as an appendix to DiceBot Programmer mode tutorial 01 - Overview


Note for beginners: Functions are predetermined sets of instructions to perform a specific task following a predetermined method or calculate a value using a predetermined method.

To call a function, one uses the function name, and in brackets, the parameters, if any are needed.
For example: functionname(param1, param2, param3)

A parameter can be a variable or a hardcoded value.


The bot provides the LUA environment with a set of functions that can directly affect variables or functions inside of the bot. These functions are there to aid the user with this/her scripts. The user can define his or own functions and use them throughout the programmer mode as needed as well.


List of functions available:

  • withdraw(amount,bitcoinaddress) Returns: void. Parameters: 1: Amount to withdraw, double. 2: Address to withdraw to, string. Withdraws the specified amount to the specified address if the site supports it.
  • invest(amount) Returns: void. Parameters: 1: Amount to withdraw, double. Invests the specified amount if supported by the site.
  • tip(username,amount) Returns: void Parameters: 1: Username or ID to tip to. 2: Amount to tip to specified user. Tips the specified amount to the specified user if the site supports it. Username can be either the name or ID depending on site being used.
  • stop() Returns: Void. Stop betting. Can be used from console or inside a script.
  • start() Returns: Void. Start betting. Can only be used from the console
  • resetseed() Returns: Void. Resets your client-server seed pair at the site if supported.
  • print(message) Returns: Void. Parameters: 1: Message, string. Prints the Message parameter to the output console. Usefull for debugging or roll finding competitions etc
  • getHistory() Returns: Bet{}. Returns all bets made by the bot for the site as stored in sqlite. Not recommended running this after every bet as the IO will become extremely intensive.
  • getHistroyBydDte(fromdate) Returns:BET[]. Parameters: 1: Starting date to search from, inclusive, string. Get all bets for the current site as stored in SQLIte made on or after the specified date.
  • getHistoryByQuery(sqlitequery) Returns: BET[]. Parameters: 1: SQLITE query to be executed to select bets from sqlite, string. Get all bets that match the sqlite query. No sanitation of sql query is done, thus updates/deletes/drops can be performed using this function.
  • martingale(win) Returns: double. Parameters: 1: Win, bool. Indicates whether to process the bet as a win or a loss. Executes the built in martingale system as set up in the advanced mode. Returns what the next bet would be using said system
  • labouchere(win) Returns: double. Parameters: 1: Win, bool. Indicates whether to process the bet as a win or a loss. Executes the built in labouchere system as set up in the advanced mode. Returns what the next bet would be using said system
  • fibonacci(win) Returns: double. Parameters: 1: Win, bool. Indicates whether to process the bet as a win or a loss. Executes the built in fibonacci system as set up in the advanced mode. Returns what the next bet would be using said system
  • dalembert(win) Returns: double. Parameters: 1: Win, bool. Indicates whether to process the bet as a win or a loss. Executes the built in dalembert system as set up in the advanced mode. Returns what the next bet would be using said system
  • presetlist(win) Returns: double. Parameters: 1: Win, bool. Indicates whether to process the bet as a win or a loss. Executes the built in preset list system as set up in the advanced mode. Returns what the next bet would be using said system
  • resetstats() Returns: Void. Resets the session stats for the bot. Takes effect in programmer mode after next bet.
  • servalueint(name,value) Returns: Void. Parameters: 1: The name of the setting to change the value for, string. 2: The new integer value for the setting, int. Set the value for a setting in the advanced mode to be used when executing one of the built in systems. Intended for use with integer values, such as number of bets, losses or wins.
  • setvaluedouble(name,value) Returns: Void.Parameters: 1: The name of the setting to change the value for. string. 2: The new double value for the setting, double. Set the value for a setting in the advanced mode to be used when executing one of the built in systems. Intended for use with double values, such as profit, balance.
  • setvaluestring(name,value) Returns: Void.Parameters: 1: The name of the setting to change the value for, string. 2: The new string value for the setting, string.. set the value for a setting in the advanced mode to be used when executing one of the built in systems. Intended for use with string values, such as lists of bets, bitcoin address.
  • setvaluebool(name,value) Returns: Void. Parameters: 1: The name of the setting to change the value for,string. 2: The new bool value for the setting. set the value for a setting in the advanced mode to be used when executing one of the built in systems. Intended for use with bool values, such as enabling or disabling a setting.
  • getvalue(name) Returns: object. Parameters: 1: Name of the setting, string. Get the value from the advanced mode for the specified setting.
  • loadstrategy(filepath) Returns: Void. Parameters: 1: full or relative path to the settings file, string. Loads the specified file into the advanced mode if the file is a settings file.
  • read(prompt,type) Returns: object. Parameters: 1: Prompt to show user, string. Type of object to return, int. Shows the user a prompt and awaits input before continuing with the script. The entered value is returned and can be used in calculations in the script. Input types:0: bool, 1:int, 2:double, 3:string



Functions can be defined in the programmer mode for internal use. A function definition needs to start with the function keyword, followed by the function name, then the parameters in brackets. A function must always be closed with an end keyword. Forexample

function FuncName(param1, parameter3)
--do your function logic here
end

The function can then be called later in the program using FuncName(0, 'hello there')


Functions need to be declared globally or as part of a class and cannot be nested inside another function. An example of functions will be covered in a later tutorial.

Sort:  

I don't personally use the Programming mode, but thanks for explaining it for other users and sharing your content here!

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.030
BTC 63595.77
ETH 3415.98
USDT 1.00
SBD 2.49