Skip to content

BBScript: BBScript 1: Variables & Logic

monopoisoner edited this page Jun 11, 2024 · 4 revisions

Variables & Logic

Variables can be created and assigned in BBScript, with their scope being limited to the post the script is defined in. Variables are expected to only contain alphabets (a-z or A-Z) or underscore (_) in their name, and are case-sensitive. BBScript has no dynamic variable naming, and expect all variables to be a literal without any starting/ending quotes. This means foo is the variable foo.

BBScript 1 has a unique resolution for undeclared variables, where if a literal being referenced is not an existing variable, it will be treated as string. For example, if foo is not yet defined, it will be treated as the string "foo".

To create a variable set operator is used. In the following snippet, the variable foo is assigned the value "bar".

set foo "bar"
print foo

At print, it will log the string "bar" into the console.


set Set

Sets a value to the variable name.

set varName value

varName : The name of the variable to set the value to or create. This should be single string or literal conforming to the restrictions of only alphabets or underscores (a-zA-Z_). : This can be a string or resolve to a string, but it is better for clarity to make this a literal.

value : The value to be assigned to the variable. This can be anything.


print

Prints the value of the arguments in the console. The console can be accessed by right clicking on the page, and clicking on the console tab.

print arg ...

arguments unlimited : The list of values to print to the console.


inc Increment

Increment the value of a variable by 1. Operation is done inplace.

inc varName

varName : The variable to increment the value of. The variable must refer to a number value.


dec Decrement

Decrement the value of a variable. Operation is done inplace.

dec varName

varName : The variable to increment the value of. The variable must refer to a number value.


if If

Performs a conditional check and executes the then or else block.

(if (conditional) (then) (else)

conditional : The conditional block to be tested. Should resolve to a boolean, but will use Javascript truthy-falsy values.

(then) : Sub-block to execute if conditional is true.

(else) : Sub-block to execute if conditional is false.

Return : This function can return the value of the then/else block depending on the conditional and will pass the value to the parent. By this way, if statements can be chained inside other functions.


stop Stop

Ends the execution of the script.

stop

eq Equal

Returns true or false if the first argument is loosely equal to the second argument.

eq val1 val2

arguments : The two values to compare against each other. Performs loose evaluation, i.e. number 1 is equal to string "1".

Return : Returns true or false based on conditional.


ge Greater Than

Returns true or false if the first argument is loosely greater than to the second argument.

ge val1 val2

arguments : The two values to compare against each other. Performs loose evaluation, i.e. number 2 is greater than string "1".

Return : Returns true or false based on conditional.


geq Greater Than or Equal to

Returns true or false if the first argument is loosely greater than or equal to the second argument.

geq val1 val2

arguments : The two values to compare against each other. Performs loose evaluation, i.e. number 1 is greater than or equal to string "1".

Return : Returns true or false based on conditional.


le Less Than

Returns true or false if the first argument is loosely less than to the second argument.

le val1 val2

arguments : The two values to compare against each other. Performs loose evaluation, i.e. number 2 is less than string "1".

Return : Returns true or false based on conditional.


leq Less Than or Equal to

Returns true or false if the first argument is loosely less than or equal to the second argument.

leq val1 val2

arguments : The two values to compare against each other. Performs loose evaluation, i.e. number 1 is less than or equal to string "1".

Return : Returns true or false based on conditional.


random Random

Generate a random integer.

random min max

min : The minimum value. Must resolve to a number.

max : The maximum value. Inclusive. Must resolve to a number.