[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