• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

String events

Level 4
Joined
May 12, 2022
Messages
22
Hello, I've been looking through the forums and tutorials for this but I can't find the answer anywhere.

Something like this is what I would like to be able to use together with other substring events:
  • Income timer Setup
    • Events
      • Player - Player 1 (Red) types a chat message containing -it as A substring
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Real((Substring((Entered chat string), 4, 5)))) Greater than or equal to 1.00
          • (Real((Substring((Entered chat string), 4, 5)))) Less than or equal to 30.00
    • Actions
      • Set VariableSet RealIncomeString = (Real((Substring((Entered chat string), 4, 5))))
      • Game - Display to (All players) the text: (|cFFE0B42FIncome time frequency is set to |r + (Substring((Entered chat string), 4, 5)))
Example: -abc-it10-def..
-abc-def-it10

How can you get the value 10 from the example I give above? This trigger won't work as it can only take the input from the 4th and 5th chat string. But I want it to work even if you randomise the order in which you type the substrings.

I am guessing it can't be done in GUI only but just to make sure I wanted to ask.

Thank you!
 
Level 39
Joined
Feb 27, 2007
Messages
5,034
You need to find the substring -it within the entered chat string, then look at the next characters after it to find the value. You would use a loop to check every possible substring of the chat until you find it.

If you are expecting the player to input many different options with these chat commands, it’s probably worth it to parse the entire input string for all instances of - (effectively your delimiter here) and put the various commands into two parallel string arrays. Then check the array values to see what commands were input.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,204
The short answer is that you will need to write a parser to process the chat string.

Similar to how Linux Bash programs parse command line arguments, you break the input down into single commands/flags that you store in a list. You then iteratively process the list. To make things easier I would recommend putting a delimiter between each command/flag. The - seems to be a suitable such character in your example.

To write such a thing you loop through the string character by character using substring until you find the "-" character. You can then substring between the two "-" characters to get a command/flag and appended it to the list. The list would be a simple array list backed by a string array.

As such your example input of "-abc-def-it10" would be parsed into an array containing 3 strings, each representing a command.
Code:
result[0] = "abc"
result[1] = "def"
result[2] = "it10"
You then use a case loop to lookup the appropriate command logic and process it, looping for every command that was detected. This would even support silly cases such as "-it10-it11-it9" correctly since it will loop 3 times and the final time will likely override the previous settings.
 
Top