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

Using a string to set a variable.

Status
Not open for further replies.
Level 13
Joined
Oct 18, 2013
Messages
690
Hello, I could use a little help with something. I am trying to make a trigger that in which you type, "-Spawn X" With X being a number. It will then set a variable to x. How would i do this o: :grin:
 
Level 13
Joined
Oct 18, 2013
Messages
690
Thanks!! Also, for when you set a real number to a random number, will it only set it to whole numbers?
 
Level 13
Joined
Oct 18, 2013
Messages
690
Well, my second question was unrelated. I'm changing most of my real variables to integer variables because I think if you set a real to a random number between say 1-4, that it will return numbers like 1.12 and such. In my triggers it's looking for only 1,2,3,4 and so the trigger doesn't go off. Does that sound correct?
 
You are correct. There are two separate GUI functions for random numbers. They are both listed as "Math - Random Number", but the actual function will say whether the output will include decimals or not.

The real version says "Random real number between 0.00 and 1.00", and the integer version says "Random integer number between 0.00 and 1.00". If you need them as reals but don't want the decimals, you can always take advantage of "Conversion - Convert Integer to Real".
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Make sure to test if the first character is "-" to prevent it running when people say it like "Use -spawn X to do ....". Only after you have evaluated the first character as a "-" should you check if the subsequent 5 characters are "spawn" as a sub string of length 1 cannot leak no where near as much as a sub string of length 6 ("-spawn compared with first 6 characters").

It is important that you minimize the maximum string leak from chat commands as otherwise a malicious player could abuse a spam robot to render the game unplayable.
 
Status
Not open for further replies.
Top