Reading letters and numbers
-
- Posts: 119
- Joined: 25 Dec 2015, 10:01
Reading letters and numbers
So i am trying to make a script for myself which automatically creates coupon codes so what it needs to do is form a certain word with numbers behind it and place it down in a .txt so that it is uable to generate the same code again
Re: Reading letters and numbers
You want to create your own codes? if so this should get you started
Code: Select all
global words := ["red","blue","green","one","two","three"]
global minNumbers := 4
global maxNumbers := 4
iniread,currentCode,coupon.ini,code,current,0 ;current code is stored in coupon.ini
if (currentCode == 0) {
currentCode := generateCode(0) ;only happens when first run to generate a starting code
iniwrite,%currentCode%,coupon.ini,code,current
}
gui,+toolwindow
gui,font,s20 cFF0000
Gui, Add, Text, x2 y8 w130 h52 vmainText, % currentCode
gui,font
Gui, Add, Button, x2 y60 w130 h30 gnewCode, New Code
Gui, Show, x127 y87 h92 w138, Coupon Codes
Return
GuiClose:
ExitApp
newCode:
currentCode := generateCode(currentCode)
iniwrite,%currentCode%,coupon.ini,code,current
guicontrol,,mainText,% currentCode
return
generateCode(currentCode) {
RegExMatch(currentCode,"^(\w+)(\d+)",match)
currentWord := (match ? match1 : "")
currentNumber := (match ? match2 : "")
loop {
word := words[random(1,words.length())]
if (word != currentWord) ;dont use the last word
break
}
loop {
numDigits := Random(minNumbers,maxNumbers)
loop % numDigits
numbers .= random(0,9)
if (numbers != currentNumber) ;dont use the last digits
break
}
return word numbers
}
random(min,max=100) {
random,result,min,max
return result
}
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
-
- Posts: 119
- Joined: 25 Dec 2015, 10:01
Re: Reading letters and numbers
so in the " global words :=" part i have to fill in all numbers and letters i know off?Spawnova wrote:You want to create your own codes? if so this should get you started
Code: Select all
global words := ["red","blue","green","one","two","three"] global minNumbers := 4 global maxNumbers := 4 iniread,currentCode,coupon.ini,code,current,0 ;current code is stored in coupon.ini if (currentCode == 0) { currentCode := generateCode(0) ;only happens when first run to generate a starting code iniwrite,%currentCode%,coupon.ini,code,current } gui,+toolwindow gui,font,s20 cFF0000 Gui, Add, Text, x2 y8 w130 h52 vmainText, % currentCode gui,font Gui, Add, Button, x2 y60 w130 h30 gnewCode, New Code Gui, Show, x127 y87 h92 w138, Coupon Codes Return GuiClose: ExitApp newCode: currentCode := generateCode(currentCode) iniwrite,%currentCode%,coupon.ini,code,current guicontrol,,mainText,% currentCode return generateCode(currentCode) { RegExMatch(currentCode,"^(\w+)(\d+)",match) currentWord := (match ? match1 : "") currentNumber := (match ? match2 : "") loop { word := words[random(1,words.length())] if (word != currentWord) ;dont use the last word break } loop { numDigits := Random(minNumbers,maxNumbers) loop % numDigits numbers .= random(0,9) if (numbers != currentNumber) ;dont use the last digits break } return word numbers } random(min,max=100) { random,result,min,max return result }
Re: Reading letters and numbers
Only the words, numbers are automatically set, the length of numbers is determined by minNumbers and maxNumbers variable.
if you need a very large list of words, it may be easier to save them to a .txt file and read them from ahk.
example:
if you need a very large list of words, it may be easier to save them to a .txt file and read them from ahk.
example:
Code: Select all
global words := []
global minNumbers := 3 ;numbers must be atleast 3 digits long
global maxNumbers := 4 ;number must not be over 4 digits long
fileread,wordList,wordList.txt ;load text file into memory (worldList.txt)
loop,parse,wordList,`n,`r ;parse through the text, checking every new line
words.insert(a_loopfield) ;insert word into array
iniread,currentCode,coupon.ini,code,current,0 ;current code is stored in coupon.ini
if (currentCode == 0) {
currentCode := generateCode(0) ;only happens when first run to generate a starting code
iniwrite,%currentCode%,coupon.ini,code,current
}
gui,+toolwindow
gui,font,s14 cFF0000
Gui, Add, Text, x2 y14 w130 h46 vmainText, % currentCode
gui,font
Gui, Add, Button, x2 y60 w130 h30 gnewCode, New Code
Gui, Show, x127 y87 h92 w138, Coupon Codes
Return
GuiClose:
ExitApp
newCode:
currentCode := generateCode(currentCode)
iniwrite,%currentCode%,coupon.ini,code,current
guicontrol,,mainText,% currentCode
return
generateCode(currentCode) {
RegExMatch(currentCode,"^(\w+)(\d+)",match)
currentWord := (match ? match1 : "")
currentNumber := (match ? match2 : "")
loop {
word := words[random(1,words.length())]
if (word != currentWord) ;dont use the last word
break
}
loop {
numDigits := Random(minNumbers,maxNumbers)
loop % numDigits
numbers .= random(0,9)
if (numbers != currentNumber) ;dont use the last digits
break
}
return word numbers
}
random(min,max=100) {
random,result,min,max
return result
}
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
Who is online
Users browsing this forum: Google [Bot], Xtra and 132 guests