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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      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