DiceBot Programmer mode tutorial 1.1 - Variables

in #dicebot8 years ago (edited)

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

Note for beginners: Variables are ways of storing values in programming so that you can recall the value later and/or perform calculations on it or with it. It usually has a name and a type.
 
Quick summary of types: int: Integer, whole numbers, for example -2,-1,0,1,2,9999 etc.
double/float/decimal: numbers with decimal places. the different types have different properties (number of decimal places etc) that you probably don't need to worry about in the programmer mode.
bool/boolean: true/false values. can only be the one or the other
string: text values. Needs to be in parenthesis or apostrophes when setting the value, depending on the language.
 
These aren't all types available, only the ones you'll likely use in DiceBots programmer mode.
 
A variable needs to be declared and a value set to it before it can be used for other functions.
to declare a variable in LUA, you need to name it and give it an initial value
 
testvar = 10.1
 
This variables name is testvar, it is of type double and has a value of 10.1

There are a list of variables already available for users to use in their scripts in the bot and they can be found in the variables box in code tab of the programmer mode.

Some variables are read only and have RO appended to them in the list. You can assign values to them from the script or console, but it will have no effect on the bet and the variable will be set by the bot again after the next bet.

Variables with RW behind them are not reset by the bot after each bet and can be assigned values that will effect the next bet, for example nextbet, chance or bethigh.

The variables available are:

  • balance, type: double. Permission: Read Only. Lists your balance at the site you're logged in to. Only available after first bet.
  • win, Type: bool. Permission: Read Only. Indicates whether the last bet you made was a winning bet (true) or a losing bet (false)
  • profit, type: double. Permission: Read Only. Shows your session profit. Session is defined as the time since opening the current instance of bot or the last time you reset your stats in the bot.
  • currentprofit, type: double. Permission: Read Only. Shows the profit for the last bet made. This is not the amount returned. betting 1 unit at x2 payout, when winning, profit will show 1 (returned =2), when losing, profit will show -1
  • currentstreak, type double. Permission: Read Only. Shows the current winning or losing streak. When positive (>0), it's a winning streak. When negative (<0) it's a losing streak. Can never be 0. Only set after first bet.
  • previousbet, type: double, Permission: Read Only. Shows the amount of the previous bet. Only set after first bet.
  • bets, type: int, Permission: Read Only. Shows the number of bets for the current session
  • wins, type: int, Permission: Read Only. Shows the number of wins for the current session
  • losses, type: int, Permission: Read Only. Shows the number of losses for the current session
  • nextbet, type: double, Permission: Read Write. The amount to bet in the next bet. you need to assign a value to this variable to change the amount bet. Defaults to previousbet after first bet. Needs to be set before betting can start.
  • chance, type: double, Permission: Read Write. The chance to win when betting. Defaults to value set in advanced settings if not set. Need to set this value to change the chance to win/payout when betting.
  • bethigh, type: bool, Permission: Read Write. whether to bet high/over (true) or low/under(false). Defaults to true (bet high/bet over)
  • lastBet, type: Bet, Permission Read Only. This is an object containing more details about the previous bet, including the lucky number that was rolled, chance, amount, profit etc. A UML for the bet is available here.
  • currencies, type: string array, Permission Read Only. List the currencies that can be used at the current site, usually in the currency short code (Btc, Ltc etc)
  • currency, type: string, Permission Read Write. can be used to change the currency to bet in using any value from the currencies list. Only values from the currencies list can be used. case sensetive.
  • enablesrc, type: bool, Permission Read Write. Enables the built in stop and reset conditions as defined in the programmer mode when true.
  • enablezz, type: bool, Permission Read Write. Enables the built in zig zag settings as set in advanced mode when set to true.

These are variables that are made available by the bot for use in the programmer mode. A user can set his/her own variables, but scope is important to take into account

scope refers to the area of the code where certain functions or variables are available. If a variable is defined inside of a function, it is only available within that function. If it is declared inside an if, for, while or any similar clause, it is only available in that clause. To make a a variable global, declare it with a default value outside of any function

New variables can easily be declared and used in the bot, as will be demonstrated in a following tutorial.

Coin Marketplace

STEEM 0.19
TRX 0.12
JST 0.027
BTC 60185.13
ETH 3290.40
USDT 1.00
SBD 2.44