• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Trigger] Substring issue

Status
Not open for further replies.
Level 9
Joined
Dec 31, 2016
Messages
320
  • DestroyBases
    • Events
      • Player - Player 2 (Blue) types a chat message containing -Destroy as A substring
    • Conditions
    • Actions
      • Set ChatString = (Entered chat string)
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • Unit - Kill Castle[(Integer((Substring(ChatString, (9 + (Integer A)), (9 + (Integer A))))))]
This trigger should kill the castle as its number is written by a player. For example you can type "-destroy 1234" or "24" and the appropriate castle will be destroyed. The thing is, it works only for the first number you type. Castle variable is set properly and the loop also worked fine when I change the action to something else. So I've run out of ideas of what is causing that issue.
 
Level 13
Joined
Jul 15, 2007
Messages
763
If you type -destroy 1234 then the first loop will return 1, the second loop will return 2, the third 3 and the fourth 4. If your castle variables are 4 numbers long as you say, this is why nothing is happening.

The sub-string you are interested in from positions 9 to 12 (1-8 are taken up by "-destroy ". Using a loop is inappropriate, all you need to do is kill Castle[(Integer((Substring(ChatString, 9, 12))))]
 
Status
Not open for further replies.
Top