Rex Posted May 8, 2006 Posted May 8, 2006 Hi i created a little script to generate a dinner menu, bu i have one big problem. Random some times puts uses the same dinner in a row. expandcollapse popup#include <GUIConstants.au3>; Includes Gui Constants #include <file.au3> #include <string.au3> Global $Uge $Y = 0 $Uge = "19" Do $Uge = $Uge + 1 $Y = $Y+1 If $y = 1 Then FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF) Else FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF) EndIf _Retter() Until $Y = 4 Exit ;Funktionen udvælg retter Func _Retter() $i = 0 $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt") Do $i = $i+1 $Retter = Random(1,$NumberOfLines,1) $Read = FileReadLine("Retter.txt", $Retter) ;Checker at den samme ret kommer 2 dage i træk If $Read = "chilisuppe" Then $i = $i +1 EndIf If $Read = "Pizza" Then $i = $i + 1 EndIf FileWrite("Menu.txt", $Read & @CRLF) Until $i = 7 EndFunc this i my code, can any one help me to do a check so i dont get the same dinner 2 days in a row /Rex
Don N Posted May 8, 2006 Posted May 8, 2006 expandcollapse popup#include <GUIConstants.au3>; Includes Gui Constants #include <file.au3> #include <string.au3> Global $Uge $Y = 0 $Uge = "19" Do $Uge = $Uge + 1 $Y = $Y+1 If $y = 1 Then FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF) Else FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF) EndIf _Retter() Until $Y = 4 Exit ;Funktionen udvælg retter Func _Retter() $i = 0 $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt") $prev_meal = "" Do $i = $i+1 ;this loop will prevent 2 of the same meals in a row Do $Retter = Random(1,$NumberOfLines,1) $Read = FileReadLine("Retter.txt", $Retter) Until $Read <> $prev_meal ;Checker at den samme ret kommer 2 dage i træk If $Read = "chilisuppe" Then $i = $i +1 EndIf If $Read = "Pizza" Then $i = $i + 1 EndIf FileWrite("Menu.txt", $Read & @CRLF) ;reacord the meal to check for same meal in next loop iteration $prev_meal = $Read Until $i = 7 EndFunc I added a nested loop to keep generating random meals until one that doesnt match the previous one is generated. _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper
Rex Posted May 8, 2006 Author Posted May 8, 2006 (edited) expandcollapse popup#include <GUIConstants.au3>; Includes Gui Constants #include <file.au3> #include <string.au3> Global $Uge $Y = 0 $Uge = "19" Do $Uge = $Uge + 1 $Y = $Y+1 If $y = 1 Then FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF) Else FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF) EndIf _Retter() Until $Y = 4 Exit ;Funktionen udvælg retter Func _Retter() $i = 0 $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt") $prev_meal = "" Do $i = $i+1 ;this loop will prevent 2 of the same meals in a row Do $Retter = Random(1,$NumberOfLines,1) $Read = FileReadLine("Retter.txt", $Retter) Until $Read <> $prev_meal ;Checker at den samme ret kommer 2 dage i træk If $Read = "chilisuppe" Then $i = $i +1 EndIf If $Read = "Pizza" Then $i = $i + 1 EndIf FileWrite("Menu.txt", $Read & @CRLF) ;reacord the meal to check for same meal in next loop iteration $prev_meal = $Read Until $i = 7 EndFunc I added a nested loop to keep generating random meals until one that doesnt match the previous one is generated. Thx I'd try to do the same thing, i only forgot to put the "clear" var in the loop (no wondering it dn't work :"> ) Now all i need is to finde out how to put in weekdays then i have a perfect meeal menu creater, and for 4 weeks Ohh any on how to prevent getting suppe twice a week ? /Rex Edited May 8, 2006 by Rex
seandisanti Posted May 8, 2006 Posted May 8, 2006 ThxI'd try to do the same thing, i only forgot to put the "clear" var in the loop (no wondering it dn't work :"> )Now all i need is to finde out how to put in weekdays then i have a perfect meeal menu creater, and for 4 weeks Ohh any on how to prevent getting suppe twice a week ?/Rexbah. wish i'd thought of something like this 5 years ago. thought i was taking the easy way out by just getting married.
Rex Posted May 8, 2006 Author Posted May 8, 2006 bah. wish i'd thought of something like this 5 years ago. thought i was taking the easy way out by just getting married.My prob. is that i'm married - but nither me or my wife can deside what to make for dinner./Rex
seandisanti Posted May 8, 2006 Posted May 8, 2006 My prob. is that i'm married - but nither me or my wife can deside what to make for dinner./Rexah. my (soon to be ex) wife can't decide what NOT to have for dinner.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now