Tutorial Strings and Substrings

Discussion in 'Graveyard' started by tooltiperror, Nov 25, 2009.

  1. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    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.
    [​IMG]
    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, SubString(2,6) in GUI is SubString(1,5) 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.
     
  2. Azlier

    Azlier Old World Ghost

    Ratings:
    +461 / 0 / -0
    This doesn't cover SubString in Jass.

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

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    I don't know Substrings in JASS, I don't speak JASS very well.
     
  4. Jesus4Lyf

    Jesus4Lyf Good Idea™

    Ratings:
    +394 / 0 / -0
    What's the point of this? The world editor includes an example in GUI of how to use substring, with the "grunts stink" thing... ?
     
  5. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    Most people I talk to don't understand that. Grunts Stink = Run? People don't get it.
     
  6. Tru_Power22

    Tru_Power22 You can change this now in User CP.

    Ratings:
    +144 / 0 / -0
    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.
     
  7. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    Whoops, my mistake.

    Added that now.
     
  8. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    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.
     
  9. Nherwyziant

    Nherwyziant Be better than you were yesterday :D

    Ratings:
    +96 / 0 / -0
    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.
     
  10. Lyerae

    Lyerae I keep popping up on this site from time to time.

    Ratings:
    +105 / 0 / -0
    Needs a JASS version... :(
     
  11. Executor

    Executor I see you

    Ratings:
    +57 / 0 / -0
    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).
     
  12. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    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.
     
  13. Lyerae

    Lyerae I keep popping up on this site from time to time.

    Ratings:
    +105 / 0 / -0
    > And JASS version coming up.

    :D

    > substring management isn NOT really difficult.

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

    Executor I see you

    Ratings:
    +57 / 0 / -0
    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.
     
  15. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    Thanks, Executor, it`s good we`re getting along good.

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

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    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.
     
  17. Romek

    Romek Super Moderator Staff Member

    Ratings:
    +961 / 0 / -0
    > 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.
     

Share This Page