Tutorial 4: Manipulating elements in a string (Introduction)
Now that we went through a simple set of triggers to give share to a list of players, it's probably a good time to mention that these triggers don't actually account for three other scenarios:
- Adding a new player to the share list
- Removing a player from the share list
- Moving a player from the automatic share list and into another list
All of these things require you to edit the contents of the ~ShareList string. Certain DS lines let us temporarily manipulate the string in the Dream itself, meaning we don't have to reupload the Dream every time we wanted to edit it (though you would need to edit your DS later if you want to keep this information in the string for the next upload the Dream). The following will cover how to edit and manipulate elements in a string!
Adding a new element to the string
Let's look at the first scenario first, which is adding a new player to the automatic share list. We can do by using the following trigger to alter the contents of the ~ShareList string:
(0:32) When someone says something with {@AddShare } in it,
(5:257) take message ~ShareList and add { [PARAM1] } onto the end of it.
So when a player says ‘@AddShare ‘ followed by a target player’s name, it will be appended to the end of the string. For example, if we said ‘@AddShare Joey|FoxyPaws’, this is what the string would then look like: { Example|Furre1 Example|Furre2 Example|Furre3 Joey|FoxyPaws }.
Tip: Don't forget that when using strings to handle the names of players, replace any spaces in their names with the pipe (|) character.
Removing an existing element from the string
Now for removing a player from the share list!
(0:32) When someone says something with {@DisableShare } in it,
(5:278) remove the first 1 copies of { [PARAM1] } from message ~ShareList.
So when a player says ‘@DisableShare ‘ followed by a target player’s name, it will be removed from the ~ShareList string (if it exists). For example, if we were to say ‘@RemoveShare Joe|FoxyPaws’, this is what the string would then look like: { Example|Furre1 Example|Furre2 Example|Furre3 }.
Moving an existing element in one string to another string
Moving something from one string to another is more of a two step process in DS. First you have to remove that element from the first string, then you add it somewhere else. Now, how can we go about extracting a player from the share list string in order to place them into a different string? This trigger will be similar to the one we used to give share, except with a different string being used as a list.
(0:32) When someone says something with {@ShareRemove } in it,
(1:75) and message ~ShareList contains { [PARAM1] } somewhere within it,
(5:278) remove the first 1 copies of { [PARAM1] } from message ~ShareList.
(5:257) take message ~RemovedShare and add {[PARAM1] } onto the end of it.
So when a player says ‘@RemoveShare ‘ followed by a target player’s name, and that player’s name is already in the ~ShareList string, it will be removed from the string. Then it adds the name of the player we just removed from the automatic share list, and puts it into the list that the owner could potentially check by using a command.
Unlike in the ‘@AddShare ‘ trigger, instead we are adding a player’s name to the ~RemovedShare string without a space at the beginning. Why? Well, a space is already present within said string, and any new names introduced into it will have a space at the end. This way, we can separate each player’s name neatly within the string.
So, when a player says ‘@RemoveShare ‘ followed by a target player’s name, that name will be added at the end of the ~RemovedShare string. For example, if we were to use ‘@RemoveShare Joey|FoxyPaws’, our string would look like: { Joe|FoxyPaws }, while the contents of the ~ShareList string will look like this: { Example|Furre1 Example|Furre2 Example|Furre3 }.
Here's the full set of triggers that were explained throughout this section of the tutorial:
(0:0) When everything is starting up,
(5:250) set message ~ShareList to { }.
(5:250) set message ~RemovedShare to { }.
(0:9) When someone arrives in the Dream,
(1:75) and message ~ShareList contains { [FURRE] } somewhere within it,
(5:102) share Dream control with the triggering furre.
(0:32) When someone says something with {@AddShare } in it,
(5:257) take message ~ShareList and add { [PARAM1] } onto the end of it.
(0:32) When someone says something with {@ShareRemove } in it,
(1:75) and message ~ShareList contains { [PARAM1] } somewhere within it,
(5:278) remove the first 1 copies of {[PARAM1] } from message ~ShareList.
(5:257) take message ~RemovedShare and add {[PARAM1] } onto the end of it.
(0:31) When someone says {@UnsharedList},
(5:200) emit message {The follow people were removed from autoshare: ~RemovedShare} to the triggering furre.
Share this:
-
-
-