Stack methods

Edit

Introduction #

What’s a stack? #

Stack is a special variable which can hold more than one value at a time. It works similar to an array in other programming languages.
If you have a list of items (for example viewer names), storing them in single variables would look like this:

  • var name1 = “Lioran”
  • var name2 = “Neverwho”
  • var name3 = “Daryl”

This seems quite inefficient if you happen to have a lot of names to store. The answer is to store them all in a stack, which can hold many values under a single name and you can access them by referring to an index number: stack names = ["Lioran", "Neverwho", "Daryl"].\

Representation of an array
Representation of an array

Stack manipulation #

If you want to retrieve a specific value from a stack, you can use the following formatting: [position]stackname. Going by the example above, [2]names would retrieve 'Neverwho'. [position] can also contain other variables or complex math.
Stack values can be viewed by pressing Tab in the main Receiver menu and typing the full name of the stack.
In the TAB window you will see at the top of your screen the position 0, and at the bottom the last position. However, the TOP position of the stack is still the last one, and the BOTTOM position is 0. Be careful as this can be confusing at first.

Top and bottom of a stack shows different in screen
Top and bottom of a stack shows different in screen

One thing to note is that a stack is cleared every time you close or reset Receiver. If you wish to save it, you can use Stack: Stringify and File: Save String commands.


Edit

Stack: Add #

Adds a value to a given stack. Will create the stack if it doesn’t exist yet.

The position you’re adding the value to can be:

  • top - adds a value to the end of the stack (same as Array Push in Javascript)
Add a value to the end of the stack
Add a value to the end of the stack
  • bottom - adds a value to the beginning of the stack (same as Array Unshift in Javascript), the positions of all elements will shifted by one
Add a value to the beginning of the stack
Add a value to the beginning of the stack
  • index of the position to push the value to. The original values will be shifted by one from this position.
Box Name Type Description
Stack Name String Name of the stack
Position index/top/bottom Position to add the value to. Can be top , bottom or index of the position.
Var./real/”string” Variable, real or string Value you want to add to the stack


Edit

Stack: Replace #

Replaces a value inside a stack, overriding the previous one. Position remains the same.

Box Name Type Description
Stack Name String Name of the stack
Position index/top/bottom Position to replace the value at. Can be top , bottom or index of the position.
Var./real/”string” Variable, real or string Value you want to replace the current value with


Edit

Stack: Pull #

Pulls a value from a stack by deleting it from the stack and saving it inside the selected variable. All stack positions will be shifted by one.

Box Name Type Description
Stack Name String Name of the stack
Position index/top/bottom Position to pull the value from. Can be top , bottom or index of the position.
Variable String Variable name to save the pulled value to.


Edit

Stack: Peek #

Reads a value from the stack and saves it inside the selected variable. Unlike Stack: Pull command, Stack: Peek does not delete the value from the stack.

Box Name Type Description
Stack Name String Name of the stack
Position index/top/bottom Position to peek at. Can be top , bottom or index of the position.
Variable String Variable name to save the value to.


Edit

Stack: Find #

Finds the first instance of a given value inside the stack. Needs to be the exact value.
Return -1 if not found.

Box Name Type Description
Stack Name String Name of the stack to search for the value
Variable Name of the variable to save the position of the found value under  
Find Var./String/Real The value to find in the stack
Find Value Stack Result
“blue” [“yellow”,”red”,”blue”,”orange”,”blue”] 2
“blue” [“yellow”,”red”,”blue cat”,”orange”] -1 (not found)
“blue” [“yellow”,”Blue”,”blue cat”,”blue”] 3


Edit

Stack: Get Size #

Returns the size of the stack (= how many values it holds) and saves it into the given variable.

Box Name Type Description
Stack Name String Name of the stack
Variable String Variable name to save the size of the stack


Edit

Stack: Sort #

Sorts a stack alphabetically or numerically (depending on its values) in an ascending order.
If you have a mix of real and string values in your stack, it will sort it based on the first stack value.

Box Name Type Description
Stack Name String Name of the stack you want to sort


Edit

Stack: Random #

Returns a random value inside the stack.
Very useful for displaying a random image or playing a random sound.
The randomization will happen with an equal chance for each value.

Box Name Type Description
Stack Name String Name of the stack
Variable String Variable name to save the random value into
Variable (position) String (optional) You can enter another Variable name if you wish to get the position of the random value.


Edit

Stack: Shuffle #

Shuffles a stack, randomizing the order of every value in it.

Box Name Type Description
Stack Name String Name of the stack you want to shuffle


Edit

Stack: Concat #

Joins two stack together.
Appends another stack at the end of first stack.

Stack: Concat
Stack: Concat
Box Name Type Description
Stack Name The stack to append to. Will create one if it doesn’t exist.  
Stack Concat The stack to append at the end of the main stack  


Edit

Stack: Clear #

Deletes an entire stack.

Box Name Type Description
Stack Name String Name of the stack to delete


Edit

Stack: Stringify #

Returns a JSON string of the whole stack.
First value will be listed as “0”, second one as “1”, etc., “name” and “size” values will be also included.
Default JSON string format is {"size":3, "0":"white cat", "1":"blue car", "2":8}.
You can use this command together with File: Save String command to save the stack values into .ini file. Once loading it back from the .ini file, you can use Stack: Parse to turn the JSON string back into a stack.

Box Name Type Description
Stack Name String Name of the stack
Original Stack JSON string after conversion (notice the order is not consistent)
0: 5
1: 20
2: 100
{ “1”: 20.000000, “size”: 3.000000, “0”: 5.000000, “2”: 100.000000, “name”: “numbers” }
0: “Cat”
1: “Rabbit”
2: “Dog”
{ “1”: “Rabbit”, “size”: 3.000000, “0”: “Cat”, “2”: “Dog”, “name”: “animals” }
0: “Cat”
1: 50
2: “Rabbit”
3: 100
{ “1”: 50.000000, “3”: 100.000000, “size”: 4.000000, “0”: “Cat”, “2”: “Rabbit”, “name”: “mixed” }


Edit

Stack: Parse #

Turns a JSON string into a stack.
Default JSON string format is {"size":3, "0":"white cat", "1":"blue car", "2":8}.

Box Name Type Description
Stack Name String Name of the stack to save the parsed string into
String String Name of the string to parse.
JSON string before conversion New Stack
{ “1”: 20.000000, “size”: 3.000000, “0”: 5.000000, “2”: 100.000000, “name”: “numbers” } 0: 5
1: 20
2: 100
{ “1”: “Rabbit”, “size”: 3.000000, “0”: “Cat”, “2”: “Dog”, “name”: “animals” } 0: “Cat”
1: “Rabbit”
2: “Dog”
{ “1”: 50.000000, “3”: 100.000000, “size”: 4.000000, “0”: “Cat”, “2”: “Rabbit”, “name”: “mixed” } 0: “Cat”
1: 50
2: “Rabbit”
3: 100