Tutorial Strings and Substrings

tooltiperror

Super Moderator
Reaction score
233
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.
 
This doesn't cover SubString in Jass.

Code:
 G R U N T ' S
0 1 2 3 4 5 6 7
 
I don't know Substrings in JASS, I don't speak JASS very well.
 
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.
 
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.
 
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.
 
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.
 
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).
 
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.
 
> And JASS version coming up.

:D

> substring management isn NOT really difficult.

Hah, I can't figure it out on my own.
 
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.
 
Thanks, Executor, it`s good we`re getting along good.

Also, I plan to ask some cool kids for help when I have time.
 
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.
 
> 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.
  • Varine Varine:
    A probate is usually done with a will, yes? If so I am sorry for your loss
    +1
  • The Helper The Helper:
    Yeah Tom, me too sorry for your loss buddy my mom told me she finds out her olds friend died from Google searching them. She had not talked to one of her old friends in a year and found out she died from Google. Also another one in the same session. RIP all of them my sincere condolences Tom
    +1
  • Varine Varine:
    We have some elderly guests that regularly come hang out at the bar at the end of the night, and every once in a while we don't see someone for a few weeks and then someone shows up with their obituary.
  • Varine Varine:
    We usually let them do their memorials there in the morning if they want to and I'll make them some snacks and drinks. There was one guy named Tom that came in like every night and would sit by himself and get a bunch of soup and a glass of wine. idk why but he LOVED our fucking soup, like he would order a fucking quart of it at a time and would always get so sad when we stop doing it for the summer.
    +1
  • Varine Varine:
    But he also loved our calamari, which is another thing I hate but it sells super well so I can't change it. There was one day he came in and was asking me how to make it, because he tried to at home once in the off season when we stop running it and he really wanted it lol
  • Varine Varine:
    I think he's one of the only people I've made recipes for for free because he really wanted a broccoli cheddar, and it was like dude I don't have a recipe, it's just whatever I have, but here, this is how you do it
  • Varine Varine:
    I don't think he ever figured out how to do the calamari in a pan though, like idk how to do that either. He was afraid of the at home deep fryers though and it's like yeah, that's fair, I am too
  • Varine Varine:
    He was just such a sweet old man, we had two servers pregnant and they held a baby shower together, he was soooooo fucking excited to get to see a baby. Unfortunately he died a month or so before they were born
  • The Helper The Helper:
    So I decided to Google some people that I had not seen or heard from in a while and sure enough one of my old best friends, we had a falling out years ago but whatever, find out he died of Pancreatic Cancer in January. I have also lost a few of my closer acquaintances from growing up the last year. Getting old - people die - I kinda thought it was going to be this way a few years ago....
    +2
  • The Helper The Helper:
    Forum running super slow again
  • Ghan Ghan:
    Not really clear from the stats as to what is causing the slowness.
  • Ghan Ghan:
    We get a lot of guest traffic so it may just be the load is getting too high and not from any particular source.
  • Ghan Ghan:
    Looks like the server is maxed out on CPU.
  • Ghan Ghan:
    Oh it looks like a lot of the traffic is Silkroad Forums. That domain isn't protected by Cloudflare.
  • Ghan Ghan:
    But the old Silkroad site is still on its own server. I just had a test site set up on this server for it.
  • Ghan Ghan:
    I just disabled that test site. Let's see if that helps the load.
  • Ghan Ghan:
    Looks much better already.
  • The Helper The Helper:
    I had actually forgot about the Silkroad site. I had asked
  • The Helper The Helper:
    SD Ryoko about it and he said the couple of people left on there really like it, that was a few years ago, maybe I should check back
  • jonas jonas:
    I guess when you're getting old, and the last day of soup season draws near, you start wondering
  • jonas jonas:
    will I make it to the start of the next season? or was this the last time I'll ever have my favorite dish?
  • The Helper The Helper:
    I am doing my first Vibe Coding project. In installed the environment and tools according to instructions but it is all chat doing this for me at my direction. It is fun really and holy shit I might finish in 2 hours what it would have taken a day to in my Access and this would be an electron app complete new
  • Ghan Ghan:
    Good stuff.
  • Ghan Ghan:
    Just make sure it is secure. :)
  • The Helper The Helper:
    It will only be on internal network

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials
      Top