DiceBot Programmer mode tutorial 02 - Process

in #dicebot8 years ago (edited)

When writing a script for DiceBots programmer mode, it's important to understand the process that DiceBot follows when running the programmer mode. Understanding the process allows you to define and use variables and functions more efficiently and will lead to less surprises  when eventually running the bot.


The flow chart below displays the basic flow of the programmer mode:



  • Awaiting Input: This is before any script is started or any bets are placed. Predefined variables like previousbet, balance, chance, etc. are not set. Console input is processed in this step and the bot goes back to awaiting input if the console input does not start betting.


  • If the console input starts the bot, it's progressed to the next bet.


  • Set LUA variables: Set the values of the predefined variables to the LUA environment for use in scripts.


  • Parse and execute code in code box: The code in the code box is executed in the LUA environment, thus defining and setting all global variables and functions in the code box. Any global variable defined and given a variable in the code box will be overwritten and reset. Any changes to the dobet function or other functions will be processed in this step. Changes made to the script while the bot is running will have no effect on the function being executed if the bot is not stopped and restarted.


  • Get variables from LUA environment: If the nextbet, chance, bethigh or other variables are already set, they will be loaded into the bot. The nextbet variable is required before a script can be started, but can be set in the global variables in a script in the code box.


  • Place Starting bet: Place a bet using bethigh, chance and nextbet variables, if set.


  • Get bet result: The bot receives the bet result from the site and processes it, updating internal variables, storing to DB, updating charts and visible stats.


  • Update LUA variables: The LUA variables are updated after the bet. New profit, balance, previousbet, etc/ are updated. lastBet is set using the data received from the site. 


  • Execute dobet: the LUA dobet function is executed. the nextbet variable determines the size of the next bet, with chance determining the chance to win and bethigh determining whether the bet were to be high or low. Any predefined function called at this stage is executed in series, meaning they're executed and only continue with the script once finished. For functions like resetseed, this could cause delays and "hangs" in the bot.


  • If the script executed the stop function for whatever reason, the bot will stop once the dobet function is finished processing. No bet will be placed until the bot is started again.


  • Get LUA variables: Gets the new values for chance, nextbet, bethigh and other RW variables from the LUA environment and sets internal variables accordingly.


  • Place Bet: The bet is placed according to the values received from the previous step.


This process defines when variables are set, updated and reset. Understanding this process will allow you to define and set variables that are in the appropriate scope and reset/updated at the appropriate times.

Sort:  

That flow chart is a great way of breaking down lots of techno-garble into stuff idiots like me can understand! ;D Thanks for sharing, Seuntjie! Shoutout to anyone else here, you guys should follow him, he does some great work!

Coin Marketplace

STEEM 0.20
TRX 0.26
JST 0.039
BTC 100331.97
ETH 3646.26
USDT 1.00
SBD 3.05