Tutorial 2: Adding text/strings onto the end of (another) string
In DS, there are currently two lines that let us to add text onto the end of a string. These lines are very useful for dynamically generating lists (and some main maps even use this for minigames to keep track of players), adding to a dynamic string database, or even stitching multiple strings together for one simple output.
To illustrate the first form of this concept, let us imagine that we currently have a string called ~ShoppingList with the text ‘Eggs, Milk, Bread’ inside of it. If we wished to add more items to the list, we can use (5:257):
(0:31) When someone says {Add Potatoes},
(5:257) take message ~ShoppingList and add {, Potatoes} onto the end of it.
When someone says the command Add Potatoes, the ~ShoppingList variable will receive the text ‘, Potatoes’, and then it will be added directly at the end of it.
Now this is really useful by itself, we could add different commands to add more items to our shopping list. But what if we had a second list, contained within a string called ~2ndShoppingList with the text ‘Potatoes, Pumpkins, Carrots’ inside of it, and we wished to combine both of our lists into one? This is where (5:258) comes in:
(0:31) When someone says {Combine Lists},
(5:258) take message ~ShoppingList and add message ~2ndShoppingList onto the end of it.
If someone says the Combine Lists command, the ~ShoppingList variable will receive the text ‘Potatoes, Pumpkins, Carrots’ that was inside of the string called ~2ndShoppingList, illustrating one of the two potential ways to combine messages together.
However, because the string called ~2ndShoppingList is only being added at the end of ~ShoppingList, the contents of ~ShoppingList will look like this: {Eggs, Milk, BreadPotatoes, Pumpkins, Carrots}
Thus it is important to keep text formatting in mind when combining two strings together through the use of the (5:258) line.
Finally, there is also a third method to add the contents of a string onto the end of another string like so:
(0:31) When someone says {Combine Lists},
(5:257) take message ~ShoppingList and add {, ~2ndShoppingList} onto the end of it.
You may have noticed the inclusion of a ‘ ,’ at the beginning in the (5:257) line, and this is intentional in order to separate the contents of the string called ~2ndShoppingList from the original contents of the string called ~ShoppingList. Altogether it will look like this: {Eggs, Milk, Bread, Potatoes, Pumpkins, Carrots}.
By using (5:257) to add a string onto the end of another, we have great flexibility and control over the formatting of the text.
Tip: adding text or a string to an empty string (a string with no text) will cause this placeholder text to be added: Dr. Cat says: Live in your hopes, not in your fears. So now you know what that message means if you ever see it anywhere! An easy way to avoid this is to make sure that any strings have at least one character of text in them, like a space: { }.
(0:0) When everything is starting up,
(5:250) set message ~ShoppingList to { }.
Share this:
-
-
-