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.