so guy i have made this script that has like 20 different loops but i need help to know how to make it random changes between it not to go in the same Specific order every time
loop
{ do stuff} ;loop1
loop
{ do stuff} ;loop2
loop
{ do stuff} ;loop3
loop
{ do stuff} ;loop4
;and on.....
so i want it to shuffle between loops not to go from 1 to 20 in same order everytime
i need help how to random the loops not to be in order
Re: i need help how to random the loops not to be in order
This performs each “loop” exactly once in random order. Just replace the MsgBox lines with the loop and whatever code you want to perform in each one.
Code: Select all
#Requires AutoHotkey v2.0
NumList := ''
loop 20
NumList .= A_Index '`n'
NumList := Sort(RTrim(NumList, '`n'), 'Random')
loop parse NumList, '`n'
Func%A_LoopField%()
Func1() {
MsgBox 'Loop 1'
}
Func2() {
MsgBox 'Loop 2'
}
Func3() {
MsgBox 'Loop 3'
}
Func4() {
MsgBox 'Loop 4'
}
Func5() {
MsgBox 'Loop 5'
}
Func6() {
MsgBox 'Loop 6'
}
Func7() {
MsgBox 'Loop 7'
}
Func8() {
MsgBox 'Loop 8'
}
Func9() {
MsgBox 'Loop 9'
}
Func10() {
MsgBox 'Loop 10'
}
Func11() {
MsgBox 'Loop 11'
}
Func12() {
MsgBox 'Loop 12'
}
Func13() {
MsgBox 'Loop 13'
}
Func14() {
MsgBox 'Loop 14'
}
Func15() {
MsgBox 'Loop 15'
}
Func16() {
MsgBox 'Loop 16'
}
Func17() {
MsgBox 'Loop 17'
}
Func18() {
MsgBox 'Loop 18'
}
Func19() {
MsgBox 'Loop 19'
}
Func20() {
MsgBox 'Loop 20'
}
Re: i need help how to random the loops not to be in order
@boiler
Why these extra movements?
Why are you ignoring Autohotkey's object-oriented features, such as the array of function objects?
Why these extra movements?
Why are you ignoring Autohotkey's object-oriented features, such as the array of function objects?
Please post your script code inside [code] ... [/code] block. Thank you.
Re: i need help how to random the loops not to be in order
Rather than ask me why I didn’t do it that way, why not just demonstrate the way you suggest for OP to see? I’m not sure how what you’re saying is going to lead to shorter code. You still need to randomize the order they’re selected while ensuring is selected once and only once.
-
- Posts: 4365
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: i need help how to random the loops not to be in order
Perhaps @vmech meant something like this:
Code: Select all
arr := []
loop 20 {
arr.Push(Func%A_Index%)
}
Loop 20 {
arr.RemoveAt(Random(1, arr.Length))()
}
I wouldn't say that the function array is an object-oriented feature. It is rather the opposite, a feature from the functional approach.
Who is online
Users browsing this forum: mikeyww, WarlordAkamu67 and 45 guests