Welcome to another guide! This one I made because in all the guides about beginner coding, (and advanced), there hasn’t been a lot of talk about text blocks, and I’m not talking length of and the normal set texts, I’m talking about first occurrences and sub-strings. But, for the sake of the guide, I’ll include all the blocks. We can break this down into 2 different sections, the Beginner and Advanced. We’ll start with the beginning first.
Wiki editing rules
Please don’t make any of the edits violate the TOS or FAQ, remember, anyone can see who edits a wiki and what part they edit.
Please be responsible!
Everyone, please don’t edit when it is being edited.
Ask before editing and tell me what you’re going to add.
Add yourself to the credits if you edited it and added something.
Don’t make credits using @ since you can only do that 10 times in a post.
Table of Contents
- Set Text
- Create Text
- Length Of
- Convert Numbers To Text
- Get Sub-string letter# to letter#
- Get letter#
- Find first occurrence
Set Text
This is the most common block used, obviously, I won’t have to explain much because even beginner coders can catch up pretty quickly on this. Usually, without using the block itself, (i.e. the text that is offered by notifications and pop-ups), text appears a lot, but the times where the block is used, is probably used when you concatenate strings, or in actually form, use Template Literals, which I actually explained before. Text blocks can be a value for properties also! They can also be manipulated, as explained in the other text blocks.
Create Text
A still very common block, create Text can conjoin multiple pieces blocks to make a whole string. An interesting thing about this is numbers, now, if you’ve used blocks before, you know it’s possible to convert numbers to strings (with commas), and text can do that! However, there appears to be certain restrictions. When you try broadcasting using numbers, say, the property of something is set to a number, 1234, and you want to broadcast on a concatenated string 1234h, well, I tried this out and it didn’t work, meaning that when broadcasting, it can’t convert numbers to string automatically, the best way to do this might be using the converted text to numbers (using commas), but if it’s a normal concatenation, like:
set text: item 1: get property propertyName
item 2: set text: "Whatever you wish!"
It works!
Length Of
Pretty self-explanatory, right? The length of the block basically gives you the length of a string, and I did a test, it’s not 0-based, meaning it starts at index 1, I can’t fully remember which data types start at index 1, pretty sure though arrays and objects are 0-based.
Convert Numbers To Text
Now, this one is pretty simple, but small warning, remember the Create Text section?
Just to be sure, when I mean (using commas) I don’t mean putting a comma after every number, I mean adding the comma at every 3 digits. For example, 1234, use the converter and you get 1,234. So you would also need to be wary to add the commas when needed in your broadcasts.
That pretty much sums it all up.
Now we’re moving on to advanced! These blocks are not as used and have more specific
Get Sub-string letter# to letter#
This part of it cuts out pieces of text from the string. For example.
string: "This is an example";
sub-string: letter6 to letter18
You would get “is an example”. Now, to let you know, the letter6, it includes the letter, and not the next one. To explain, the 6th letter is “I”, so it includes it, not go to the next letter, which is “s”.
Get Letter#
For this, it works virtually the same as the letter# to letter# except for one thing, it instead gets you the letter index. For example, using our example above, lets pick letter2, well, we would get “h” if we wired this to a notification or pop-up. I’m not entirely sure why it wasn’t made to go all the way to the end of the string, but maybe it was so that you could get more specific letters to build together with. (reminds me of when your typing on your phone and some words appears that match what you’ve began typing for some reason).
Find First Occurrence
And, now, the most important for last, and the reason I made this Guide, the occurrence block. Now, what this does is that it finds the occurrence, like the find button shortcut. Now, this isn’t all it does, and there’s a secret thing that people might not know about if you don’t experiment, it also tracks the number of occurrences, even before the thing is triggered. Now, I discovered this during my Battleship game, the goal for the occurrence was to identify if an updated property had the word “Enemy”. I triggered 3 “Enemy” buttons that updated the property, and then ran the trigger, getting a notification of ‘3’, the same amount of triggers I triggered with “Enemy” in it. What I assume is that the updated properties are stored somewhere and that the occurrence block goes through those updates, and while it does activate since the property already has “Enemy” in it, it also stores the total amount of times “Enemy” was stored. Just saying, I would suggest asking Blockhole to explain more about this part, since they literally are [1] the best coders in the forums, (that might be Clic-Clac though), they could help clear this part out.
And that’s it! While the most important part was the occurrence part of it, I did want to explain all the text blocks, so that I could explain it to them. Hope this helps, signing off, Friends of Berk!
Lemme know if I missed anything, or have a suggestion on what to add!
Credits
Toothless
(Hopefully others soon!)