• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] How to detect String?

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
Hello guys I need some help in GUI with detecting script anywhere in a chat message.

let's say I type the sentence "This is a test string"

If I want to detect the word "test" I use this:
  • (Substring((Entered chat string), 11, 14)) Equal to test
then this action is successful BUT what If I want to detect it anywhere on a chat?

example:
I have the sentence "This test is a string"

In this case the above trigger will not work, I tried finding a solution to this under
"Conditions - String Comparison" but no luck there...


so does anybody know if it's possible to detect strings anywhere on a chat message??
 
It's also possible in GUI. Check out the attached demo.

  • String Find
    • Events
    • Conditions
    • Actions
      • Set STRF_Text_Position = -1
      • Set STRF_Length_Read = (Length of STRF_Text_ToRead)
      • Set STRF_Length_Find = (Length of STRF_Text_ToFind)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • STRF_CaseSensitive Equal to False
        • Then - Actions
          • Set STRF_Text_ToFind = (String(STRF_Text_ToFind) as Lower case)
        • Else - Actions
      • For each (Integer STRF_i) from 1 to STRF_Length_Read, do (Actions)
        • Loop - Actions
          • Set STRF_Substring = (Substring(STRF_Text_ToRead, STRF_i, (STRF_i + (STRF_Length_Find - 1))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • STRF_CaseSensitive Equal to False
            • Then - Actions
              • Set STRF_Substring = (String(STRF_Substring) as Lower case)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • STRF_Substring Equal to STRF_Text_ToFind
            • Then - Actions
              • Set STRF_Text_Position = STRF_i
              • Set STRF_i = (STRF_Length_Read + 1)
            • Else - Actions
  • Demo
    • Events
      • Player - Player 1 (Red) types a chat message containing <Empty String> as A substring
    • Conditions
    • Actions
      • Set SomeText = (Entered chat string)
      • -------- Setup variables and run find trigger --------
      • Set STRF_Text_ToFind = test
      • Set STRF_Text_ToRead = SomeText
      • Set STRF_CaseSensitive = True
      • Trigger - Run String Find <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • STRF_Text_Position Not equal to -1
        • Then - Actions
          • Game - Display to (All players) the text: (Found at position: + (String(STRF_Text_Position)))
        • Else - Actions
          • Game - Display to (All players) the text: Text was not found
You can set the both string variables:
  • Text_ToRead
  • Text_ToFind
and define if you want it to have case sensitive, or not:
  • CaseSensitive
(not case sensitive will not care if written in upper or lower case)
And then run the StringFind trigger. After running you can compare the "Text_Position" integer:
  • If "Text_Position" equals -1 means text was not found
  • .. else it does tell you the position where the string was found
In the demo it will watch what Player 1 writes and will search for "test" string and case sensitive.

How To Import A Spell/System
 

Attachments

  • StringFind.w3x
    13.7 KB · Views: 18
Status
Not open for further replies.
Top