Why have different types? #
In order for Stream Hydra to provide vast customisation in each node, the data returned by triggers and actions will fall into a few different data categories. These categories tell the code how to read each item and prevents any downstream nodes from trying to read/manipulate data inaccurately and causing errors in your applets. To understand what these data types are, and how to use them, we’ll explore each one in this article which will hopefully give you the tools to build powerful applets for your channel.
Data Types #
String #
Put simply, strings are text, that’s it. It’s a term used in programming which we’ve carried over to Stream Hydra, but in essence, nodes will just read the text or pass it along to the next node to be used elsewhere. An example for a string would be the “title” element in the “Twitch – On Channel Update” node.
Boolean #
Again, this is another fancy programming term for a data type that can only be “True” or “False. This gets used in various places across nodes that have toggles or switches, or get returned in some events like “Twitch – On Ban” with “is_permanent”.
Number #
No points for guessing this one! This allows nodes to manipulate or calculate certain parameters based on this value that otherwise wouldn’t be possible with just a string. For example, if you use the “Core – Comparison” node to see if value A is greater than value B, the code wouldn’t understand value A or B if any of them are strings, since it’s just text. However if they are both numbers, say 5 and 10, the comparison node can determine that 10 is greater than 5 and can output true or false accordingly. This also proves useful when performing any maths to this data. If value A is 5, but in the form of a string, and you try to add 1 to it the applet will error because you can’t do maths on text. However if value A is 5 as a number, then the code will understand this and allow you to perform whatever number manipulation you wish.
Object #
This is where data types can start to get complicated. An object is simply a group of values, in which said values can be strings, booleans, numbers, arrays (which we’ll get to) or indeed other objects. These values are stored as Key-Value pairs, meaning each value has a name attached to it so you can reference it later. Objects allow you to predefine what values you are expecting which makes data sharing a lot more reliable. This becomes especially useful when using some action nodes that perform certain functions on 3rd party platforms which require data in a specific format and if this format is not adhered to, will error and break your applet. Objects also help group values when these groups are used in arrays; we’ll cover this below.
Arrays #
Arrays are simply lists of items. These values in these lists can be anything mentioned above including other arrays. More complicated nodes that require arrays of objects can become very tricky to deal with especially if you are not manually adding the values in and instead, pulling that data from other nodes. So what can you do with arrays? Well, you can use the “Core – Array Length” node to get the number of items in the array. You can also loop through each item in the array to perform any action you’d like using the “Core – For Loop”. This returns an index for each item, starting at 0 which you can use to extract the specific item in another node. For example, if you had an array called {my_array} with 3 strings in it, and you wanted to use the first string, you can pluck that value by writing {my_array[0]}. The index is placed inside the square brackets and this will pull the correct value at that position. It’s worth noting that you don’t have to use the For Loop node to get the index, if you already know the position of the value you can type in that index and the value will be extracted.