• 🏆 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!

[Solved] 'timer' command causing CTD

Status
Not open for further replies.
Level 2
Joined
Sep 27, 2021
Messages
4
title.

I need help regarding a 'timer' trigger. Could anyone help me with adding a condition/variable that blocks the commands listed below from enabling if someone types, say '-timer on' or any sort of body of text that is NOT a number after the '-timer' string?

  • Time Age Copy
    • Events
      • Player - Player 1 (Red) types a chat message containing -timer as A substring
    • Conditions
      • (Substring((Entered chat string), 1, 6)) Equal to -timer
    • Actions
      • Countdown Timer - Start AgeTimer as a Repeating timer that will expire in (Real((Substring((Entered chat string), 7, 60)))) seconds
      • Set VariableSet timer_amount = (Real((Substring((Entered chat string), 8, 12))))
This is to create failsafe as we're currently having issues with the game CTD'ing as soon as the command is entered.

Thank you,

- xxguyjonesxx
 
Level 25
Joined
Sep 26, 2009
Messages
2,383
Use a boolean variable:
  • TimerOn
    • Events
      • Player - Player 1 (Red) types a chat message containing -timer on as An exact match
    • Conditions
    • Actions
      • Set VariableSet TimerOn = True
  • TimerStart
    • Events
      • Player - Player 1 (Red) types a chat message containing -timer as A substring
    • Conditions
      • TimerOn Equal to False
      • (Substring((Entered chat string), 1, 7)) Equal to -timer
    • Actions
      • -------- do stuff --------
I am not sure if there is a function that checks if string is a valid number. Perhaps someone will know of such jass function.
If there is none, then you would have to manually check each character of the string to see whether it is any of the number characters. It's not complicated, but should be avoided if there are better ways to do it.

Aside from that, a few things to note:
  • Your condition checks that the first to sixth characters in the string are equal to '-timer', but you probably want to check first to seventh character '-timer ' (including the space), since the extra space could cause any conversion from string to number to fail.
  • You set the timer's value to (Real((Substring((Entered chat string), 7, 60)))) seconds - you should think of a more realistic times than this range
    • First of all, in your case the number could possibly have 54 digits, which I think is more digits than real number can have
    • Second of all, just the number 99,999 seconds is equal to 27.7 hours - way longer time than the players will possibly play the game

Edit:
I created the validation trigger. Currently it simply checks if a string is an integer number (number with no fractions). It is possible to update the trigger to also check a string that may contain a single fraction separator (either dot or comma).


  • CharacterIsDigit: boolean
  • NumericChar: integer
  • StringCharacter: string
  • StringIndex: integer
  • StringIsNumber: boolean
  • StringToValidate: string


  • StringIsIntegerNumber
    • Events
    • Conditions
    • Actions
      • -------- Assume the string will be valid number --------
      • Set VariableSet StringIsNumber = True
      • -------- ------------------------------------------------ --------
      • -------- Check the string to see if any character IS NOT a digit --------
      • For each (Integer StringIndex) from 1 to (Length of StringToValidate), do (Actions)
        • Loop - Actions
          • -------- Get a character from string at StringIndex position --------
          • Set VariableSet StringCharacter = (Substring(StringToValidate, StringIndex, StringIndex))
          • -------- ------------------------------------------------ --------
          • -------- Validate the single character against all posible digits, break loop at first positive hit --------
          • Set VariableSet CharacterIsDigit = False
          • For each (Integer NumericChar) from 0 to 9, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • StringCharacter Equal to (String(NumericChar))
                • Then - Actions
                  • -------- Character is a digit, set CharacterIsDigit to True --------
                  • Set VariableSet CharacterIsDigit = True
                  • -------- break the loop --------
                  • Set VariableSet NumericChar = 10
                • Else - Actions
          • -------- ------------------------------------------------ --------
          • -------- If character was not digit, end the trigger and set StringIsNumber to false --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CharacterIsDigit Equal to False
            • Then - Actions
              • Set VariableSet StringIsNumber = False
              • Skip remaining actions
            • Else - Actions


  • Test
    • Events
      • Player - Player 1 (Red) types a chat message containing <Empty String> as A substring
    • Conditions
    • Actions
      • -------- Set string you want to validate --------
      • Set VariableSet StringToValidate = (Entered chat string)
      • -------- ------------------------------------------------ --------
      • -------- Run the validation trigger --------
      • Trigger - Run StringIsIntegerNumber <gen> (checking conditions)
      • -------- ------------------------------------------------ --------
      • -------- StringIsNumber contains result of the validation --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • StringIsNumber Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: STRING IS VALID INT...
        • Else - Actions
          • Game - Display to (All players) the text: STRING IS NOT AN IN...

 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,579
I think you could just do this:
  • Example
    • Events
      • Player - Player 1 (Red) types a chat message containing -timer as A substring
    • Conditions
    • Actions
      • Set VariableSet TimeAmount = 0
      • Set VariableSet StringAmount = (Substring((Entered chat string), 7, (Length of (Entered chat string))))
      • Set VariableSet TimeAmount = (Integer(StringAmount))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TimeAmount Greater than 0
          • TimeAmount Less than or equal to 9999
        • Then - Actions
          • Countdown Timer - Start AgeTimer as a Repeating timer that will expire in (Real(TimeAmount)) seconds
        • Else - Actions
          • Game - Display to (All players) for 2.00 seconds the text: Please type a valid...
This will only start the timer if the user typed a number between 1 and 9999.
 
Level 25
Joined
Sep 26, 2009
Messages
2,383
@Uncle that depends on how safe you want to have it. For example the following trigger will print 51:
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet int = (Integer(51ABC2))
      • Game - Display to (All players) the text: (String(int))
Just converting the string to integer will work for most cases, but all you need to break it is to have someone typing number like 360, but by accident also inserting additional character... e.g. '36-0' and you would suddenly have a 36 second timer instead of 360 one
 
Status
Not open for further replies.
Top