Random Number Help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bettis

Random Number Help

26 Jul 2017, 22:42

Hi All,

I need help with a script.
What I want to do is generate a random number between x and y and have a word after it.
What I currently have,

Code: Select all

send, % ran(1, 10) word

ran(min, max)
 {
   random, ran, min, max
   return ran
 }
However because it returns ran the 'word' isn't written. Can I get some help with this please? :)

Mod edit: Added code tags.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Random Number Help  Topic is solved

26 Jul 2017, 23:06

send, % ran(1, 10) " word"

Read up a bit on expressions.
Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.
Without the double quote, AHK was interpretting word to be a variable. And this variable was never assigned a value. You can try it with a code like this:

Code: Select all

word:="AutoHotkey"
Send, % ran(1, 10) word
Bettis

Re: Random Number Help

26 Jul 2017, 23:19

Thanks for the fast reply! I'll have to take a look more into that thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CrowexBR, Google [Bot], ht55cd3 and 267 guests