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!
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.
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 --------
@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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.