[Solved] Substring Integer Comparison

Status
Not open for further replies.
Level 5
Joined
Dec 30, 2022
Messages
36
Hello!

I have the below trigger with conditions that the substring has to be between 50-400. No matter what is typed in the chat (like "-cam 999"), only the Else is running, even when it shouldnt.. I tried converting the substring to a real and doing the same condition comparison which did not work either.

  • camAdjust
    • Events
      • Player - Player 1 (Red) types a chat message containing -cam as A substring
    • Conditions
    • Actions
      • Set VariableSet camInteger = (Integer((Substring((Entered chat string), 6, 8))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • camInteger Less than 50
          • camInteger Greater than 400
        • Then - Actions
          • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
          • Sound - Play Error <gen>
          • Custom script: endif
          • Game - Display to (Player group((Triggering player))) the text: |cffff0000Error:|r ...
        • Else - Actions
          • Game - Display to (All players) the text: (String(camInteger))
          • Set VariableSet camera_distance[(Player number of (Triggering player))] = (10.00 x (Real(camInteger)))
Thanks for the help! :)
 

Uncle

Warcraft Moderator
Level 69
Joined
Aug 10, 2018
Messages
7,240
Your Conditions don't make sense. How can a number be both less than 50 and greater than 400 at the same time? ALL Conditions need to be met in order for the Actions to occur.

Also, use a Sound variable to avoid a desync:
  • Set Variable TempSound = No sound
  • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
  • Set Variable TempSound = Error <gen>
  • Sound - Play TempSound
  • Custom script: endif
  • camAdjust
    • Events
      • Player - Player 1 (Red) types a chat message containing -cam as A substring
    • Conditions
    • Actions
      • Set VariableSet camInteger = (Integer((Substring((Entered chat string), 6, 8))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • camInteger Greater than or equal to 50
          • camInteger Less than or equal to 400
        • Then - Actions
          • Game - Display to (All players) the text: (String(camInteger))
          • Set VariableSet camera_distance[(Player number of (Triggering player))] = (10.00 x (Real(camInteger)))
        • Else - Actions
          • Set Variable TempSound = No sound
          • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
          • Set Variable TempSound = Error <gen>
          • Sound - Play TempSound
          • Custom script: endif
          • Game - Display to (Player group((Triggering player))) the text: |cffff0000Error:|r ...
Lastly, this leaks a Player Group: (Player group((Triggering player)))
 
Last edited:
Level 5
Joined
Dec 30, 2022
Messages
36
Your Conditions don't make sense. How can a number be both less than 50 and greater than 400 at the same time? ALL Conditions need to be met in order for the Actions to occur.

Also, use a Sound variable to avoid a desync:
  • Set Variable TempSound = No sound
  • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
  • Set Variable TempSound = Error <gen>
  • Sound - Play TempSound
  • Custom script: endif

Thanks Uncle. You know sometimes I should get up and walk away from my trigger and come back in an hour to give my eyes a rest. Was just missing the OR (multiple conditions). Just added it! whoops...

Thanks for the tip on the sound variable/ player group as well.
 
Last edited:
Status
Not open for further replies.
Top