• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Tutorial about Strings

Status
Not open for further replies.
Level 12
Joined
Aug 20, 2007
Messages
866
I would greatly appreciate a short tutorial on how to use strings, not so much color codes (there are a billion ways to do color codes, even with pen + pencil)

But the way maps have

"-name HAHA I CAN CHANGE MY NAME BECAUSE I KNOW HOW!!!"

And the name changes

I tried to read their triggers, but I couldn't understand the context of it, I need definition of the terminology

I'm sure this will be helpful to many ppl (a small detail to add to your map to make it more fun and seem like your a pro)
 
Level 5
Joined
Dec 10, 2007
Messages
65
Strings Tutorial

Hey, I know alittle about triggers, so i should be able to help. Might not be too much of a tutorial, but il give it a shot.

first of all, you need a prompt for the user.

  • prompt
    • Events:
      • Time - Elapsed game time is 5 seconds
    • Conditions:
    • Actions:
      • Game - Display to (All players) the text: Type "-name " + what you would like to change your name to.
This just tells the user how to use the name changer.

Next thing to do is to store some variables of type STRING, now you could use an STRING ARRAY to hold all the names of each player. Depending on the max players in your map, you would set the string variable to that number, lets say for our case we have 8 players in our map.

So, click on the X variables and add a new variable Called NameStore and pick the variable type of STRING. Select the Array checkbox and make it size 8.

We also need a variable to store the size of the string that the user enters into the name changer, so make a variable called NameStore and pick type Integer and select Array size 8.

Now we got the prompt and a variable to store the names, now all we do is create the name changer trigger. I will first write the entire code, then explain what each part does afterwards. This is for the example for just player 1 (red), you could just copy and paste for each player and change the nessesary parts to it or you can get tricky and use for loops ect, but for this tutorial i will only do it for player 1:

  • nameChanger
    • Events:
      • Player 1 (Red) types a chat message containing -name as A substring
    • Conditions:
    • Actions:
      • Set NameSize[1] = (Length of (Entered chat string))
      • Set NameStore[1] = (Entered chat string)
      • Set NameStore[1] = (Substring(NameStore[1],7,NameSize[1]))
      • Player - Set name of Player 1 (Red) to NameStore[1]
So for our event, player 1 types "-name ........." , so this ignores the rest of the text of what the player typed and fires this trigger. This is called a substring of a String, its just a small piece of the String that was typed.

Our actions were to get the Length of the string typed. This just returns a integer value of how many characters (including spaces) in the chat message typed. The nameStore just stores the whole string, then we use nameStore again to get the substring that we want, in our case the stuff after "-name ". To do this, we just use substring(STRING,startingCharNumber,SizeOfString).
In our case "-name " takes up 6 chars (including the last space too). So we use 7 for the startingCharNumber then just put in our variable for the size of string.

Now we have our string all we need to do is set the players name to that string.

Its as simple as that, hope this helps understanding strings. If you have any more questions just post it up and il try to answer it. :wthumbsup:
 
Level 12
Joined
Aug 20, 2007
Messages
866
hah

Thank you for the tutorial :thumbs_up:

But, I didn't need that, I wouldn't consider myself completely new though

All I really needed to know was what the

  • Set NameStore[1] = (Substring(NameStore[1],7,NameSize[1]))
Part ment

What the 7 means is really what I need to know
___________________________________________

Nope, just got it

The seven is where the string you would like to change to starts, and the size is where it ends

Thanks man I got it now :wgrin:
 
Level 12
Joined
Aug 20, 2007
Messages
866
Oh

Yeah, I kinda just skipped your whole tutorial

No offense or nothin, all I wanted was the example at the bottom

So I could see the context n decipher it myself

+rep
 
Status
Not open for further replies.
Top