CrystalBall Lite has powerful scripting abilities. Scripting allows absolute custom control of the workings of CrystalBall Lite including the functionality and flow of dice rolls and for custom user input. Use the menu on the left, or scroll down to see more detailed examples of scripting features.
Dice Button Functions:
- These functions effect the buttons on the main dice rolling window. Buttons can be moved, swapped, and cleared. Their values, name, type and more can be set. This allows the dice rolling window to be fully interactive.
- ButtonClear Clears a button
- ButtonReplace Replaces a button with another button
- ButtonSwap Swaps two buttons
- CounterButtonPushDownArrow Performs the down arrow roll on a counter button as if the down arrow had been clicked
- CounterButtonPushUpArrow Performs the up arrow roll on a counter button as if the up arrow had been clicked
- CounterButtonReset Resets a counter
- GetButtonIndex Gets the index of a button from its name
- GetButtonName Gets the name of a button from its index
- GetButtonRoll Gets the actual roll that would be made if a button was clicked on as a string
- GetCounterValue Returns the current value in the counter.
- RefreshButton Causes a single button to repaint himself. Do not use this inside of a button's Paint event.
- RefreshAllButtons Causes all the buttons to repaint themselves. Do not use this inside of a button's Paint event.
- SetButtonColor Sets the background color of a button
- SetButtonDownArrow Sets the down arrow's roll of the given button
- SetButtonName Sets the name of a button from its index
- SetButtonRoll Sets the roll the button rolls
- SetButtonStyle Sets the style of a button
- SetButtonUpArrow Sets the up arrow's roll of the given button
- SetCounterResetRoll Sets the reset roll for a counter button.
- SetCounterValue Sets the current value of a counter
Button Drawing Functions:
- These functions provide ways to draw on buttons. Using a button's events a script can respond to actions and draw the button however you want.
- GraphicsBold Sets the bold flag for drawing strings
- GraphicsDrawButtonCaption Draws a buttons caption on the button.
- GraphicsDrawLine Draws a line
- GraphicsDrawOval Draws an oval
- GraphicsDrawPicture Draws a picture from a file
- GraphicsDrawPolygon Draws a polygon
- GraphicsDrawRect Draws a rectangle
- GraphicsDrawRoundRect Draws a rectangle with rounded corners
- GraphicsDrawString Draws a string using the current font, italic, bold, and underline settings
- GraphicsFillOval Draw a filled oval
- GraphicsFillPolygon Draw a filled polygon
- GraphicsFillRect Draw a filled rectangle
- GraphicsFillRoundRect Draw a filled rectangle with rounded corners
- GraphicsForeColor Set the drawing color for the drawing functions
- GraphicsHeight Returns the height of the button's drawing area
- GraphicsItalic Sets the italic status for drawing a string
- GraphicsPenHeight Sets the pen height for drawing
- GraphicsPenWidth Sets the pen width for drawing
- GraphicsSetPixel Sets the color of a single pixel
- GraphicsStringHeight Returns the height of a string
- GraphicsStringWidth Using the current font this returns the width of a string
- GraphicsTextFont Sets the current font for drawing strings
- GraphicsTextSize Sets the font size for drawing strings
- GraphicsUnderline Sets the underline flag for drawing strings
- GraphicsWidth Returns the width of the button's drawing area
CBLite Library:
- These functions and classes are for utility use. They can be used to store and manipulate data.
- ArrayClass Stores values in a linear array with indexes of 0 through n where n is the number of items - 1.
- ArrayIterator This is used to step through an ArrayClass of items.
- Dictionary Stores values in a key to value pair dictionary.
- DictionaryIterator Steps through the elements of a Dictionary.
- GetTable Gets a table from the CrystalballData folder and loads it in to a TableClass.
- StrsDiffersAt Given two strings, this returns the first character at which they differ.
- SubTableClass Represents a sub table of a multitable. This contains the rows and columns of the table.
- TableClass Stores the subtables of a multitable. This class allows reading a table from a file and writing back to that file.
Dice Rolling Functions:
- These functions allow control for rolling dice. This includes making a roll from a script, setting the value to use for a script in a dice roll, and other dice related functionality. This allows rolls to be customized for any situation conceivable.
- GetVariableString Returns the value of a variable as a string
- GetVariableValue Returns the value of a variable
- LookupFromTable_Double Returns the numeric value of a cell in a table
- LookupFromTable_String Returns the string value of a cell in a table
- ReturnValue Sets the value returned from a script if called from a dice roll
- RollDice Rolls a dice string returning the numeric result
- SetCurrentDiceSet Sets the current diceset
- SetVariableValue Sets a variable's value
- SetVariableString Sets a variable's roll string
Global Variables:
- Global variables are used for passing data between scripts. Global variables stick around until CBLite is closed allowing any called script to use values from other scripts as well as to access CBLite supplied variables like knowing the current dice set's name and knowing which button was most recently used.
- GetGlobalVariableString Returns the value of a Global Variable
- SetGlobalVariableString Sets the value of a Global Variable
Miscellaneous Functions:
- These functions provide prompting, sounds, calling a script from another script and other powerful functionality.
- CallScript Runs another script
- EndOfLine Returns the line seperator string
- Quote Returns a quote as a string
- CreateDiceSet Creates a dice set given a name. This allows scripts to create character dice sets and other functionality.
- GetMicroSeconds Gets the current microseconds since the computer started. Useful for timers, andimations, and other time dependent features.
- GetScriptParameter Gets a variable that is passed to the script by name.
- MessageBox Shows a messagebox with a given message
- OutputText Outputs text to the dice roller window's roll box without sending it over the network
- PlaySoundFile Plays a sound file
- SetTableValue Sets a value in to a table creating the table and columns as needed. This can be used for storing data in a file for later use through the LookupFromTable_String function
- StartTimer Starts a timer to run a script at a specified delay
- StopTimer Stops a timer so that it no longer fires
- User Input Prompting Provides user dialogs for getting many forms of infomration from the user. See the Script Prompter FAQ for more information
Network Functions:
- These functions provide abilities to send messages over the network to other participants.
- SendText_ToAll Sends text to specific chat participants
- SendText_ToSpecific Sends text to all chat participants
Button Events:
- Dice buttons have events that can have scripts. The scripts for these events allow further customization of the interface for giving specific control to how buttons work. The event scripts are editable in the dice set table in the Buttons subtable. The scripts are columns where you can double click the script for the button to edit the script for that button's events.
- Closed This event occurs when CBLite closes. All buttons currently showing will run its close event script. This event also occurs when switching dice sets. The current dice set's buttons will fire their close events before switching to the new diceset.
- Mouse Enter This event occurs when the mouse enters a button. It only occurs once until the mouse moves off the button. This is a great way to have buttons become active when the mouse is over them.
- Mouse Exit This event occurs when the mouse exits a button. It only occurs once until the mouse moves back on the button. This is a great way to have a button become inactive when the mouse goes off it.
- Mouse Over This event occurs whenever the mouse passes over the button. The script will run every time the mouse moves while over the button. The current X and Y position of the mouse is stored in a GlobalVariable. To get the X and Y positions use the following calls:
- mouseX = GetGlobalVariableString("CurrentButtonMouseX")
- mouseY = GetGlobalVariableString("CurrentButtonMouseY")
- Opened This event occurs when CBLite opens. All buttons currently showing will run its open event script. This event also occurs when switching dice sets. The new dice set's buttons will fire their open events after switching to the new diceset.
- Paint This event occurs whenever the button is drawn. Use the Button Drawing Functions to change how the button is displayed. To get the width and height of the current button being drawn, use the following calls:
- buttonHeight = GraphicsHeight()
- buttonWidth = GraphicsWidth()
- Post-Roll This event occurs when a button is clicked and after its roll is rolled.
- Pre-Roll This event occurs when a button is clicked but before its roll is rolled.
RBScript
Variables and Constants
All numeric and alphanumeric operators are supported:
+, -, *, /, \, Mod, <, =, >, <=, >=, <>.
Logical operators: And, Not, Or.
All forms of comments are supported: ', //, and REM.
Data Types
RBScript supports the following data types:
Integer
Single
Double
Boolean
String
Color
Object
Variant
Arrays can use any of these types.
Control Structures
Supported control structures include:
Function...
Sub...
For... Next
Do... Loop
If... Then... End If
Select Case... End Select
While...Wend
Return statement
Classes
You can create a class using the Class...End Class structure. A new class can have properties, methods, and events.
Class NewClass Dim i as Integer //Property definitions.. Dim c as Color Sub myMethod (x as Integer, y as Integer) //Method definition goes here End Sub //Class definition End Class
A class can be subclassed from another class using the "Inherits" declaration.
Modules
You can create modules using the Module structure. For example:
Module Foo Dim bar As Integer Sub Baz () bar = 42 End Sub End Module
Modules are similar to REALbasic modules. The differences are that properties are always protected and constants are not allowed. You can get the effect of a public property or constant by simply putting the Dim or Const statement outside of the module.
TypeCasting
Typecasting is supported. Use the desired type's name as a function whose only argument is the object reference you want to cast. If it fails, it will trigger an IllegalCastExceptionerror.
"Super" keyword
The new "Super" keyword lets you call overridden methods without having to specify which class the method came from. This works for constructors as well. You can call overridden superclass methods using REALbasic's classname.methodname() syntax.
Inheritance
Class inheritance is implemented with the "Inherits" declaration.
Class MyNewSubClass Inherits NewClass //continue coding here.... End Class
Events
Classes can declare new events using a New Event declaration.
Class myClass New Event myEvent (myParameter as DataType) as DataType End Class
Methods can handle such events using the Handles Event declaration. For example:
Class myClass New Event myEvent (myParameter as DataType) as DataType End Class Class mySubClass Inherits myClass Function myEvent (myParameter as DataType) Handles Event //continue with function here End Function End Class
Interfaces
RBScript now supports interfaces, declared by the Interface...End Interface structure. Interface methods are declared with a Sub or Function line just as they would be declared inside a class, but they have no contents and need no End Sub or End Function line:
Interface MovableItem Sub Move( x As Integer, y As Integer) Function LocationX() As Integer Function LocationY() As Integer End Interface
Function declarations with no parameters must have empty parentheses, as shown above.
A class may declare that it implements an interface with the Implements keyword:
Class Box Implements MovableItem End Class
Classes can implement any number of interfaces, but they must provide all of the methods listed in the interface. Interfaces can be used in all the situations as in REALbasic.
Input and Output
- Input(Prompt as String) Retrieves input from the user. This function triggers the Input event.
- Print(String) Sends output to the implied output device. This function triggers the Print event.
Functions
Standard library functions are supported as follows. These functions work as specified in this Language Reference unless comments indicate otherwise. String functions can be called using the syntax of methods, just as in REALbasic.
- Abs(Double) As Double - Returns the absolute value of the number specified.
- Acos(Double) As Double - Returns the arccosine of the value specified. The arccosine is the angle whose cosine is value. The returned angle is given in radians.
- Asc(String) As Integer - Returns as an Integer, the ASCII value for the first character of a String.
- AscB(String) As Integer - Returns as an Integer, the value for the first byte of a String.
- Asin(Double) As Double - Returns the arcsine of the value specified
- Atan(Double) As Double - Returns the arctangent of the value specified. The arctangent is the angle whose tangent is value.
- Atan2(Double, Double) As Double - Returns the arctangent of the point whose coordinates are x and y. The arctangent is the angle from the x-axis to a line drawn through the origin (0,0) and a point with coordinates x, y.
- ByRef keyword - Used to pass a parameter by reference.
- ByVal keyword - Used to pass a parameter by value.
- CDbl(String) As Double - Returns the numeric equivalent of the passed String. This function is the same as the Val function but is international-savvy. Use Val if you control the String that is passed, and use CDbl if the String comes from the user. See the Val function for more information.
- Ceil(Double) As Double - Returns the value specified rounded up to the nearest Integer.
- Chr(Double) As String - Returns the character whose ASCII value is passed.
- ChrB(Double) As String - Returns a single byte String whose value is passed.
- CMY - Returns a Color based on the CMY (cyan, magenta, yellow) color model.
- Color - A Color is an intrinsic data type that consists of three bytes that define the color. A color can be set using the RGB, HSV, or CMY models or the &c literal. Each set of properties is used with the appropriate function to specify a color. The values of any of the nine properties can then be read. The default value of a Color is &c000000 (black).
- Const name = value - Declares a value as a local constant.
- Cos(Double) As Double - Returns the cosine of the given angle.
- CountFields(String, String) As Integer - Returns the number of values (fields) in the string passed that are separated by the separator string passed. If the source string is binary data or you require case-sensitivity, use CountFieldsB instead.
- Parameters:
- Source as String - The source string to search.
- Seperator as String - The character or characters that separate the values in source.
- CStr(Double) As String - Use to convert the passed data type to a String. You can also pass a class instance as long as the class implements the Operator_Convert method that returns a String. See the Str function for more information.
- Dim - Creates a local variable or array with the name and size (in the case of an array) and data type specified. The Static statement provides similar functionality except that the variables retain their values from one invocation of the method to the next.
- Do...Loop - Repeatedly executes a series of statements while a specified condition is True.
- Exit - The Exit statement causes control to exit a loop and jump to another line of code without the loop conditions being satisfied. The optional keywords enable you to control where execution will resume.
- Exp(Double) As Double - Returns "e" to the power of the value specified.
- False - Used to set Boolean variables or properties. False is the result of a comparison of two objects that are not equal.
- Floor(Double) As Double - Returns the value specified rounded down to the nearest Integer.
- For...Next - Executes a series of statements a specified number of times. The For Each...Next statement is a variation that executes once for each element of a one-dimensional array.
- Format(Double,String) As String - Returns as a String a formatted version of the number passed based on the parameters specified. The Format function is similar to the way spreadsheet applications format numbers. Format will use the information based on the user's locale even if the user's locale is a Unicode-only locale.
- Parameters:
- Number as Double - The number to be formatted.
- FormatSpec as String - Defines the formatting to be applied to the number passed.
Character Description
#
Placeholder that displays the digit from the value if it is present.
If fewer placeholder characters are used than in the passed number, then the result is rounded.0
Placeholder that displays the digit from the value if it is present.
If no digit is present, 0 (zero) is displayed in its place..
Placeholder for the position of the decimal point.
,
Placeholder that indicates that the number should be formatted with thousands separators.
%
Displays the number multiplied by 100.
(
Displays an open paren.
)
Displays a closing paren.
+
Displays the plus sign to the left of the number if the number is positive or a minus sign if the number is negative.
-
Displays a minus sign to the left of the number if the number is negative. There is no effect for positive numbers.
E or e
Displays the number in scientific notation.
\character
Displays the character that follows the backslash.
- Function - Declares the name, parameters, returned value, and code that form the body of a function (method).
- Goto keyword - Jumps to a statement label.
- Hex(Integer) As String - Returns as a String the hexadecimal version of the number passed.
- HSV - Returns a Color object based on the HSV (hue, saturation, value) color model.
- If...Then...Else - Conditionally executes a group of statements, depending on the value of a Boolean expression.
- InStr(Integer, String, String) As Integer - Returns the position of the first occurrence of a String inside another String. The first character is numbered 1.
- Parameters:
- Start as Integer - The Start where to being searching in the string.
- Source as String - This is the source string that is going to be searched.
- Find as String - The String you are searching for in the Source.
- InStrB(Integer, String, String) As Integer - Returns the byte position of the first occurrence of a String inside another String. The first character is numbered 1.
- Parameters:
- Start as Integer - The Start where to being searching in the string.
- Source as String - This is the source string that is going to be searched.
- Find as String - The String you are searching for in the Source.
- IsA operator - Used to determine the class of a particular object reference.
- Left(String, Integer) As String - Returns the first n characters in a source String.
- Parameters:
- Source as String - The original string.
- Number as Integer - The number of byte characters to return from the Left.
- LeftB(String, Integer) As String - Returns the first n bytes in a source String.
- Parameters:
- Source as String - The original string.
- Number as Integer - The number of byte characters to return from the Left.
- Len(String) As Integer - Returns the number of characters in the specified String.
- LenB(String) As Integer - Returns the number of bytes in the specified String.
- Log(Double) As Double - Returns the natural logarithm of the value specified.
- Lowercase(String) As String - Converts all characters in a String to lowercase characters.
- LTrim(String) As String - Returns the String passed with leading (left side) whitespaces removed.
- Max(Double, Double) As Double - Returns the largest value passed to it.
- Me - Me refers to the control that fired the current event. Outside an event handler, it simply refers to the current object ( Self).
- Microseconds As Double - Returns the number of microseconds (1,000,000th of a second) that have passed since the user's computer was started.
- Mid(String, Integer, Integer) As String - Returns a portion of a String. The first character is numbered 1.
- Parameters:
- Source as String - The original string.
- Start as Integer - The position of the first character to be returned. The first character position is 1. If start is greater than the number of characters in source, an empty string is returned.
- Length as Integer - The number of characters to return from source. If length + start is greater than the length of source, all characters from start to the end of source will be returned.
- MidB(String, Integer, Integer) As String - Returns a portion of a String. The first character is numbered 1. (See Mid)
- Min(Double, Double) As Double) - Returns the smallest of the numbers passed.
- Nil - Used to determine if an object is nil (no value).
- NthField(String, String, Integer) As String - Returns a field from a row of data. The first field is numbered 1. If you need to parse binary data, use NthFieldB instead.
- Parameters:
- Source as String - The original string.
- Seperator as String - The character that separates the columns of data.
- Field Number as Integer - The column number of the desired field. The first field is numbered 1.
- Oct(Integer) As String - Returns as a String, the octal version of the number passed.
- Pow(Double, Double) As Double - Returns the value specified raised to the power specified.
- Redim - Resizes the passed array.
- Rem - Used to add comments to your code.
- Replace(String, String, String) As String - Replaces the first occurrence of a String with another String.
- Parameters:
- Source as String - The original string.
- Old String as String - The characters to be replaced.
- New String as Integer - The replacement characters.
- ReplaceB(String, String, String) As String - Replaces the first occurrence of a String with another String. (See Replace for Parameters)
- ReplaceAll(String, String, String) As String - Replaces all occurrences of a String with another String. (See Replace for Parameters)
- ReplaceAllB(String, String, String) As String - Replaces all occurrences of a String with another String. (See Replace for Parameters)
- RGB - Returns a Color based on the red, green, and blue amounts specified. These amounts are represented by integers between 0 and 255. You can also specify a color using the HSV or CMY function or the & color constant, &cRRBBGG (In Hex eg: &cFF5A0B).
- Right(String, Integer) As String - Returns the last n characters from the String specified.
- Parameters:
- Source as String - The original string.
- Number as Integer - The number of characters to return from the Right.
- RightB(String, Integer) As String - Returns the last n bytes from the String specified. (See Right for Parameters)
- Rnd As Double - Returns a randomly generated number in the range 0 <= Rnd < 1. The equivalent functionality is provided by the Random class as a special case. The Random class also provides additional options, such as a random number selected from a Normal distribution.
- Round(Double) As Double - Returns the value specified rounded to the nearest Integer.
- RTrim(String) As String - Returns the String data type passed with trailing (right side) whitespaces removed.
- Select Case - Executes one of several groups of statements, depending on the value of an expression.
- Self - Self is a reference to an object's parent object.
- Sin(Double) As Double - Returns the sine of the value specified.
- Sqrt(Double) As Double - Returns the square root of the value specified.
- Str(Double) As String - Returns the String form of the value passed.
- StrComp(String, String, Integer) As Integer - Makes a binary (case-sensitive) or text (lexicographic) comparison of the two strings passed and returns the result.
- Parameters:
- 1st String as String - The first string to compare.
- 2nd String as String - The second string to compare.
- Mode as Integer - The comparison mode, Binary or Text.
Mode can take on the following values:
0=binary (case-sensitive)
1=text (lexicographic) - RESULT as Integer - Returns the result of the comparison of string1 and string2.
The value can be -1, 0, or 1, according to the following rules:
If string1 < string2 the function returns -1
If string1 = string2 the function returns 0
If string1 > string2 the function returns 1
- Sub - Declares the name, parameters, and code that form the body of a subroutine (method).
- Tan(Double) As Double - Returns the tangent of the angle specified.
- Ticks As Integer - Returns the number of ticks (60th of a second) that have passed since the user's computer was started.
- Titlecase(String) As String - Returns the String passed to it with all alphabetic characters in Titlecase.
- Trim(String) As String - Returns the String passed with leading and trailing whitespaces removed.
- True - Used to set a Boolean object to the value of 'True' or test whether an existing Boolean expression is equal to True. A comparison of two values that are equal returns True.
- Ubound(array) As Integer - Returns the index of the last element in an array.
- Uppercase(String) As String - Converts all characters in a String to uppercase characters.
- Val(String) As Double - Returns the numeric form of a String.
- While...Wend - Repeatedly executes a series of statements while a specified condition is True.
View Online RB Documentation For more information.
Creating, Editing, and Running Scripts
There are two types of Scripts: Dice Set scripts and General Scripts.
Dice Set Scripts are stored in a subtable of a Dice Set. They are useful for scripts to be included with a specific dice set and so that scripts of the same name can do different things based on what is the current dicset. They can be called in a roll using the Script function. There are several ways to create a dice set script:
- Right click a dice button and choose New Dice Set Script. Enter the name for the script and then create the script in the editor. This will add the script to the diceset and create a call to it in the button.
- In the Customize Menu choose Script Editor and then New Dice Set Script. This opens the Dice Set's Script subtable for creating the new dice set script.
- Edit dice set directly by clicking hte menu in the top right and choosing Edit Dice Set and then Edit Scripts.... This will open the Dice Set's Script subtable for creating the new dice set script.
A General Script is stored in a file in the CrystalBallData's Scripts folder. They are useful for scripts that run the same all the time and aren't required for a dice set or are used across multiple dice sets. To create a General Script go to the Customize Menu and then Script Editor and then New General Script. This will open the script editor for the new script.
To Run a General Script, click on it from the Customize menu then Script Editor menu item and then the script name.
To edit the script, while holding down the shift key, click on it from the Customize menu then Script Editor menu item and then the script name.
Scripts with Dice Rolls
Scripts can be called from within rolls
To call a script fromi inside a roll use the following syntax: Script(MyScriptName) This can be put in a button's, rolled from the roll input box, or any other place where a dice roll can be put. If the script is used in a calculation like 1d20 + Script(MyScriptName) make sure to use the ReturnValue function within the script to return the value to be used in the calculation. Also see the Script dice function in the DiceFAQ for more information about the Script function.
Glossary
Button Event Script Only
These functions can only be used in a button event script. Button event scripts are set by right clicking a button and choosing an event from the button's "Events" menu. These scripts run when the specified event triggers. 'Button Event Script Only' functions are an easy format of the function that infers the button index from the current button triggering the event. The other versions of these functions that require a button index or name can be called in scripts that are not an event script.
Button Paint Event Script Only
These functions can only be used in a button's paint event script. Button paint event scripts are set by right clicking a button and choosing the "Paint" event from the button's "Events" menu. These scripts run when the button draws itself event triggers. 'Button Paint Event Script Only' functions draw on a button so that if the function is called while not in a paint event, there is nothing to draw on.
Call
Call is a RealBasic Keyword used to ignore the returned result of a function. RB requires that if a function returns a value that that value must be used. Sometimes the returned value is not needed. Instead of creating a temporary variable to hold the unneeded value, the keyword Call can be put in front of the function call.
Call GetButtonIndex("My Button") This would get the button index of "My Button" and return it. Since Call is used, the returned value is ignored.
Current Button
This the last clicked button. This is useful for updating the last clicked button based on some sort of event or roll or for knowing what was last rolled. Many of the button setting and getting functions have a version which will operate on the Current Button if no button index is given.
Dice Roll Scripts Only
These scripts can only be run when running a script as a dice set script. These scripts require settings that are only available during a roll. Both dice set scripts and menu scripts can be run as a Dice Set Script. To run either script type as a Dice Roll Script, run the roll CallScript(MyScriptName) in the roll input field or in a button or other roll location. Functions marked as 'Dice Roll Scripts Only' just means that the function only works when the script is called from a roll and gives an error when run by itself like when running a script from the scripts menu.
Dice Set Function
These functions add an additional parameter specifying which dice set to use. This will allow the function to operate on a dice set besides the one that is currently being displayed in the buttons. Functions that are not Dice Set Functions work only on the currently selected dice set being displayed in the buttons window.
Some of these functions require that the given dice set be the current dice set in order to work. So those functions will toggle the current dice set to the requested dice set, run the operation, and then toggle back to the original dice set. This may cause a flicker when the function is run. The most part of these functions don't require this toggling and won't have the flicker.
Having functions able to operate on different dice sets at one time is a very powerful way to sync and store values as well as to create templates of buttons to be copied to other sets and many other exciting possibilities. Thanks to Alvorn for this suggestion.
Flatten
When editing a script, in the libraries toolbar item, there is an option to "Flatten...". Flatten will put all the included libraries directly in the script. This makes the script more shareable since it doesn't require any libraries to be shared with it; everything will be in just one file. So, if you have a custom library called "My Library" and your script includes that library. You have a function in "My Library" called ShuffleCharacter(). In your script you call that function. Since "My Library" is included through the Libraries toolbar item your script can call that function without having the function directly in your script. When you flatten that script, all the script text from "My Library" gets put directly in your script and then "My Script" is no longer included from the libraries toolbar item. Your script now can run without the library. This does mean that if the library changes, your script won't see those changes. If you try to include "My Library" again after the script is flattened, you will probably get errors that things are already defined since they exist both in your script and in your library.
The Master Library cannot be flattened. If a script is including the Master Library, then when the script is flattened, the Master Library will not be flattened in to the script but it will continue to be included as a library for the new flattened script.
The main purpose of flattening is to make it easier to share scripts. If you have any questions please ask on the message boards
Global Variable
A Global Variable is a string key paired with a string value that is stored globally for as long as CBLite is running. Scripts can get and set these variables in order to communicate with each other and store values for later use. Some button events and other CBLite features set the value of relevant Global Variables to provide information about the current state of CBLite. One example of this is how when a button is pressed the button's index is set as the current button in the global variables. Following is the list of stored global variables, most of these are accessible through function calls:
- CurrentButtonHeight When in a script for a paint event, this global tracks the height of the button in pixels
- CurrentButtonIndex After a button is clicked, this tracks the index of the clicked button.
- CurrentButtonMouseX When the mouse moves over a button this is updated with the X coordinate of the mouse relative to the top left of the button.
- CurrentButtonMouseY When the mouse moves over a button this is updated with the Y coordinate of the mouse relative to the top left of the button.
- CurrentButtonName When a button is clicked, this is set to the name of the clicked button.
- CurrentButtonWidth When in a script for a paint event, this global tracks the width of the button in pixels
- CurrentDiceSet This tracks the name of the current dice set
- ButtonsHigh Tells how many rows of buttons there are on the main dice rolling window
- ButtonsWide Tells how many buttons across are shown in the main dice rolling window
Not In Paint Event
These functions can not be used in a dice button's paint event. If one of these methods is found in a paint event, the paint event will not run and will show an error message. These methods call update on the buttons to redraw them, so putting one in a paint even twill cause an infinite loop of redrawing.
Examples:
ArrayClass
An ArrayClass allows storing variant values in an array with elements 0 through n where n is the number of items - 1. Because Realbasic arrays don't allow passing by pointer (passed arrays are always copies) having an ArrayClass object allows arrays to pass by pointer so that their values can be changed in called methods. This also allows array functions to be made members of the class. The following is the list of functions usable on an ArrayClass object:
- Append()
Dim a As ArrayClass a = New ArrayClass a.Append("My Value")
Append adds the given data to the end of the array, increasing the array's size by 1. Arrays are of type Variant, so any value may be appended to an array.
- Parameter 1 - New Value (Variant) The value to add to the end of the array.
- No Return Value
- Clear()
Dim a As ArrayClass a = New ArrayClass a.Append("My Value") a.Clear()
Clear will remove all items from the array.- No Parameters
- No Return Value
- Clone()
Dim a As ArrayClass Dim b As ArrayClass a = New ArrayClass a.Append("My Value") b = a.Clone()
This will make a copy of array a and put it in to array b.- No Parameters
- Returned Value (ArrayClass) A copy of the array
- Explode(str As String, delimeter As String)
Dim a As ArrayClass a = New ArrayClass() a.Explode("list of items", " ")
Given a string and a delimiter, this will chop the string in to an array with each delimited part of the string being an item in the array.- Parameter 1 - theString (String) The string to be chopped.
- Parameter 2 - delimiter (String) The delimiter that determines where each part begins and ends.
- Returned Value (ArrayClass) The elements of the delimited string
- Implode(delimeter As String)
Dim a As ArrayClass a = New ArrayClass() a.Explode("list of items", " ") MessageBox(a.Implode(";"))
This will show the message "list;of;items". Implode returns the elements of an array as a single string with the delimiter placed between each element.- Parameter 1 - delimiter (String) The delimiter to be placed between each string element.
- No Return Value
- Items(index As Integer)
Dim theItem As Variant theItem = Items(4)
This will return the 5th item in the array and put it in to theItem. This returns Nil if the index is out of bounds.- Parameter 1 - Index (Integer) The 0 based item index in to the array.
- Returned Value (Variant) The element found at Index position in the array
- Remove(index As Integer)
myArray.Remove(4)
This will delete the 5th item in the array.- Parameter 1 - Index (Integer) The 0 based item index of the item to delete.
- No Return Value
- UBound()
Dim a As ArrayClass a = New ArrayClass a.Append("My Value") MessageBox("The array size is " + Str(a.UBound())
UBound returns the index of the array's last item (number of items - 1).- No Parameters
- Returned Value (Integer) The number of items in the list - 1. The last used index of the list.
ArrayIterator
An ArrayIterator provides a way to loop through an ArrayClass without requiring tracking the current position as an Integer nor knowing how many items there are in the ArrayClass.
- HasNext() GetNext()
Dim a As ArrayClass Dim i As ArrayIterator a = New ArrayClass a.Append("My Value") i = New ArrayIterator(a) While i.HasNext() MessageBox(i.GetNext()) Wend
HasNext() returns true if there is another item to get from the array. GetNext() returns the next item in the array and increments the current position by 1.
ButtonClear
Clears a button of its name, value, roll, and type. It can be called with either the 0 based index of the button, or by the button's name.
- ButtonClear() current button in the window
- No Parameters
- No Return Value
This will clear the - ButtonClear(5) This will clear the 6th button in the window
- Parameter 1 - Button Index (Integer) The 0 based number index of the button to clear
- No Return Value
- ButtonClear("This Button") This will clear the button with the name "This Button"
- Parameter 1 - Button Index (String) The name of the button to clear
- No Return Value
- ButtonClear(5, "Dice Set Name") Dice Set Function This will clear the 6th button of the dice set named "Dice Set Name"
- Parameter 1 - Button Index (Integer) The 0 based number index of the button to clear
- Parameter 2 - Dice Set Name (String) The name of the dice set to use
- No Return Value
- ButtonClear("This Button", "Dice Set Name") Dice Set Function This will clear the button with the name "This Button" from the dice set named "Dice Set Name"
- Parameter 1 - Button Index (String) The name of the button to clear
- Parameter 2 - Dice Set Name (String) The name of the dice set to use
- No Return Value
ButtonReplace
Replaces a button with the type, name, and values of another button.
- ButtonReplace(5, 3) Replaces the 4th button with the 6th button
- Parameter 1 - Source Button Index (Integer) The 0 based number index of the "source" button
- Parameter 2 - Destination Button Index (Integer) The 0 based number index of the "destination" button to be a copy of the "source" button
- No Return Value
- ButtonReplace("This Button", 3) Replaces the 4th button with the button named "This Button"
- Parameter 1 - Source Button Index (String) The name of the "source" button
- Parameter 2 - Destination Button Index (Integer) The 0 based number index of the "destination" button to be a copy of the "source" button
- No Return Value
- ButtonReplace(3, "This Button") Replaces the button named "This Button" with the 4th button
- Parameter 1 - Source Button Index (Integer) The 0 based number index of the "source" button
- Parameter 2 - Destination Button Index (String) The name of the "destination" button to be a copy of the "source" button
- No Return Value
- ButtonReplace("Other Button", "This Button") Replaces the button named "Other Button" with the button named "This Button"
- Parameter 1 - Source Button Index (String) The name of the "source" button
- Parameter 2 - Destination Button Index (String) The name of the "destination" button to be a copy of the "source" button
- No Return Value
- ButtonReplace(5, 3, "Dice Set One", "Dice Set Two") Dice Set Function Replaces the 4th button in the dice set called "Dice Set Two" with the 6th button in the dice set "Dice Set One"
- Parameter 1 - Source Button Index (Integer) The 0 based number index of the "source" button
- Parameter 2 - Destination Button Index (Integer) The 0 based number index of the "destination" button to be a copy of the "source" button
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
- ButtonReplace("This Button", 3, "Dice Set One", "Dice Set Two") Dice Set Function Replaces the 4th button in the dice set "Dice Set Two" with the button named "This Button" in the dice set "Dice Set One"
- Parameter 1 - Source Button Index (String) The name of the "source" button
- Parameter 2 - Destination Button Index (Integer) The 0 based number index of the "destination" button to be a copy of the "source" button
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
- ButtonReplace(3, "This Button", "Dice Set One", "Dice Set Two") Dice Set Function Replaces the button named "This Button" in the dice set "Dice Set Two" with the 4th button in the dice set "Dice Set One"
- Parameter 1 - Source Button Index (Integer) The 0 based number index of the "source" button
- Parameter 2 - Destination Button Index (String) The name of the "destination" button to be a copy of the "source" button
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
- ButtonReplace("Other Button", "This Button", "Dice Set One", "Dice Set Two") Dice Set Function Replaces the button named "Other Button" in the dice set "Dice Set Two" with the button named "This Button" in the dice set "Dice Set One"
- Parameter 1 - Source Button Index (String) The name of the "source" button
- Parameter 2 - Destination Button Index (String) The name of the "destination" button to be a copy of the "source" button
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
ButtonSwap
Swaps two buttons positions in the dice roller window.
- ButtonSwap(5, 3) Swaps the 4th button with the 6th button
- Parameter 1 - Button Index 1 (Integer) The 0 based number index of the 1st button to swap
- Parameter 2 - Button Index 2 (Integer) The 0 based number index of the 2nd button to swap
- No Return Value
- ButtonSwap("This Button", 3) Swaps the 4th button with the button named "This Button"
- Parameter 1 - Button Index 1 (String) The name of the 1st button to swap
- Parameter 2 - Button Index 2 (Integer) The 0 based number index of the 2nd button to swap
- No Return Value
- ButtonSwap(3, "This Button") Swaps the button named "This Button" with the 4th button
- Parameter 1 - Button Index 1 (Integer) The 0 based number index of the 1st button to swap
- Parameter 2 - Button Index 2 (String) The name of the 2nd button to swap
- No Return Value
- ButtonSwap("Other Button", "This Button") Swaps the button named "Other Button" with the button named "This Button"
- Parameter 1 - Button Index 1 (String) The name of the 1st button to swap
- Parameter 2 - Button Index 2 (String) The name of the 2nd button to swap
- No Return Value
- ButtonSwap(5, 3, "Dice Set One", "Dice Set Two") Dice Set Function Swaps the 4th button in the dice set "Dice Set Two" with the 6th button in the dice set "Dice Set One"
- Parameter 1 - Button Index 1 (Integer) The 0 based number index of the 1st button to swap
- Parameter 2 - Button Index 2 (Integer) The 0 based number index of the 2nd button to swap
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
- ButtonSwap("This Button", 3, "Dice Set One", "Dice Set Two") Dice Set Function Swaps the 4th button in the dice set "Dice Set Two" with the button named "This Button" in the dice set "Dice Set One"
- Parameter 1 - Button Index 1 (String) The name of the 1st button to swap
- Parameter 2 - Button Index 2 (Integer) The 0 based number index of the 2nd button to swap
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
- ButtonSwap(3, "This Button", "Dice Set One", "Dice Set Two") Dice Set Function Swaps the button named "This Button" in the dice set "Dice Set Two" with the 4th button in the dice set "Dice Set One"
- Parameter 1 - Button Index 1 (Integer) The 0 based number index of the 1st button to swap
- Parameter 2 - Button Index 2 (String) The name of the 2nd button to swap
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
- ButtonSwap("Other Button", "This Button", "Dice Set One", "Dice Set Two") Dice Set Function Swaps the button named "Other Button" in the dice set "Dice Set Two" with the button named "This Button" in the dice set "Dice Set One"
- Parameter 1 - Button Index 1 (String) The name of the 1st button to swap
- Parameter 2 - Button Index 2 (String) The name of the 2nd button to swap
- Parameter 3 - Dice Set Name 1(String) The name of the dice set to use for the first button
- Parameter 4 - Dice Set Name 2(String) The name of the dice set to use for the second button
- No Return Value
CallScript
Runs another script from inside a script. This only runs scripts that are saved in the "Scripts" folders inside the CrystalballData folder (These scripts can be access through the Customize> Script Editor Menu). The script is first searched for in the UserData's Scripts folder. If not found there, then the MainData's Scripts folder is searched. Calling another script calls the script immediately. The called script is fully run before returning back to the calling script.
Parameters can be passed to the called script. The parameters appear after the script name in a comma separated list. The parameters are given the name "paramX" where X is the 1 based number of the parameter so that the first parameter has the name param1 and the second has the name param2. The name is used to access the parameter value from within the called script. Parameters can also be named by using the following syntax "myvalue=Brett". A variable with the name "myvalue" would be assigned the value "Brett". If named, the parameter will get set with the given name and with the "paramX" name. Use the GetScriptParameter method to get the variable's value in the called script.
- CallScript("AnotherScript") The "Another Script" is run
- Parameter 1 - Script Name (String) The name of the script to run
- No Return Value
- CallScript("AnotherScript", "Brett", "is cool") The "Another Script" is run. "Another Script" will also have access to two variables. The param1 variable will have the value "Brett" and param2 will have the value "is cool". In "Another Script" use the GetScriptParameter method to get these variable values.
- Parameter 1 - Script Name (String) The name of the script to run
- Parameter X - Script Variables (String) One or more parameters to pass to the called script. These parameters can be named by separating the name and value with an equals (=) sign.
- No Return Value
- CallScript("AnotherScript", "name=Brett", "description=is cool") The "Another Script" is run. "Another Script" will also have access to two variables. The name variable will have the value "Brett" and description will have the value "is cool". In "Another Script" use the GetScriptParameter method to get these variable values.
- Parameter 1 - Script Name (String) The name of the script to run
- Parameter X - Script Variables (String) One or more parameters to pass to the called script. These parameters can be named by separating the name and value with an equals (=) sign.
- No Return Value
- CallScript("AnotherScript", "My Dice Set", "name=Brett", "description=is cool") Dice Set Function The "Another Script" is run. When searching for the "Another Script" it will first try to find the script file in the User's ScriptData folder and then in the MainData's Script Folder. If not found there, it will then search in the dice set for a dice set script with the name of "My Dice Set". "Another Script" will also have access to two variables. The name variable will have the value "Brett" and description will have the value "is cool". In "Another Script" use the GetScriptParameter method to get these variable values.
- Parameter 1 - Script Name (String) The name of the script to run
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to search for the script
- Parameter X - Script Variables (String) One or more parameters to pass to the called script. These parameters can be named by separating the name and value with an equals (=) sign. These parameters are all optional.
- No Return Value
-
Code Example - This example uses two script files. One is called ScriptOne and the other is ScriptTwo.
// ScriptOne's code // call ScriptTwo passing in two strings // hello will be in 'param1' // world will be in 'name' CallScript("ScriptTwo", "Hello ", "name=World!") //ScriptTwo's code // get the two parameters and output them in a messagebox // this will output: Hello World! MessageBox(GetScriptParameter("param1") + GetScriptParameter("name"))
EndOfLine
Returns an endofline string character that will break a string in to lines.
- MessageBox("Line 1" + EndOfLine() + "Line 2") The messagebox would show the message:
Line 1
Line2- No Parameters
- Returned Value (String) A string with the End Of Line character in it.
Quote
Returns a quote in a string. This is useful for putting a quote in a string since a quote by itself tells RBScript when a string starts and ends. By using Quote, a quote can be put in a string without the hassle of remembering the syntax for a non string terminating quote.
- MessageBox("MyStr = " + Quote() + "Quote" + Quote()) The messagebox would show the message: MyStr = "Quote"
- No Parameters
- Returned Value (String) A string with the quote (") character in it.
CounterButtonPushDownArrow
Pushes the down arrow of the counter button as if the down arrow had been clicked.
- CounterButtonPushDownArrow() current button's down arrow.
- No Parameters
- No Return Value
Pushes the - CounterButtonPushDownArrow("This Button") Pushes the down arrow of the counter button with the name of "This Button".
- Parameter 1 - Button Name (String) The name of the counter button to reset
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
- CounterButtonPushDownArrow(3) Pushes the down arrow of the 4th button
- Parameter 1 - Button Index (Integer) Pushes the down arrow of the 0 based number index button
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
- CounterButtonPushDownArrow("This Button", "My Dice Set") Dice Set Function Pushes the down arrow of the counter button with the name of "This Button" in the dice set "My Dice Set".
- Parameter 1 - Button Name (String) The name of the counter button to reset
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
- CounterButtonPushDownArrow(3, "My Dice Set") Dice Set Function Pushes the down arrow of the 4th button in the dice set "My Dice Set"
- Parameter 1 - Button Index (Integer) Pushes the down arrow of the 0 based number index button
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
CounterButtonPushUpArrow
Pushes the up arrow of the counter button as if the up arrow had been clicked.
- CounterButtonPushUpArrow() current button's up arrow.
- No Parameters
- No Return Value
Pushes the - CounterButtonPushUpArrow("This Button") Pushes the up arrow of the counter button with the name of "This Button".
- Parameter 1 - Button Name (String) The name of the counter button to reset
- No Return Value
- CounterButtonPushUpArrow(3) Pushes the up arrow of the 4th button
- Parameter 1 - Button Index (Integer) Pushes the up arrow of the 0 based number index button
- No Return Value
- CounterButtonPushUpArrow("This Button", "My Dice Set") Dice Set Function Pushes the up arrow of the counter button with the name of "This Button" in the dice set "My Dice Set".
- Parameter 1 - Button Name (String) The name of the counter button to reset
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
- CounterButtonPushUpArrow(3, "My Dice Set") Dice Set Function Pushes the up arrow of the 4th button in the dice set "My Dice Set"
- Parameter 1 - Button Index (Integer) Pushes the up arrow of the 0 based number index button
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
CounterButtonReset
Resets the counter button as if the button had been right clicked on and the "Reset" menu item chosen.
- CounterButtonReset() current button.
- No Parameters
- No Return Value
Resets the - CounterButtonReset("This Button") Resets the counter button with the name of "This Button".
- Parameter 1 - Button Name (String) The name of the counter button to reset
- No Return Value
- CounterButtonReset(3) Resets the 4th button
- Parameter 1 - Button Index (Integer) The 0 based number index of the button to reset
- No Return Value
- CounterButtonReset("This Button", "My Dice Set") Dice Set Function Resets the counter button with the name of "This Button" in the dice set "My Dice Set".
- Parameter 1 - Button Name (String) The name of the counter button to reset
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
- CounterButtonReset(3, "My Dice Set") Dice Set Function Resets the 4th button in the dice set "My Dice Set".
- Parameter 1 - Button Index (Integer) The 0 based number index of the button to reset
- Parameter 2 - Dice Set Name(String) The name of the dice set in which to find the counter button
- No Return Value
CreateDiceSet
Creates a new dice set with the given name. This dice set automatically gets Buttons, Variables, Scripts and Templates subtables and is saved in the DiceSets subfolder of the UserData's TableData folder. If the diceset name already exists then the function returns false. Otherwise it returns True. Use the keyword Call to ignore the returned result.
- Call CreateDiceSet("My New DiceSet") Creates a dice set called "My New DiceSet". If the dice set already existed then return would have been returned but the keyword Call makes the return result ignored.
- Parameter 1 - DiceSet Name (String) The name of the new dice set to be created
- Returned Value (Boolean) True if the dice set was created. False if the diceset already existed or could not be created.
Dictionary
A Dictionary allows storing string keys to variant values. The following is the list of functions usable on a Dictionary object:
- Clear()
Dim d As Dictionary d = New Dictionary d.SetValue("My Key", "My Value") d.Clear()
Clear removes all keys and values from the Dictionary.- No Parameters
- No Return Value
- Clone()
Dim d As Dictionary Dim d2 As Dictionary d = New Dictionary d.SetValue("My Key", "My Value") d2 = d.Clone()
Clone creates a copy of the Dictionary.- No Parameters
- Returned Value (Dictionary) A copy of the dictionary.
- HasKey()
Dim d As Dictionary d = New Dictionary d.SetValue("My Key", "My Value") If d.HasKey("My Key") Then MessageBox("Has Key") End If
HasKey() checks if the key is set in the dictionary. If so True is returned otherwise False is returned.- Parameter 1 - key (String) The key to find in the dictionary
- Returned Value (Boolean) True if the key exists in the Dictionary, False otherwise.
- Keys()
Dim d As Dictionary Dim a As ArrayClass d = New Dictionary d.SetValue("My Key", "My Value") a = d.keyes()
Keys() returns an ArrayClass holding all the keys in the Dictionary.- No Parameters
- Returned Value (ArrayClass) The keys in the Dictionary.
- SetValue()
Dim d As Dictionary d = New Dictionary d.SetValue("My Key", "My Value")
SetValue sets a key to value pair in the Dictionary. The Dictionary may be any data while the key must be a String.- Parameter 1 - key (String) The key to set to find the data.
- Parameter 2 - value (Variant) The value to match to the key.
- No Return Value
- Value()
Dim d As Dictionary d = New Dictionary d.SetValue("My Key", "My Value") MessageBox(d.Value("My Key")
Value returns the value for the given key.- Parameter 1 - key (String) The key to find in the dictionary and return its matching value.
- Returned Value (Variant) The value found for the key in the Dictionary. Nil if not found.
DictionaryIterator
A DictionaryIterator provides a way to loop through an ArrayClass without requiring tracking the current position as an Integer nor knowing how many items there are in the Dictionary.
- HasNext() GetNext()
Dim d As Dictionary Dim i As DictionaryIterator d = New Dictionary d.SetValue("My Key", "My Value") i = New DictionaryIterator(d) While i.HasNext() i.GetNext() MessageBox("Key = " + i.Key() + " Value = " + i.Value()) Wend
HasNext() returns true if there is another item to get from the dictionary. GetNext() increments the current position by 1. Key() and Value() return the current key to value pair from the iterator.
GetButtonIndex
Returns the 0 based numeric index of the button with the given name. Returns -1 if the button name is not found.
- GetButtonIndex() current button
- No Parameters
- Returned Value (Integer) The 0 based index of the current button or -1 if not found.
Returns the index of the - GetButtonIndex("My Button") Returns the index of the button with the name "My Button"
- Parameter 1 - Button Name (String) The name of the button of which to get the 0 based Integer index
- Returned Value (Integer) The 0 based index of the given button or -1 if not found.
GetButtonName
Returns the name of the 0 based numeric index of a button.
- GetButtonName() current button
- No Parameters
- Returned Value (String) The name of the current button or a blank string if not found.
Returns the name of the - GetButtonName(0) Returns the name of the 1st button
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to get the name
- Returned Value (String) The name of the button at the given Button Index or a blank string if not found.
GetButtonRoll
Gets the actual roll that would be made if a button was clicked on as a string. If a button performs the roll "1d20 + 10" every time it is clicked then caling GetButtonRoll for this button would return "1d20 + 10" as a string. The roll is not calculated nor rolled.
- GetButtonRoll() current button as a string
- No Parameters
- Returned Value (String) The roll used for the button.
Returns the roll used for the - GetButtonRoll(0) Returns the roll used for the 1st button
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to get its roll
- Returned Value (String) The roll used for the button.
- GetButtonRoll("My Button") Returns the roll used for the button with the name "My Button"
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to get its roll
- Returned Value (String) The roll used for the button.
GetCounterValue
Returns the value of a counter button. This is the number that is displayed in the counter button.
- GetCounterValue() current button
- No Parameters
- Returned Value (Double) The value of the counter button.
Gets the current value of the - GetCounterValue(4) Gets the value of the 5th button
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to get the value
- Returned Value (Double) The value of the counter button.
- GetCounterValue("Button Name") Gets the value for the button with the name "Button Name"
- Parameter 1 - Button Index (String) The name of the "source" button for which to get its value
- Returned Value (Double) The value of the counter button.
GetGlobalVariableString
Gets the string value of a script Global Variable. Use SetGlobalVariableString to set a Global Variable value.
- GetGlobalVariableString("My Value") Returns a string for the Global Variable "My Value"
- Parameter 1 - Global Variable Name (String) The variable name of the Global Variable to retrieve
- Returned Value (String) The value of the global variable with a matching a matching key or a blank string if not found.
GetMicroSeconds
Gets the microseconds since the computer started. This is useful for timers, andimations, and other time dependent features. Microseconds are 1,000,000th of a second.
- GetMicroSeconds() Returns the microseconds since the computer started
- No Parameters
- Returned Value (Double) The total microseconds (1,000,000th of a second) since the computer started.
GetScriptParameter
Gets the string value of a script Parameter. Parameters can be passed to a script when calling a script from another script with CallScript or in a dice roll using the Script() function.
- GetScriptParameter("param1") Returns a string for the parameter named "param1"
- Parameter 1 - Script Parameter Name (String) The parameter name of the parameter to retrieve
- Returned Value (String) The value of the script parameter with a matching key or a blank string if not found.
GetTable
Returns a TableClass object for the given table name. The table name is searched for the CrystalballData/User_Data/TableData folder and then in the MainData's TableData folder. The ".xml" at the end of the filename is added on if it is not already there. If the table is not found a NIL value is returned.
ONLY STRING TABLES
Only tables that have all their columns of the type String can be used with the TableClass. Columns with values as Integer, Double, or Boolean will be converted to String and written as String when the Table is saved. Other types of values will result in an error reading and writing the table.
- GetTable("MyTable") Finds the table named "MyTable.xml" in the User Data's Table Data folder and returns a TableClass with the corresponding Table and SubTables.
- Parameter 1 - Table Name (String) The name of the table to load
- Returned Value (TableClass) The found TableClass or Nil if not found.
GetVariableString
Returns the value of a variable in the current dice set. The returned value is a string.
- GetVariableString("VariableName") Returns the string value of the variable with the variable name "VariableName"
- Parameter 1 - Variable Name (String) The variable name of the dice set variable to retrieve
- Returned Value (String) The value of the variable with a matching key.
GetVariableValue
Returns the value of a variable in the current dice set. The returned value is a double, but is effected by the number of decimal places specified in the preferences' dice rolling tab.
- GetVariableValue("VariableName") Returns the numeric value of the variable with the variable name "VariableName"
- Parameter 1 - Variable Name (String) The variable name of the dice set variable to retrieve
- Returned Value (Double) The value of the variable with a matching a matching key or 0 if not found.
GraphicsBold
Sets the bold flag for drawing a string.
- GraphicsBold = True This will turn on bold for drawing strings
- GraphicsBold = False This will turn off bold for drawing strings
GraphicsDrawButtonCaption
If a script is written for a button's paint event, then the button's title will not be shown by default. This allows custom drawing of the button with the option to not show the title if the script doesn't want it. This function can be called in a button's paint event to draw the caption if the script wants the default caption drawn.
- GraphicsDrawButtonCaption() This will draw the caption on the current button.
- No Parameters
- No Return Value
GraphicsDrawLine
Draws a line on a button.
- GraphicsDrawLine(10, 10, 50, 50) This will draw a line starting at (10, 10) to (50, 50)
- Parameter 1 - X1 (Integer) X coordinate of point 1
- Parameter 2 - Y1 (Integer) Y coordinate of point 1
- Parameter 3 - X2 (Integer) X coordinate of point 2
- Parameter 4 - Y2 (Integer) Y coordinate of point 2
- No Return Value
GraphicsDrawOval
Draws an oval on a button.
- GraphicsDrawOval(10, 10, 50, 40) This will draw an oval at (10, 10) with width of 50 and height of 40
- Parameter 1 - X (Integer) X coordinate of oval
- Parameter 2 - Y (Integer) Y coordinate of oval
- Parameter 3 - Width (Integer) Width of oval
- Parameter 4 - Height (Integer) Height of oval
- No Return Value
GraphicsDrawPicture
Draws an image from a file on to the button. The picture can be skewed using the parameters.
- GraphicsDrawPicture("/Users/Awesome/Desktop/MyImage.jpg", 1, 1, 50, 50, 0, 0, -1, -1) This will draw the image at the given path in to the button. The image is placed at (1, 1) and is skewed to fit to (50, 50). The source is clipped from (0, 0) to the (width, height) of the image.
To find the picture, GraphicsDrawPicture first looks in the CrystalBallData/User_Data/Images/ folder. If not found there it then looks in CrystalBallData/Main_Data/Images. If still not found, it treats the path as an absolute path. If still not found, no picture is drawn. It is recommended to store your images in your CrystalBallData/User_Data/Images folder.- Parameter 1 - Path (String) This is the path to the image to draw on the button
- Parameter 2 - Destination X (Integer) The x position on the button where to draw the button
- Parameter 3 - Destination Y (Integer) The y position on the button where to draw the button
- Parameter 4 - Destination Width (Integer) This is the width on the button to place the image in to. The image will be skewed to fit this size. If the value is -1 then the size of the button is used.
- Parameter 5 - Destination Height (Integer) This is the height on the button to place the image in to. The image will be skewed to fit this size. If the value is -1 then the size of the button is used.
- Parameter 6 - Source X (Integer) This is the x position of the picture from which to start copying
- Parameter 7 - Source Y (Integer) This is the y position of the picture from which to start copying
- Parameter 8 - Source Width (Integer) This is the width of the picture to copy from. If set to -1 then this will be set to the width of the picture.
- Parameter 9 - Source Height (Integer) This is the height of the picture to copy from. If set to -1 then this will be set to the height of the picture.
- No Return Value
GraphicsDrawPolygon
Draws a polygon given an array of points. The polygon is closed so that the last point connects to the first point. All odd array indexes are x coordinates. All even array indexes are y coordinates. The array is 1 based.
- GraphicsDrawPolygon(points) Draws a polygon given the array of points
Dim points(6) As Integer points[1] = 0 points[2] = 0 points[3] = 10 points[4] = 15 points[5] = 20 points[6] = 25 GraphicsDrawPolygon(points)
- Parameter 1 - Points (Array of Integer) The points of the polygon.
- No Return Value
GraphicsDrawRect
Draws a rectangle on the button.
- GraphicsDrawRect(1, 1, 50, 50) Draws a rectangle on the button starting at (1, 1) and going to (50, 50).
- Parameter 1 - X1 (Integer) The left x position on the button where to draw the rect
- Parameter 2 - Y1 (Integer) The top y position on the button where to draw the rect
- Parameter 3 - X2 (Integer) The right x position on the button where to draw the rect
- Parameter 4 - Y2 (Integer) The bottom y position on the button where to draw the rect
- No Return Value
GraphicsDrawRoundRect
Draws a rectangle on the button with rounded corners.
- GraphicsDrawRoundRect(1, 1, 50, 50, 5, 5) Draws a rectangle on the button starting at (1, 1) and going to (50, 50) with rounded corners of 5 with and 5 height.
- Parameter 1 - X1 (Integer) The left x position on the button where to draw the rect
- Parameter 2 - Y1 (Integer) The top y position on the button where to draw the rect
- Parameter 3 - X2 (Integer) The right x position on the button where to draw the rect
- Parameter 4 - Y2 (Integer) The bottom y position on the button where to draw the rect
- Parameter 5 - ArcWidth (Integer) The width of the rounded corners
- Parameter 6 - ArcHeight (Integer) The height of the rounded corners
- No Return Value
GraphicsDrawString
Draws a string on the button.
- GraphicsDrawString("Hello World!", 7, 5, 50, True) Draws a the string "Hello World!" on the button at (7, 5). The string won't take up longer width than 50 and it will be condensed to try to fit (showing ... if it can't fit when condensed).
- Parameter 1 - Text (String) The text to draw on the button
- Parameter 2 - X (Integer) The x position to show the text
- Parameter 3 - Y (Integer) The y position to show the text
- Parameter 4 - WrapWidth (Integer) How much space horizontally to give the text before it tries to wrap. Set to 0 to not have a wrap width.
- Parameter 5 - Condense (Boolean) Flag telling if the text should try to be squished to fit in the WrapWidth.
- No Return Value
GraphicsFillOval
Fills an oval on a button.
- GraphicsFillOval(10, 10, 50, 40) This will fill an oval at (10, 10) with width of 50 and height of 40
- Parameter 1 - X (Integer) X coordinate of oval
- Parameter 2 - Y (Integer) Y coordinate of oval
- Parameter 3 - Width (Integer) Width of oval
- Parameter 4 - Height (Integer) Height of oval
- No Return Value
GraphicsFillPolygon
Fills a polygon given a 1 based array of points. The polygon is closed so that the last point connects to the first point. All odd array indexes are x coordinates. All even array indexes are y coordinates.
- GraphicsFillPolygon(points) Fills a polygon given the array of points
Dim points(6) As Integer points[1] = 0 points[2] = 0 points[3] = 10 points[4] = 15 points[5] = 20 points[6] = 25 GraphicsFillPolygon(points)
- Parameter 1 - Points (Array of Integer) The 1 based array of points of the polygon.
- No Return Value
GraphicsFillRect
Fills a rectangle on the button.
- GraphicsFillRect(1, 1, 50, 50) Fills a rectangle on the button starting at (1, 1) and going to (50, 50).
- Parameter 1 - X1 (Integer) The left x position on the button where to fill the rect
- Parameter 2 - Y1 (Integer) The top y position on the button where to fill the rect
- Parameter 3 - X2 (Integer) The right x position on the button where to fill the rect
- Parameter 4 - Y2 (Integer) The bottom y position on the button where to fill the rect
- No Return Value
GraphicsFillRoundRect
Fills a rectangle on the button with rounded corners.
- GraphicsFillRoundRect(1, 1, 50, 50, 5, 5) Fills a rectangle on the button starting at (1, 1) and going to (50, 50) with rounded corners of 5 with and 5 height.
- Parameter 1 - X1 (Integer) The left x position on the button where to fill the rect
- Parameter 2 - Y1 (Integer) The top y position on the button where to fill the rect
- Parameter 3 - X2 (Integer) The right x position on the button where to fill the rect
- Parameter 4 - Y2 (Integer) The bottom y position on the button where to fill the rect
- Parameter 5 - ArcWidth (Integer) The width of the rounded corners
- Parameter 6 - ArcHeight (Integer) The height of the rounded corners
- No Return Value
GraphicsForeColor
Sets the color that the graphics functions use for drawing shapes, filling shapes, and drawing strings.
- GraphicsForeColor = RGB(100, 200, 50) Sets the drawing color to be a color with red = 100, green = 200, and blue = 50.
GraphicsHeight
Gets the height of the button drwaing area.
- buttonHeight = GraphicsHeight() The buttonHeight variable will get set to the height of the button.
- No Parameters
- Returned Value (Integer) The height of the current button or 0 if not found.
GraphicsItalic
Sets the italic flag for drawing strings.
- GraphicsItalic = True Turns italic on for drawing a string.
- GraphicsItalic = False Turns italic off for drawing a string.
GraphicsPenHeight
Sets the height of the pen when drawing.
- GraphicsPenHeight = 15 The pen will set the height to 15.
GraphicsPenWidth
Sets the width of the pen when drawing.
- GraphicsPenWidth = 15 The pen will set the width to 15.
GraphicsSetPixel
Sets the color of a single pixel on the button.
- GraphicsSetPixel(10, 10, RGB(10, 50, 173)) The pixel at (10, 10) is set to a color with red = 10, green = 50, and blue = 173.
- Parameter 1 - X (Integer) The x position of the pixel
- Parameter 2 - Y (Integer) The y position of the pixel
- Parameter 3 - Pixel Color (Color) The color to put on the pixel
- No Return Value
GraphicsStringHeight
Given a string and wrap width this returns the height the string will take.
- GraphicsStringHeight("My String", 100) Returns how much height the string "My String" will take given a Wrap Width of 100 and using the current font, italic, underline, and bold.
- Parameter 1 - Text (String) The text for which to find the height
- Parameter 2 - WrapWidth (Integer) The width at which to wrap the string. A value of 0 means to now wrap
- Returned Value (Integer) The height the given string will take up with the current font settings and given wrapWidth.
GraphicsStringWidth
Given a string this returns the width the string will take.
- GraphicsStringWidth("My String") Returns how much width the string "My String" will take using the current font, italic, underline, and bold.
- Parameter 1 - Text (String) The text for which to find the width
- Returned Value (Integer) The width the given string will take up with the current font settings and given wrapWidth.
GraphicsTextFont
Sets the font to the given font for drawing strings.
- GraphicsTextFont = "Arial" Sets the string drawing font to "Arial".
GraphicsTextSize
Sets the size of the font.
- GraphicsTextSize = 30 Sets the font size to 30 for drawing strings.
GraphicsUnderline
Sets the underline flag for drawing a string.
- GraphicsUnderline = True This will turn on underline for drawing strings
- GraphicsUnderline = False This will turn off underline for drawing strings
GraphicsWidth
Returns the width of the button.
- GraphicsWidth() Returns the width of the drawing area of the button
- No Parameters
- Returned Value (Integer) The width of the zurrent button.
LookupFromTable_Double
Returns the numeric value of a variable looked up from a table. See DiceFAQ - Table Lookups and DiceFAQ - Table Random Rolling for related information.
- LookupFromTable_Double("TableName", "SubTableName", "RowKey", "ColumnName") Returns the numeric value of the cell at (row, column) in the subtable of the table specified
- Parameter 1 - Table Name (String) The name of the table
- Parameter 2 - Sub Table Name (String) The name of the sub table
- Parameter 3 - Row Key (String) The string key of the row
- Parameter 4 - Column Name (String) The column name for the value
- Returned Value (Double) The value of the cell in the table at (row, column) or 0 if not found.
LookupFromTable_String
Returns the string value of a variable looked up from a table. See DiceFAQ - Table Lookups and DiceFAQ - Table Random Rolling for related information.
- LookupFromTable_String("TableName", "SubTableName", "RowKey", "ColumnName") Returns the string result of the cell at (row, column) in the subtable of the table specified
- Parameter 1 - Table Name (String) The name of the table
- Parameter 2 - Sub Table Name (String) The name of the sub table
- Parameter 3 - Row Key (String) The string key of the row
- Parameter 4 - Column Name (String) The column name for the value
- Returned Value (String) The value of the cell in the table at (row, column) or a blank string if not found.
MessageBox
Shows a message to the user
- MessageBox("CBLite Scripting is fun") The messagebox would show the message: CBLite Scripting is fun
- Parameter 1 - Message (String) The message to show the user
- No Return Value
OutputText
Shows text in the dice roller window's output box
- OutputText("This is shown") The dice roller window's output box shows the message: This is shown
- Parameter 1 - Message (String) The message to put in the dice roll output box
- No Return Value
PlaySoundFile
Plays a sound file found in any of the CrystalBallData's sounds folders. It is encouraged that your sounds should be stored in your CrystalBallData/User_Data/Sounds/ folder.
- PlaySoundFile("SwordClash.mp3") The SwordClash.mp3 file located in the sound folder of the CrystalBallData folder is played
- Parameter 1 - Filename (String) The name of the sound file to play
- No Return Value
ReturnValue
ReturnValue is used in a script called inside a dice roll. It sets the string and/or numeric values to return back to the roll. ie The roll is 1d20 + Script(MyScript) and inside the script called MyScript ReturnValue(32) would return 32 back to be added to 1d20. ReturnValue does not stop your scripts execution and can be called more than once in the same script (overriding the previously set return value(s)).
- ReturnValue("This Rocks!", 32) Returns the string "This Rocks!" with the number value of 32 to the calling roll
- Parameter 1 - String Value (String) The string value to return
- Parameter 2 - Integer Value (Integer) The integer value to return
- No Return Value
- ReturnValue(32, "This Rocks!") Returns the string "This Rocks!" with the number value of 32 to the calling roll
- Parameter 1 - Integer Value (Integer) The integer value to return
- Parameter 2 - String Value (String) The string value to return
- No Return Value
- ReturnValue("This Rocks!") Returns the string "This Rocks!" to the calling roll
- Parameter 1 - String Value (String) The string value to return
- No Return Value
- ReturnValue(32) Returns the value of 32 to the calling roll
- Parameter 1 - Integer Value (Integer) The integer value to return
- No Return Value
RollDice
Rolls a roll and returns the numeric result of the roll back to the script.
- RollDice("1d20 + 6") 1d20 + 6 is rolled using standard dice rolling and the numeric result of 1d20 + 6 is returned back to the script
- Parameter 1 - Roll (String) The dice roll to roll
- Returned Value (Double) The resulting value of the passed in roll string.
SendText_ToAll
Sends text to all network connected players.
- SendText_ToAll("Hello Gamers!") "Hello Gamers!" is sent to all connected participants
- Parameter 1 - Text (String) The text to send
- No Return Value
SendText_ToSpecific
Sends text to a comma separated lists of specific connected players.
- SendText_ToSpecific("Hello Gamers!", "Uskaks,Realgan") Only Realgan and Uskaks are sent the message: "Hello Gamers!"
- Parameter 1 - Text (String) The text to send
- Parameter 2 - Recipients (String) The comma separated list of people to send to
- No Return Value
SetButtonColor
Sets the background color of a button.
- SetButtonColor(RGB(0, 15, 100)) current button to RGB(0, 15, 100)
- Parameter 1 - Background Color (Color) The background color for the button
- No Return Value
Sets the color of the - SetButtonColor(4, RGB(0, 15, 100)) Sets the color of the 5th button to RGB(0, 15, 100)
- Parameter 1 - Button Index (Integer) The 0 based index of the button of which to set the background color
- Parameter 2 - Background Color (Color) The background color for the button
- No Return Value
- SetButtonColor("Button Name", RGB(0, 15, 100)) Sets the color of the button with the name "Button Name" to RGB(0, 15, 100)
- Parameter 1 - Button Name (String) The name of the button of which to set the background color
- Parameter 2 - Background Color (Color) The background color for the button
- No Return Value
SetButtonDownArrow
Sets the down arrow roll of a counter button.
- SetButtonDownArrow("1d4") current button to be 1d4
- Parameter 1 - Roll (String) The roll to put in the counter's down arrow
- No Return Value
Sets the down arrow roll of the - SetButtonDownArrow(4, "1d4") Sets the 5th button's down arrow roll to 1d4
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to set the down arrow roll
- Parameter 2 - Roll (String) The roll to put in the counter's down arrow
- No Return Value
- SetButtonDownArrow("Button Name", "1d4") Sets the button's down arrow roll to 1d4 of the button with the name "Button Name"
- Parameter 1 - Button Index (String) The name of the "source" button for which to set the down arrow roll
- Parameter 2 - Roll (String) The roll to put in the counter's down arrow
- No Return Value
RefreshButton
Causes a single button to repaint itself which also calls the button's paint event if it has one. Do not use this inside of a button's Paint event.
- RefreshButton() current button to repaint
- No Parameters
- No Return Value
Causes the - RefreshButton(4) Causes the 5th button to repaint
- Parameter 1 - Button Index (Integer) The 0 based number index of the button to repaint
- No Return Value
- RefreshButton("Button Name") Causes the button with the name "Button Name" to repaint
- Parameter 1 - Button Index (String) The name of the button to repaint
- No Return Value
RefreshAllButtons
Causes all the buttons to repaint themselves.
- RefreshAllButtons() All buttons will repaint themselves which will also trigger the buttons' paint events if they have one. Do not use this inside of a button's Paint event.
- No Parameters
- No Return Value
SetButtonName
Sets the name of a button.
- SetButtonName("New Name") current button to "New Name"
- Parameter 1 - New Name (String) The new name to put in for the button
- No Return Value
Sets the button name of the - SetButtonName(4, "New Name") Sets the 5th button's name to "New Name"
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to set the down arrow roll
- Parameter 2 - New Name (String) The new name to put in for the button
- No Return Value
- SetButtonName("Old Name", "New Name") Sets the button's name of the button with the name "Old Name" to "New Name"
- Parameter 1 - Button Index (String) The name of the "source" button for which to set the down arrow roll
- Parameter 2 - New Name (String) The new name to put in for the button
- No Return Value
SetButtonRoll
Sets the roll the button will roll when pressed.
- SetButtonRoll("1d10 + 4") current button to 1d10 + 4
- Parameter 1 - Roll (String) The roll to put in for the button
- No Return Value
Sets the roll for the - SetButtonRoll(4, "1d10 + 4") Sets the roll for the 5th button to "1d10 + 4"
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to set the down arrow roll
- Parameter 2 - Roll (String) The roll to put in for the button
- No Return Value
- SetButtonRoll("Button Name", "1d10 + 4") Sets the roll for the button with the name "Button Name" to "1d10 + 4"
- Parameter 1 - Button Index (String) The name of the "source" button for which to set the down arrow roll
- Parameter 2 - Roll (String) The roll to put in for the button
- No Return Value
SetButtonStyle
Sets the style of a button. The style can be set to one of the following constants:
- kButtonStyle_Style1 Button Style 1
- kButtonStyle_Style2 Button Style 2
- kButtonStyle_Style3 Button Style 3
- kButtonStyle_Style4 Button Style 4
- kButtonStyle_DisplayButton Display Button - shows title and current value of the button
- kButtonStyle_Counter Counter Button - title, up arrow, down arrow, and editable current value of the button
- SetButtonStyle(kButtonStyle_Style1) current button to a "Style 1" button
- Parameter 1 - Button Style (String) The new style for the button
- No Return Value
Sets the - SetButtonStyle(3, kButtonStyle_Style1) Sets the 4th button to a "Style 1" button
- Parameter 1 - Button Index (String) The 0 based index of the button
- Parameter 2 - Button Style (String) The new style for the button
- No Return Value
- SetButtonStyle("The Button", kButtonStyle_Style1) Sets the button with the name "The Button" to a "Style 1" button
- Parameter 1 - Button Name (String) The name of the button
- Parameter 2 - Button Style (String) The new style for the button
- No Return Value
SetButtonUpArrow
Sets the up arrow roll of a counter button.
- SetButtonUpArrow("1d4") current button to be 1d4
- Parameter 1 - Roll (String) The roll to put in for the button's up arrow
- No Return Value
Sets the up arrow roll of the - SetButtonUpArrow(4, "1d4") Sets the 5th button's up arrow roll to 1d4
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to set the down arrow roll
- Parameter 2 - Roll (String) The roll to put in for the button's up arrow
- No Return Value
- SetButtonUpArrow("Button Name", "1d4") Sets the button's up arrow roll to 1d4 of the button with the name "Button Name"
- Parameter 1 - Button Index (String) The name of the "source" button for which to set the down arrow roll
- Parameter 2 - Roll (String) The roll to put in for the button's up arrow
- No Return Value
SetCounterResetRoll
Sets the reset roll for a counter. The result of this roll is the value put in the counter when the counter is reset.
- SetCounterResetRoll("1d20") current button to "1d20"
- Parameter 1 - Value (String) The roll to put in for resetting the counter button
- No Return Value
Sets the reset roll value for the - SetCounterResetRoll(4, "1d20") Sets the reset roll for the 5th button to "1d20"
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to set the reset roll
- Parameter 2 - Value (String) The roll to put in for resetting the counter button
- No Return Value
- SetCounterResetRoll("Button Name", "1d20") Sets the reset roll for the button with the name "Button Name" to "1d20"
- Parameter 1 - Button Index (String) The name of the "source" button for which to set the reset roll
- Parameter 2 - Value (String) The roll to put in for resetting the counter button
- No Return Value
SetCounterValue
Sets the value of a counter.
- SetCounterValue("32") current button to 32
- Parameter 1 - Value (String) The value to put in for the counter button
- No Return Value
Sets the counter value for the - SetCounterValue(4, "32") Sets the counter value for the 5th button to "32"
- Parameter 1 - Button Index (Integer) The 0 based number index of the button for which to set the down arrow roll
- Parameter 2 - Value (String) The value to put in for the counter button
- No Return Value
- SetCounterValue("Button Name", "1d4") Sets the counter value for the button with the name "Button Name" to "1d4"
- Parameter 1 - Button Index (String) The name of the "source" button for which to set the down arrow roll
- Parameter 2 - Value (String) The value to put in for the counter button
- No Return Value
SetCurrentDiceSet
Sets the current dice set to the passed in name.
- SetCurrentDiceSet("My Dice Set") The current dice set is changed to "My Dice Set"
- Parameter 1 - Dice Set Name (String) The name of the dice set to become the current one
- No Return Value
SetGlobalVariableString
Sets a string value to a script Global Variable. Use GetGlobalVariableString to get a Global Variable value.
- SetGlobalVariableString("My Value", "This is my value") Sets "This is my value" in to the Global Variable "My Value"
- Parameter 1 - Global Variable Name (String) The name of the Global Variable to set
- Parameter 2 - Global Variable Value (String) The new value of the Global Variable
- No Return Value
SetTableValue
Sets a value in a table that is then written to a file. This is useful for storing data to be used even after CBLite is closed and reopened. Use LookupFromTable_String to later retrieve the value.
- SetTableValue("MyTable", "MySubTable", "KeyValue", "ColumnName", "NewValue") Loads the table with the name "MyTable" or, if table does not exist, creates it. It then uses the subtable "MySubTable" and creates it if it is missing. Uses "KeyValue" to search in the first column of the table for a match and creates a row for it if one doesn't exist. "ColumnName" Tells in which column the value is to be stored, creating it if it does not exist. Sets the value of cell at ("KeyValue" row, "ColumnName" column) to "NewValue"
- Parameter 1 - Table Name (String) The name of the table to use. The table name will have ".xml" added to it automatically if it is missing. This table is saved in the UserData/TableData folder unless it is originally found in a different folder
- Parameter 2 - SubTable Name (String) The name of the subtable to use. A multitable can have more than one subtable. The subtable is created if it isn't found
- Parameter 3 - Key Value (String) This is the value in the first column of the table that is searched for in order to determine which row will hold the value
- Parameter 4 - Column Name (String) The name of the column that will hold the new value. If the column name doesn't exist in the subtable, it is created
- Parameter 5 - Value (String) This is the value that is put in the table at the (Key Value row, Column Name column)
- No Return Value
SetVariableValue
Sets a variable to the given value.
- SetVariableValue("My Variable", 42) Sets the variable "My Variable" to 42
- Parameter 1 - Variable Name (String) The name of the dice set variable to set
- Parameter 2 - Variable Value (Integer) The new value of the dice set variable
- No Return Value
SetVariableString
Sets a variable to the given string. This allows putting a roll in to a variable instead of putting the roll's result in to the variable.
- SetVariableString("My Variable", "floor((_button_ - 10) / 2") Sets the variable "My Variable" to "floor((_button_ - 10) / 2"
- Parameter 1 - Variable Name (String) The name of the dice set variable to set
- Parameter 2 - Variable Dice Roll (String) The roll for this variable
StartTimer
Timers allow a script to be run after a specified interval. The run script can even be the script creating the timer. You can also specify a Timer Name so that the timer can be later stopped. The delay is a decimal number specifying how many seconds to wait before running the passed in script. If the delay were 10.25, then after 10 1/4 seconds, the passed in script would run. The timer can also be told to run a certain number of times before removing itself. The number of times to run can also be set to -1 in order that the script runs indefinitely. If a script's number of times to run is set to -1, then the script must have a name so that it can be stopped later if desired.
- StartTimer("My Timer", 5.25, "My Script", 5) Creates a timer called "My Timer" that runs every 5.25 seconds. When it runs, it runs the script in the User's Scripts folder called "My Script". After running 5 times this script will remove itself and stop running
- StartTimer("My Timer", 0.25, "My Script", -1) Creates a timer called "My Timer" that runs every 0.25 seconds. When it runs, it runs the script in the User's Scripts folder called "My Script". This script will keep running until a script calls StopTimer("My Script")
- Parameter 1 - Timer Name (String) The name of the timer
- Parameter 2 - Recurrance (Double) Delay between when the timer will fire
- Parameter 3 - Script Name (String) The name of the script to run when the timer fires
- Parameter 4 - Times To Run (Integer) How many times to run before the timer is destroyed
- No Return Value
StopTimer
Timers can be stopped by calling StopTimer and passing in the name of the timer to stop. The name of the timer is the name given to it in StartTimer.
- StopTimer("My Timer") The timer with the name "My Timer" is stopped and will not fire any more events
- Parameter 1 - Timer Name (String) The name of the timer to stop
- No Return Value
StrsDiffersAt
This function compares two strings and returns the first position at which they differ. This is a utility function used in backend stuff and exposed out of pure charity.
- StrsDiffersAt("My Timer", "my limber") Returns 4 because l and T do not match and the first characters not matching from the left.
- Parameter 1 - String 1 (String) First string to compare
- Parameter 1 - String 2 (String) Second string to compare
- Returned Value (Integer) The position at which the strings first differ. If the strings are the same, -1 is returned.
SubTableClass
A SubTableClass gives access to the subtables of a multitable. This is where the actual data of the table is stored. Each SubTable has its own name and its own rows/columns of data that are completely independent of other subtables in the table. Subtables allow related data to be grouped in one file though the data itself may not be closely tied together. SubTables provide access to Cells, Rows, Columns and other ways of manipulating the data. Remember that all the data in the table must be a String.
The following is the list of functions usable on a SubTableClass object:
- Constructor()
Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable")
This creates a new SubTableClass.- Parameter 1 - Sub Table Name (String) The name of the sub table being created. Sub tables must have a name so there is no default Constructor.
- No Return Value
- AddColumn()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.AddColumn("MyColumn")
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then adds a column called "MyColumn" to the table.- Parameter 1 - Column Name (String) The column name to add to the Sub Table. It is added to the end of the current columns list.
- No Return Value
- Cell()
Dim table As TableClass Dim subTable As SubTableClass Dim data As String table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.Cell(0, 0) = "MyData" subTable.Cell("MyKey", 0) = "MyData" subTable.Cell(0, "MyColumn") = "MyData" subTable.Cell("MyKey", "MyColumn") = "MyData" MessageBox(subTable.Cell(0, 0)) MessageBox(subTable.Cell("MyKey", 0)) MessageBox(subTable.Cell(0, "MyColumn")) MessageBox(subTable.Cell("MyKey", "MyColumn"))
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then sets the value in the cell in the 0th row and 0th column to "MyData". It then gets the data from the 0th row and 0th column and shows it in a messagebox.- Parameter 1 - Row Number (Integer / String) Integer : The 0 based index of the row of the table for which to get its data.
String : The key value to match to find the row based on either the values in the first column or the values in the column with the name of "Key" if there is one.
- Parameter 2 - Column Number (Integer / String) Integer : The 0 based index of the column of the table for which to get its data.
String : The name of the column.
- Returned Value (String) The data found at the (row, column) location in the table.
- Parameter 1 - Row Number (Integer / String) Integer : The 0 based index of the row of the table for which to get its data.
- DeleteColumn()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.DeleteColumn(0)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then deletes the sub table's 0th column.- Parameter 1 - Column Number (Integer) The 0 based index of the column of the table to delete.
- No Return Value
- DeleteColumn()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.DeleteColumn("MyColumn")
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then deletes the sub table's "MyColumn" column.- Parameter 1 - Column Name (String) The name of the column of the table to delete.
- No Return Value
- DeleteRow()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.DeleteRow(0) subTable.DeleteRow("MyKey")
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then deletes the row at index 0. All rows below this row are moved up one.- Parameter 1 - Row Number (Integer / String) Integer : The 0 based index of the row to delete.
String : the value to match in the 0th column or the in the column named "Key" if there is one.
- No Return Value
- Parameter 1 - Row Number (Integer / String) Integer : The 0 based index of the row to delete.
- GetColumnData()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetColumnData(0)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets all the values in the 0th column of the table.- Parameter 1 - Column Index (Integer) The 0 based index of the column to get its values from.
- Returned Value (ArrayClass) The data values found in the column. The data's index is the row that the data was found on.
- GetColumnData()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetColumnData("MyColumn")
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets all the values in the column named "MyColumn" of the table.- Parameter 1 - Column Name (String) The name of the column to get its values from.
- Returned Value (ArrayClass) The data values found in the column. The data's index is the row that the data was found on.
- GetColumnName()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") MessageBox(subTable.GetColumnName(0))
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then shows the name of the column at the 0 based index of 0 in a messagebox.- Parameter 1 - Column Index (Integer) The 0 based index of the column to get.
- Returned Value (String) The found column name
- GetColumns()
Dim table As TableClass Dim subTable As SubTableClass Dim data As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetColumns()
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the names of the columns for the table.- No Parameters
- Returned Value (ArrayClass) The names of the columns of the table. The index of each array item corresponds to the column index of the column in the table.
- GetEmptyRow()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetEmptyRow()
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets a Dictionary of blank strings for each column name.- No Parameters
- Returned Value (Dictionary) A Dictionary with keys equal to the sub table's column names and values for the keys all equal to a blank string.
- GetKeys()
Dim table As TableClass Dim subTable As SubTableClass Dim keys As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") keys = subTable.GetKeys()
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets an ArrayClass of the "key" values for the table. This is useful for having each row having a unique identifier (like character name) and allows looking up values based on this identifier.- No Parameters
- Returned Value (ArrayClass) An ArrayClass of the "keys" for a table. The "key" column is the first column in the table that does not have the column name "value". Or, it uses the column named "key" if there is one.
- GetName()
Dim table As TableClass Dim subTable As SubTableClass Dim keys As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") MessageBox(subTable.GetName())
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then shows a MessageBox with the name of the subtable in it, which in this case would be "MySubTable".- No Parameters
- Returned Value (String) The name of the subtable.
- GetRandomRow()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetRandomRow()
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets a Dictionary of a randomly chosen row from the SubTable. Each row has a weight of one. Or, if a column has the name of Weight then the values of this Weight column are used for each row's weight. The weights are totaled and a random number from 1 to the total weight is chosen. This determines which row's data is returned.- No Parameters
- Returned Value (Dictionary) The returned dictionary has keys equal to column names and values equal to the row's cell's value for the matching key. The returned dictionary also has one extra field with the key of Row Number which tells which row number the data was taken from.
- GetRow()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetRow("MyKey")
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets all the values in the row with a key value of "MyKey".- Parameter 1 - Row Number (String) The key name for the row of the table for which to get its data. Keys are the values either in the 1st column or in the column with the name of "key" if there is one.
- Returned Value (Dictionary) The data values found in the given row. The dictionary's key is the column name and the value is the data found in that column for the given row.
- GetRow()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetRow(0)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets all the values in the 0th row.- Parameter 1 - Row Number (Integer) The 0 based index of the row of the table for which to get its data.
- Returned Value (Dictionary) The data values found in the given row. The dictionary's key is the column name and the value is the data found in that column for the given row.
- GetRowNumForKey()
Dim table As TableClass Dim subTable As SubTableClass Dim rowNum As Integer table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") rowNum = subTable.GetRowNumForKey("MyKey")
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the row number of the row with the key of "MyKey".- Parameter 1 - Row Key (String) The value in the row in the 0th column or in the column with the name of "Key" for which to return the row number.
- Returned Value (Integer) The found row number for the given key.
- GetRows()
Dim table As TableClass Dim subTable As SubTableClass Dim data As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetRows()
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the rows of the table as an ArrayClass.- No Parameters
- Returned Value (ArrayClass) The returned Array represents each row of the table. Each item in the array is a Dictionary which has keys equal to the column names of the table and values equal to the value for the row for the matching column name.
- InsertRow()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.InsertRow(0)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then inserts a blank row in to the sub table at row index 0. This blank row will have all the cells for each column set to an empty string.- Parameter 1 - Row Number (Integer) The 0 based index of the row at which to insert a new row. Rows after this index will be moved down.
- No Return Value
- MoveRow()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") subTable.MoveRow(0, 4)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then moves the row at index 0 to index 4.- Parameter 1 - Source Row Number (Integer / String) Integer : The 0 based index of the row to be moved.
String : the value to match in the 0th column or the column named "Key" if there is one
- Parameter 2 - Destination Row Number (Integer / String) Integer : The 0 based index where the row will be after the move.
String : the value to match in the 0th column or in the column named "key" if there is one.
- No Return Value
- Parameter 1 - Source Row Number (Integer / String) Integer : The 0 based index of the row to be moved.
- NumCols()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") MessageBox(Str(subTable.NumCols()))
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then shows the number of columns in the subtable in a messagebox.- No Parameters
- Returned Value (Integer) The number of columns in the Sub Table
- NumRows()
Dim table As TableClass Dim subTable As SubTableClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") MessageBox(Str(subTable.NumRows()))
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then shows the number of rows in the subtable in a messagebox.- No Parameters
- Returned Value (Integer) The number of rows in the Sub Table
- SetColumnData()
Dim table As TableClass Dim subTable As SubTableClass Dim data As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetColumnData(0) data.Items(0) = "changed value" data.SetColumnData(0, data)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the 0th column's data as an ArrayClass, changes the value of the 0th row for the column to "changed value" and then puts the changed data back in to the column.- Parameter 1 - Column Index (Integer) The 0 based index of which column to set.
- Parameter 2 - Data Array (ArrayClass) An ArrayClass with the data for the column. Each ArrayClass index correspondes to the row number for the data.
- No Return Value
- SetColumnData()
Dim table As TableClass Dim subTable As SubTableClass Dim data As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetColumnData("MyColumn") data.Items(0) = "changed value" data.SetColumnData("MyColumn", data)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the "MyColumn" column's data as an ArrayClass, changes the value of the 0th row for the column to "changed value" and then puts the changed data back in to the column.- Parameter 1 - Column Name (String) The name of which column to set.
- Parameter 2 - Data Array (ArrayClass) An ArrayClass with the data for the column. Each ArrayClass index correspondes to the row number for the data.
- No Return Value
- SetRow()
Dim table As TableClass Dim subTable As SubTableClass Dim data As Dictionary table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetRow(0) data.SetValue("MyColumn", "changed value") subTable.SetRow(0, data) subTable.SetRow("MyKey", data)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the 0th row as a Dictionary, changes the value of the "MyColumn" cell and then sets the 0th row's data from the dictionary.- Parameter 1 - Row Index (Integer / String) Integer : The 0 based index of which row to set.
String : The value to match in the 0th column for the row or the value in the "Key" column if there is one
- Parameter 2 - Data Dictionary (Dictionary) A Dictionary with the data for the row. Keys are the column names. Values are the row's cell values for the matching key column name.
- No Return Value
- Parameter 1 - Row Index (Integer / String) Integer : The 0 based index of which row to set.
- SetRows()
Dim table As TableClass Dim subTable As SubTableClass Dim data As ArrayClass table = GetTable("MyTable") subTable = table.GetSubTable("MySubTable") data = subTable.GetRows() data.Append(subTable.GetEmptyRow()) subTable.SetRows(data)
This loads a table from the "MyTable.xml" file and gets its subtable with the name "MySubTable". It then gets the rows of the table, adds a blank row, and sets the rows of the table to the changed data.- Parameter 1 - Rows Data (ArrayClass) Sets the table's rows to the passed in array of Dictionaries. The Array represents each row of the table. Each item in the array is a Dictionary which has keys equal to the column names of the table and values equal to the value for the row for the matching column name.
- No Return Value
TableClass
A TableClass allows reading and writing tables. It also gives access to SubTables which allow direct editing of a table.
TablesClass only works with tables of strings. Integer, Double, and Boolean values are converted to String. This class adds a lot of power to scripts allowing them to get and store data as a Table.
Tables are the top layer. They contain SubTables which contain the actual data. A table can have several Sub Tables referenced by name.
The following is the list of functions usable on a TableClass object:
- Constructor()
Dim table As TableClass table = GetTable("MyTable")
This creates a new TableClass loaded from the table named "MyTable" stored in either the user_data's or main_data's table_data folder.- Parameter 1 - Table Name (String) The name of the table to load
- No Return Value
- Constructor()
Dim table As TableClass table = GetTable()
This creates a blank TableClass ready for custom creation.- No Parameters
- No Return Value
- AddSubTable()
Dim table As TableClass table = GetTable Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") table.AddSubTable(subTable)
This creates a blank TableClass and adds a new sub table to it called "MySubTable".- Parameter 1 - New Sub Table (SubTableClass) The sub table to add to the table.
- No Return Value
- Delete()
Dim table As TableClass Dim num As Integer table = GetTable("MyTable") table.Delete()
This opens the table called "MyTable" and then deletes the table from disk.- No Parameters
- No Return Value
- DeleteSubTable()
Dim table As TableClass table = New TableClass Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") table.AddSubTable(subTable) table.DeleteSubTable("MySubTable")
This creates a blank TableClass and adds a new sub table to it called "MySubTable". It then deletes the added sub table out of the table with the DeleteSubTable call.- Parameter 1 - Sub Table Name (String) The sub table to delete from the table.
- No Return Value
- GetSubTable()
Dim table As TableClass table = New TableClass Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") table.AddSubTable(subTable) subTable = table.GetSubTable(0) subTable = table.GetSubTable("MySubTable")
This creates a blank TableClass and adds a new sub table to it called "MySubTable". It then gets the added sub table out of the table with the GetSubTable call.- Parameter 1 - Sub Table Name (Integer / String) Integer : the 0 based index of the subtable to get.
String : The sub table name to return.
- Returned Value (SubTableClass) The sub table with that name
- Parameter 1 - Sub Table Name (Integer / String) Integer : the 0 based index of the subtable to get.
- GetName()
Dim table As TableClass table = GetTable("MyTable") MessageBox(table.GetName())
This loads a TableClass from the table on disk with the filename of "MyTable.xml" and shows the name of the table in a messagebox.- No Parameters
- Returned Value (String) The name of this table.
- GetSubTables()
Dim table As TableClass Dim subTables As Dictionary table = New TableClass Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") table.AddSubTable(subTable) subTables = table.GetSubTables()
This creates a blank TableClass and adds a new sub table to it called "MySubTable". It then gets the sub tables out of the table.- No Parameters
- Returned Value (Dictionary) The sub tables from the Table as a Dictionary where the Keys are the subtable names and the Values are the actual subtables.
- NumSubTables()
Dim table As TableClass Dim num As Integer table = New TableClass Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") table.AddSubTable(subTable) num = table.NumSubTables()
This creates a blank TableClass and adds a new sub table to it called "MySubTable". It then gets the number of sub tables in the table which in this case would return 1.- No Parameters
- Returned Value (Integer) The number of sub tables in the table
- SetName()
Dim table As TableClass table = New TableClass table.SetName("MyTable")
This creates a blank TableClass and sets its name to "MyTable".- Parameter 1 - Table Name (String) The new name of the table. This is used when saving to know where to save the table to. Changing the name of a table does not rename the table's associated file so you should do a delete and then a setname on the table to change the actual file's name.
- No Return Value
- SetSubTables()
Dim table As TableClass Dim subTables As Dictionary table = New TableClass Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") subTables = New Dictionary subTables.SetValue("MySubTable", subTable) table.AddSubTables(subTables)
This creates a blank TableClass and a blank Sub Table. It puts the subtable in a dictionary where the key is the subtable name and the value is the subtable. It then sets the table's subtables to the dictionary of subtables.- Parameter 1 - Sub Tables (Dictionary) The sub tables to add to the table where the name of the subtables are the keys and the subtables are the values. This overwrites any subtables that may already be in the table.
- Returned Value (Dictionary) The sub tables from the Table as a Dictionary where the Keys are the subtable names and the Values are the actual subtables.
- Write()
Dim table As TableClass Dim num As Integer table = New TableClass table.SetName("MyTable") Dim subTable As SubTableClass subTable = New SubTableClass("MySubTable") table.AddSubTable(subTable) table.Write()
This creates a blank TableClass with the name "MyTable" and adds a new sub table to it called "MySubTable". It then writes the table to a file called "MyTable" in the user's TableData folder.- No Parameters
- No Return Value
Script Examples
These examples show different ways to use scripting to customize rolling and functionality. CBLite functions are clickable to go to that function to explain what it does.
- Reroll if result greater than 17
Dim num As Integer Dim total As Integer Dim rolls As String total = 0 rolls = "" Do num = RollDice("1d20") total = total + num If (Len(rolls) > 0) Then rolls = rolls + "," End If rolls = rolls + Str(num) Loop Until num < 18 ReturnValue(total) MessageBox(Str(total) + " is the total result of (" + rolls + ")")
This script rolls a 1d20. Every time the result is greater than or equal to 18, the result is added to the total and another 1d20 is rolled. The total of the rolls and the individual rolls are shown to the user in a MessageBox.