My random chance isn't working. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zndr
Posts: 15
Joined: 07 Jul 2017, 04:09

My random chance isn't working.

18 Nov 2017, 18:09

Hey, I'm making a really simple script but for some reason I'm still messing up :|

My goal is to press T, and then it sends a WheelUp input. However, there's a 50% chance to then sleep 100-250ms and send a WheelDown input.

For some reason, it's doing Wheelup then Wheeldown 100% of the time - so my randomization isn't working properly. I used this a lot before for different purposes but I can't get it to work for this.

Here's my code.

Code: Select all

ran(min, max)
 {
   random, ran, min, max
   return ran
 }

T::
send {WheelUp}
	Random, rnd,1,100
	#if (rnd <= 50)
		Sleep, % ran(100, 250)
		send {WheelDown}
return
ty <3
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: My random chance isn't working.

18 Nov 2017, 18:32

Code: Select all

#SingleInstance,Force
i:=0
j:=0
return

ran(min, max)
	{
  		random, ran, min, max
  		return ran
 	}

T::
	i++
	send {WheelUp}
	Random, rnd,1,100
	if (rnd <= 50)
		{
			j++
			Sleep, % ran(100, 250)
			send {WheelDown}
		}
	Tooltip,% i "`n" j		
	return

Esc::ExitApp
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: My random chance isn't working.  Topic is solved

18 Nov 2017, 18:39

You just used the wrong if statement incorrectly is all.

Code: Select all

rand(min, max) {
    Random, i, %min%, %max%
    return i
}

T::
    send {WheelUp}
    rnd := rand(1, 2)
    if(rnd == 1) {
        Sleep, % rand(100, 250)
        Send, {WheelDown}
    }
return
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
zndr
Posts: 15
Joined: 07 Jul 2017, 04:09

Re: My random chance isn't working.

19 Nov 2017, 19:53

KuroiLight wrote:You just used the wrong if statement incorrectly is all.

Code: Select all

rand(min, max) {
    Random, i, %min%, %max%
    return i
}

T::
    send {WheelUp}
    rnd := rand(1, 2)
    if(rnd == 1) {
        Sleep, % rand(100, 250)
        Send, {WheelDown}
    }
return
Thanks so much :)

@Hell you too, i took a look at what you did as well and it helped ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 357 guests