• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Using a string to set a variable.

Status
Not open for further replies.
Level 14
Joined
Oct 18, 2013
Messages
710
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 14
Joined
Oct 18, 2013
Messages
710
Thanks!! Also, for when you set a real number to a random number, will it only set it to whole numbers?
 
Level 14
Joined
Oct 18, 2013
Messages
710
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 64
Joined
Jan 18, 2005
Messages
27,258
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