Tutorial Strings and Substrings

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

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.
2cz9h4w.png

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))


Now let's break this down.
Trigger:
  • Player - Player 1 (Red) types a chat message containing -name as a substring
This event means that Player 1 types a message with '-name' in it. Notice 'as a substring', this is needed for the trigger to work, without it the trigger will glitch.

Trigger:
  • (Substring((Entered chat string), 1, 6)) Equal to -name
This condition makes it so that the first six letters are '-name ' with a space at the end.

Trigger:
  • Player - Set name of (Triggering player) to (Substring((Entered chat string), 7, 19))
This sets the name of the triggering player to whatever follows the space in '-name '; with a maximum length of 12 Characters.

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))




Other Useful Links:
  • Hiding Chat Messages [link]
  • emjlr3 Leak Prevention Tutorial [link]
  • Color Code Tutorial [link]

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.
 

Azlier

Old World Ghost
Reaction score
461
This doesn't cover SubString in Jass.

Code:
 G R U N T ' S
0 1 2 3 4 5 6 7
 

tooltiperror

Super Moderator
Reaction score
231
I don't know Substrings in JASS, I don't speak JASS very well.
 

tooltiperror

Super Moderator
Reaction score
231
What's the point of this? The world editor includes an example in GUI of how to use substring, with the "grunts stink" thing... ?

Most people I talk to don't understand that. Grunts Stink = Run? People don't get it.
 

Tru_Power22

You can change this now in User CP.
Reaction score
144
Trigger:
  • Set Name
    • Events
      • Player - Player 1 (Red) types a chat message containing -name as An exact match
    • Conditions
      • (Substring((Entered chat string), 1, 6)) Equal to -name
    • Actions
      • Player - Set name of (Triggering player) to (Substring((Entered chat string), 7, 19))


That wont fire because it can't exactly match "-name", and contain the rest of the name as A substring :D.

You should use this:

Trigger:
  • Player - Player 1 (Red) types a chat message containing -name as a substing.
 

tooltiperror

Super Moderator
Reaction score
231
Thought I`d bump this, I fixed some stuff and added some clarifications and such.

If I need to add JASS to get this approved, I`d be glad to.
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
I study this substring and strings by my own, cuz there was not a tutorial like these at old days. weeeee! lol, nice tutorial too.
 

Executor

I see you
Reaction score
57
Hm, imo this tutorial is unnecessary, because string and substring management isn NOT really difficult.
But if some really want this, you should add string and substring management in JASS.

And btw. if you base a map on many string commands, the game becomes harder to learn (even when you show all commands, dialogs are always more noob-friendly).
 

tooltiperror

Super Moderator
Reaction score
231
Executor, SotDRP is a successful WC3 Map, and it is made by mainly string commands, so that point is invalid.

And JASS version coming up.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
> And JASS version coming up.

:D

> substring management isn NOT really difficult.

Hah, I can't figure it out on my own.
 

Executor

I see you
Reaction score
57
I didn't say that maps with a chat command interface would be unsucessful.
I said they are less noob-friendly, because beginners have to know and understand these commands/ this command syntax, instead of simply clicking around with the mouse. Nevertheless this is just a hint for those who play with the thought of creating such a map.

"And JASS version coming up."
Good luck.
 

tooltiperror

Super Moderator
Reaction score
231
Thanks, Executor, it`s good we`re getting along good.

Also, I plan to ask some cool kids for help when I have time.
 

tooltiperror

Super Moderator
Reaction score
231
Buump!

Moderators, what does this need to be approved? If it is really to basic to get approved/not a good topic, you can GY it.
 

Romek

Super Moderator
Reaction score
963
> Moderators, what does this need to be approved?
Preferably, you finish it. With all those extras you 'want to add', including JASS Substrings.
It's such a specific topic, I'm sure you could cover it completely, in detail.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top