tooltiperror
Super Moderator
- Reaction score
- 231
So you created a thread asking for a '-name' system, or maybe you want to create text next to a unit whenever they speak. Someone linked this to you, or maybe your just browsing the lair known as Tutorials and Resources. Well, here's the right place. In this tutorial you will learn;
I. Uses of Strings
II. Uses of Substrings
III. How to use Substrings
IV. '-name'
I. Uses of Strings
II. Uses of Substrings
III. How to use Substrings
IV. '-name'
I. Uses of Strings
In my opinion, the use of strings is by far the most interesting and clever and most interactive way to let players manipulate and use the game. Anything, '-ar' and '-apen' to '-name' are all examples of using strings. Even when you type a simple message to a friend, you are using strings to communicate and send a message. Strings could be used for more advanced things, like tax and such. In games like SotDRP, a popular battle.net role playing game, the entire game is operated through commands like 'size ###' and 'tint ###' to mod the units in the game.
II. Uses of Substrings
Let's face it. Without substrings, I don't think any String Related systems and snippets would be possible. Substrings allow us to look at specific things in the string, instead of the whole thing. When using '-name', we use substrings to only look at what comes after the '-name' instead of setting the players name to '-name Jimmy'. In '-apem' we make sure that the string begins with '-apem' instead of the host saying "No -Apem'. Without substrings, the host could accidently trigger a mode, or someone would have a stupid name. I mean, who wants to be named '-name Jimmy'?
III. How to use Substrings
Substrings may seem confusing at first. For a long time, I did not know how to use Substrings, and I was afraid to ask for help. Being such a big helper, I did not want to look stupid. SELF REVELATION FOR THE WIN. But, anyway, after a bit, I learned to use them from testing and learning. Now, look, this is how substrings work.
In this example, 'Substring (2,5)' is 'RUNT'. How do I find this? Look at the small (red) numbers before each letter or symbol. That is the letter's substring integer, a phrase I will use in this tutorial. Now, the substring's integers are the '2,5' in the string. '2' is the starting point, and '5' is the last letter in the integer. This goes for anything. To see if you understand it, answer this question. When you think you know what it is, click the spoiler.
Q: What is 'Substring 4,6' in 'Thanksgiving Turkey'?
A: 'nks'
Substrings in JASS.
If you want to find Substrings in JASS, they are almost the same. The thing is, in JASS, the first character is 0. See, the thing is, in GUI, it is made to be easy for people to understand without learning a language. So, 1 seams like a better place to start than 0. But, in JASS, there is no reason to make it really easy, so it starts at 0. So, just find the regular string numbers, and subtract one. So, [ljass]SubString(2,6)[/ljass] in GUI is [ljass]SubString(1,5)[/ljass] in JASS.
Code:
G R U N T ' S
0 1 2 3 4 5 6 7
IV. '-name'
Most tutorials using '-name' do not explain how they work, they only give you the trigger and hope that you know what it means. Here, I will be explaining explicitly how to use it. You will use a substring to find the '-name ', then you will use a substring to find the new name.
Trigger:
- Set Name
- Events
- Player - Player 1 (Red) types a chat message containing -name as a substring
- Conditions
- (Substring((Entered chat string), 1, 6)) Equal to -name
- Actions
- Player - Set name of (Triggering player) to (Substring((Entered chat string), 7, 19))
- Events
Now let's break this down.
Trigger:
- Player - Player 1 (Red) types a chat message containing -name as a substring
Trigger:
- (Substring((Entered chat string), 1, 6)) Equal to -name
Trigger:
- Player - Set name of (Triggering player) to (Substring((Entered chat string), 7, 19))
Here is the final trigger.
Trigger:
- Set Name
- Events
- Player - Player 1 (Red) types a chat message containing -name as a substring
- Player - Player 2 (Blue) types a chat message containing -name as a substring
- Player - Player 3 (Teal) types a chat message containing -name as a substring
- Player - Player 4 (Purple) types a chat message containing -name as a substring
- Player - Player 5 (Yellow) types a chat message containing -name as a substring
- Player - Player 6 (Orange) types a chat message containing -name as a substring
- Player - Player 7 (Green) types a chat message containing -name as a substring
- Player - Player 8 (Pink) types a chat message containing -name as a substring
- Player - Player 9 (Gray) types a chat message containing -name as a substring
- Player - Player 10 (Light Blue) types a chat message containing -name as a substring
- Player - Player 11 (Dark Green) types a chat message containing -name as a substring
- Player - Player 12 (Brown) types a chat message containing -name as a substring
- Conditions
- (Substring((Entered chat string), 1, 6)) Equal to -name
- Actions
- Player - Set name of (Triggering player) to (Substring((Entered chat string), 7, 19))
- Events
Other Useful Links:
PS: Lime Text.
I'll be adding more to this as more things that have to do with strings are developed or I have other things to add. I'll also be finishing the over-string thing once I get my WC3 Editor back, so when 12.4c goes public.