thanks very much! i'll test and report back...
Getting a Random Choice
tried the script as follows but it runs without doing anything?
#SingleInstance FORCE ; Create the empty array Files := Object ; Write to the array: Loop, Read, C:\MediaInfo\Play_List.txt ; This loop retrieves each line from the file, one at a time Files.Insert(A_LoopReadLine) ; Append this line to the array Loop, % Files.MaxIndex() ; Files.MaxIndex() contains the maximum number of items in the Array { File := Unique_RChoice(Files) msgbox % File ;RunWait,C:\Program Files\Windows Media Player\wmplayer.exe %File% ;Run,"C:\Program Files\Windows Media Player\wmplayer.exe" %File% ; tried this, too! Run,%File% ;Runwait is really unlikely to work here. You have to do something to figure out when to resume the loop when the track has finished } Unique_RChoice(Array){ If (Array.MaxIndex() = 0 || Array.MaxIndex() = "") return, "ERROR" else { Random,Rand,1,% Array.MaxIndex() Ret := Array[Rand] Array.Remove(Rand) return, Ret } }
@mrmike. Here it is. I'm not sure if it will work 100% properly. But i gave it a few test runs.
Choices := ["glow stick", "needle", "stop sign", "blouse", "hanger", "rubber duck", "shovel", "bookmark", "model car", "tampon", "rubber band", "tire swing", "sharpie", "picture frame", "photo album", "nail filer", "tooth paste", "bath fizzers", "tissue box", "deodorant ", "cookie jar", "rusty nail", "drill press", "chalk", "word search", "thermometer ", "face wash", "paint brush", "candy wrapper", "shoe lace", "leg warmers", "wireless control", "boom box", "quilt", "stockings", "card", "tooth pick", "shawl", "speakers ", "key chain", "cork", "helmet", "mouse pad", "zipper", "glasses", "lamp shade", "sketch pad", "gage", "plastic fork", "flag", "clay pot", "check book", "CD"] Loop,% Choices.MaxIndex() MsgBox % Unique_RChoice(Choices) Unique_RChoice(Array){ If (Array.MaxIndex() = 0 || Array.MaxIndex() = "") return, "ERROR" else { Random,Rand,1,% Array.MaxIndex() Ret := Array[Rand] Array.Remove(Rand) return, Ret } }First you create an array. And then pass the array off as a parameter to the function.
It will return a random choice and remove it from the array. It will return "ERROR" either when the values run out or if the parameter passed to the function is not an array.
I made a typo in my orginal code. It should be
Files := Object()
Not
Files := Object
[ Dropbox User] [ Windows 7 Ultimate] [AHK_L v1.1.13.01]
Dynamic Hotstrings Library - Create hotstrings with variables and regex!
this one works as expected. simple and fast. i am running this script using run, % a_loopfield, 1. have a piece of code in my archives that figures out when to resume the loop when the track has finished that i am going to add later...
Maybe, this is not enough code;)
fileread, x, mp3.txt sort, x, Random loop, parse, x, `n, `r run, % a_loopfield, 1 ;soundplay,% a_loopfield, 1
thanks, it works now! i will add the part that figures out when to resume the loop when the track has finished now...
I made a typo in my orginal code. It should be
Files := Object()Not
Files := Object
this is the piece of code that figures out when to resume the loop when the track has finished:
p.s.: this is NOT my code. i believe it was created by Wicked.
{ o:=comobjcreate("Shell.Application") ;fileselectfile,file,c:\ ;file := Clipboard ;msgbox %file% splitpath,file,file,directory if errorlevel exitapp od:=o.namespace(directory) of:=od.parsename(file) loop,50 ; 50 is an arbitrary number > 21 if(od.getdetailsof("",a_index)=="Duration"){ length:=od.getdetailsof(of,a_index) break } stringsplit,length,length,: MP3Len := 3600000*length1+60000*length2+1000*length3 ;msgbox,% "Duration of " file " in millisceonds is " 3600000*length1+60000*length2+1000*length3 "." Return }
Hello, I'm new round here and think AHK is wonderful ...
I'm not sure if anyone else has noticed but in Menixator's excellent post there is a miss-spelling in the first line:
Random,Coice_Num,1,3
If (Choice_Num = 1)
Choice = "Rock"
else if (Choice_Num = 2)
Choice = "Num"
else if (Choice_Num = 3)
Choice = "Num"
I assume Coice should be Choice.
Hi, I'm very new to AHK, so apologies if this exists but I can't find it.
So I want to be able to randomise a script. At the moment I have:
::soz::
I hope that makes sense,
Thanks,
Luke
hi:=["Hi", "Hello", "Hey"] soz:=["Oh no, I'm sorry", "I can't believe it!"] ::hi:: ::soz:: abr:=SubStr(A_ThisHotkey,3) Random, Word, 1, % %abr%.MaxIndex() Send % %abr%[Word] Return