Xenobiologist Posted March 26, 2006 Share Posted March 26, 2006 HI, I´m scripting the game Yahtzee int Autoit and I wanna add a highscore. Maybe somebody has already done that and shares his code. I´ve just started with the highscore thing. That is what I have so far. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Global $mamesArray[10] Global $pointsArray[10] Dim $points = 260 For $i = 1 To UBound($mamesArray) $mamesArray[$i-1] = IniRead(@ScriptDir & "\highscore\highscore.ini", $i, "Name", "NotFound") $pointsArray[$i-1] = IniRead(@ScriptDir & "\highscore\highscore.ini", $i, "Points", "NotFound") Next $GUI_HighScore = GUICreate("HighScore", 502, 233, 190, 118) $highScoreList = GUICtrlCreateListView("Number |Name |Points ", 240, 16, 250, 206) $Group1 = GUICtrlCreateGroup("Menu", 8, 48, 209, 177) GUICtrlCreateLabel("You´ve reached " &$Points & " Points", 16, 72, 187, 17) $name_I = GUICtrlCreateInput("Please enter your name", 16, 104, 185, 21, -1, $WS_EX_CLIENTEDGE) $save = GUICtrlCreateButton("Save", 16, 144, 187, 25, $SS_SUNKEN) $Headline_L = GUICtrlCreateLabel("HighScore of Yahtzee(Mega)", 8, 15, 211, 33) GUICtrlSetFont($Headline_L,12, 400, 4, "Arial") For $i = 0 To UBound($mamesArray) - 1 GUICtrlCreateListViewItem($i+1 & "|" & $mamesArray[$i] & "|" & $pointsArray[$i], $highScoreList) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop case $msg = $save save() Case Else ;;;;;;; EndSelect WEnd Exit Func save() ;save at the right postition and refresh GUI EndFunc Ini-File [1] Name=Player 1 Points = 300 [2] Name=Player 2 Points = 290 [3] Name=Player 3 Points = 280 [4] Name=Player 4 Points = 270 [5] Name=Player 5 Points = 260 [6] Name=Player 6 Points = 250 [7] Name=Player 7 Points = 240 [8] Name=Player 8 Points = 230 [9] Name=Player 9 Points = 220 [10] Name=Player 10 Points = 210 Thank you! So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
cppman Posted March 26, 2006 Share Posted March 26, 2006 I Think it would be pretty interesting to have online scores... using MySQL. right now, seems like a good way to keep the scores............ Miva OS Project Link to comment Share on other sites More sharing options...
nfwu Posted March 26, 2006 Share Posted March 26, 2006 I have some Windows Server scripts for a highscore database, but I'm not sure if that is what you want... #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 26, 2006 Author Share Posted March 26, 2006 HI, no I don´t want online score and I don´t want a MySQL-thing. I just want a GUI where the user can enter his name and then name and score is saved in a ini file. (at the right position) There always should be only 10 highscores which should be displayed in a GUICtrlCreateListView. After the user has saved his highscore the ini file has to be read again and the new highscore is shown (refreshed). That´s all. I think, that is a little bit specific, so that I have to make it on my own. I was asking, because maybe somebody has already made a autoit game with a nice highscore functionality. Thanks for you replies! So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 26, 2006 Author Share Posted March 26, 2006 Hi, I ment something like this. Not ready, but it seems to work by now. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Global $mamesArray[10] Global $pointsArray[10] Global $listViewItems[11] Dim $points = 256 Dim $defaultName = "Player1" $GUI_HighScore = GUICreate("HighScore", 502, 233, 190, 118) $highScoreList = GUICtrlCreateListView("Number |Name |Points ", 240, 16, 250, 206) $menu_G = GUICtrlCreateGroup("Menu", 8, 48, 209, 177) GUICtrlCreateLabel("Your Score is: " & $points & " Points", 16, 72, 187, 17) $name_I = GUICtrlCreateInput(IniRead(@ScriptDir & "\highscore\highscore.ini", "Name", "Name", "No Name found!"), _ 16, 104, 185, 21, -1, $WS_EX_CLIENTEDGE) $save = GUICtrlCreateButton("Save", 16, 144, 187, 25, $SS_SUNKEN) $Headline_L = GUICtrlCreateLabel("HighScore of Yahtzee(Mega)", 8, 15, 211, 33) GUICtrlSetFont($Headline_L, 12, 400, 4, "Arial") If GUICtrlRead($name_I) = "" Then GUICtrlSetData($name_I, $defaultName) read() For $i = 0 To UBound($mamesArray) - 1 $listViewItems[$i] = GUICtrlCreateListViewItem($i + 1 & "|" & $mamesArray[$i] & "|" & $pointsArray[$i], $highScoreList) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $save save() Case Else ;;;;;;; EndSelect WEnd Exit Func read() For $i = 1 To UBound($mamesArray) $mamesArray[$i - 1] = IniRead(@ScriptDir & "\highscore\highscore.ini", $i, "Name", "NotFound") $pointsArray[$i - 1] = IniRead(@ScriptDir & "\highscore\highscore.ini", $i, "Points", "NotFound") Next EndFunc ;==>read Func save() Dim $sortArray[10] For $i = 0 To UBound($mamesArray) - 1 $sortArray[$i] = $pointsArray[$i] & "," & $mamesArray[$i] Next $sortArray[9] = _ArrayAdd($sortArray, $points & "," & GUICtrlRead($name_I)) _ArraySort($sortArray, 1, 0) For $i = 1 To UBound($mamesArray) IniWrite(@ScriptDir & "\highscore\highscore.ini", $i, "Points", StringMid($sortArray[$i - 1], 1, 3)) IniWrite(@ScriptDir & "\highscore\highscore.ini", $i, "Name", StringMid($sortArray[$i - 1], 5)) Next read() For $i = 1 To UBound($mamesArray) - 1 GUICtrlSetData($listViewItems[$i - 1], $i & "|" & StringMid($sortArray[$i - 1], 5) & "|" & StringMid($sortArray[$i - 1], 1, 3)) Next IniWrite(@ScriptDir & "\highscore\highscore.ini", "Name", "Name", GUICtrlRead($name_I)) EndFunc ;==>save Ini Name=Player 1 Points = 300 [2] Name=Player 2 Points = 290 [3] Name=Player 3 Points = 280 [4] Name=Player 4 Points = 270 [5] Name=Player 5 Points = 260 [6] Name=Player 6 Points = 250 [7] Name=Player 7 Points = 240 [8] Name=Player 8 Points = 230 [9] Name=Player 9 Points = 220 [10] Name=Player 10 Points = 210 [Name] Name=Mega So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 26, 2006 Moderators Share Posted March 26, 2006 Name=Player 10If you are going to be pulling data, and since you are using arrays, wouldn't it be easier to do that like:Player10=Name? That could leave you with just having to mess with one Section rather than multiple ones I would imagine... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 27, 2006 Author Share Posted March 27, 2006 If you are going to be pulling data, and since you are using arrays, wouldn't it be easier to do that like:? That could leave you with just having to mess with one Section rather than multiple ones I would imagine... Hi SmOke_N, I don´t get what your are saying. There is no advantage saving the data in the key instaed of saving it in the value. For the highscore, I have to save 10 sections with 10 players and the points. I could do just one key in a section and save it like this: [1] key=SmOke_N,300 [2] key=Mega,297 [3] key=Player 4,200 and so on. The advantage would be saving the time to read but adding time to manipulate the string. I´ve to think about it. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 27, 2006 Moderators Share Posted March 27, 2006 Depends on how you look at that... you could do it all with one array... IniReadSection() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 27, 2006 Author Share Posted March 27, 2006 (edited) Depends on how you look at that... you could do it all with one array... IniReadSection() Hi, I changed it to using only one array and one read action. (? Is that good English ) That´s what I got so far. Maybe somebody has an idea for me. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Global $highScoreArray[10] Global $listViewItems[11] Dim $points = 326 Dim $defaultName = "Player1" ;GUI $GUI_HighScore = GUICreate("HighScore", 502, 233, 190, 118);,$DS_SETFOREGROUND);,$WS_EX_TRANSPARENT) $highScoreList = GUICtrlCreateListView("Number |Name |Points ", 240, 16, 250, 206) $menu_G = GUICtrlCreateGroup("Menu", 8, 48, 209, 177) GUICtrlCreateLabel("Your Score is: " & $points & " Points", 16, 72, 187, 17) $name_I = GUICtrlCreateInput(IniRead(@ScriptDir & "\highscore\highscore.ini", "Name", "Name", "No Name found!"), _ 16, 104, 185, 21, -1, $WS_EX_CLIENTEDGE) $save = GUICtrlCreateButton("Save", 16, 144, 187, 25, $SS_SUNKEN) $Headline_L = GUICtrlCreateLabel("HighScore of Yahtzee(Mega)", 8, 15, 211, 33) ;States and Fonts GUICtrlSetState($name_I, $GUI_FOCUS) GUICtrlSetState($save, $GUI_DEFBUTTON) GUICtrlSetFont($Headline_L, 12, 400, 4, "Arial") ;Program-Code readHighScoreIni() For $i = 0 To UBound($highScoreArray) - 1 $listViewItems[$i] = GUICtrlCreateListViewItem($i + 1 & "|" & StringMid($highScoreArray[$i], 5) & "|" & StringMid($highScoreArray[$i], 1, 3), $highScoreList) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $save save() GUICtrlSetState($save, $GUI_DISABLE) GUICtrlSetState($name_I, $GUI_DISABLE) Case Else ;;;;;;; EndSelect WEnd Exit Func readHighScoreIni() For $i = 1 To UBound($highScoreArray) $highScoreArray[$i - 1] = IniRead(@ScriptDir & "\highscore\highscore.ini", $i, "value", "NotFound") Next EndFunc ;==>read Func save() If GUICtrlRead($name_I) = "" Then GUICtrlSetData($name_I, $defaultName) _ArrayAdd($highScoreArray, $points & "," & GUICtrlRead($name_I)) _ArraySort($highScoreArray, 1, 0) For $i = 1 To UBound($highScoreArray) - 1 IniWrite(@ScriptDir & "\highscore\highscore.ini", $i, "value", $highScoreArray[$i - 1]) Next readHighScoreIni() For $i = 1 To UBound($highScoreArray) - 1 GUICtrlSetData($listViewItems[$i - 1], $i & "|" & StringMid($highScoreArray[$i - 1], 5) & "|" & StringMid($highScoreArray[$i - 1], 1, 3)) Next IniWrite(@ScriptDir & "\highscore\highscore.ini", "Name", "Name", GUICtrlRead($name_I)) EndFunc ;==>save Ini [1] value=310,Player 0 [2] value=300,Player 1 [3] value=290,Player 2 [4] value=280,Player 3 [5] value=270,Player 4 [6] value=260,Player 5 [7] value=260,Player 6 [8] value=260,Player 7 [9] value=260,Player 8 [10] value=260,Player 9 [Name] Name=Mega So long, Mega Edited March 27, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 31, 2006 Moderators Share Posted March 31, 2006 I had forgoten about this thread... Mega.. This is what I was talking about: [HighScore] 320=Player1 310=Player2 300=Player3 290=Player4 280=Player5 270=Player6 260=Player7 250=Player8 240=Player9 230=Player10 [Name] Name=Mega expandcollapse popup#include <GUIConstants.au3> Global $highScoreArray[10] Global $listViewItems[11] Dim $points = 326 Dim $defaultName = "Player1" ;GUI $GUI_HighScore = GUICreate("HighScore", 502, 233, 190, 118);,$DS_SETFOREGROUND);,$WS_EX_TRANSPARENT) $highScoreList = GUICtrlCreateListView("Number |Name |Points ", 240, 16, 250, 206) $menu_G = GUICtrlCreateGroup("Menu", 8, 48, 209, 177) GUICtrlCreateLabel("Your Score is: " & $points & " Points", 16, 72, 187, 17) $name_I = GUICtrlCreateInput(IniRead(@ScriptDir & "\highscore\highscore.ini", "Name", "Name", "No Name found!"), _ 16, 104, 185, 21, -1, $WS_EX_CLIENTEDGE) $save = GUICtrlCreateButton("Save", 16, 144, 187, 25, $SS_SUNKEN) $Headline_L = GUICtrlCreateLabel("HighScore of Yahtzee(Mega)", 8, 15, 211, 33) ;States and Fonts GUICtrlSetState($name_I, $GUI_FOCUS) GUICtrlSetState($save, $GUI_DEFBUTTON) GUICtrlSetFont($Headline_L, 12, 400, 4, "Arial") ;Program-Code $highScoreArray = readHighScoreIni() For $i = 1 To $highScoreArray[0][0] $listViewItems[$i] = GUICtrlCreateListViewItem($i & "|" & $highScoreArray[$i][1] & "|" & $highScoreArray[$i][0], $highScoreList) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $save SaveScore() GUICtrlSetState($save, $GUI_DISABLE) GUICtrlSetState($name_I, $GUI_DISABLE) Case Else ;;;;;;; EndSelect WEnd Exit Func readHighScoreIni() Return IniReadSection(@ScriptDir & "\highscore\highscore.ini", 'HighScore') EndFunc;==>read Func SaveScore(); Will only keep the top 10... Didn't know if that's what you wanted, but having them all would have been easier anyway. If Not GUICtrlRead($name_I) <> '' Then GUICtrlSetData($name_I, $defaultName) Local $SaveIni = readHighScoreIni() Local $SaveSpot = 0 Local $NewSaveValue[11][3] For $i = 1 To $SaveIni[0][0] If $points >= $SaveIni[$i][0] And $SaveSpot = 0 Then $SaveSpot = 1 $NewSaveValue[$i][0] = $points $NewSaveValue[$i][1] = GUICtrlRead($name_I) ElseIf $points >= $SaveIni[$i][0] And $SaveSpot = 1 Then $NewSaveValue[$i][0] = $SaveIni[$i - 1][0] $NewSaveValue[$i][1] = $SaveIni[$i - 1][1] Else $NewSaveValue[$i][0] = $SaveIni[$i][0] $NewSaveValue[$i][1] = $SaveIni[$i][1] EndIf Next For $i = 1 To $SaveIni[0][0] IniDelete(@ScriptDir & "\highscore\highscore.ini", 'HighScore', $SaveIni[$i][0]) Next For $i = 1 To UBound($NewSaveValue) - 1 IniWrite(@ScriptDir & "\highscore\highscore.ini", 'HighScore', $NewSaveValue[$i][0], $NewSaveValue[$i][1]) GUICtrlSetData($listViewItems[$i], $i & "|" & $NewSaveValue[$i][1] & "|" & $NewSaveValue[$i][0]) Next IniWrite(@ScriptDir & "\highscore\highscore.ini", "Name", "Name", GUICtrlRead($name_I)) EndFuncSorry it took so long, but I just ran acrossed 20 minutes ago and said "Oh yeah!".... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 31, 2006 Author Share Posted March 31, 2006 (edited) Sorry it took so long, but I just ran acrossed 20 minutes ago and said "Oh yeah!".... Nice one. I'll have to think about replacing mine with yours. Later on I´ll use _StringEncrypt() for it so that nobody easily could manipulate the highscore. I haven't looked at IniReadSection that close before, but it seems to be a good alternative to one I´ve chosen. (because returning an array [X][Y]) Thanks! Maybe in three weeks my game Yahtzee is nearly ready and I'll PM you for having a look first. So long, Mega Edited March 31, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 31, 2006 Moderators Share Posted March 31, 2006 Good deal... you know... I kinda feel like an , I didn't know you actually got yours working ... But none the less, I wanted to show you what I was talking about. I set up my Ini(s) like this alot, just makes it for easier tracking if you know what I mean. Look forward to the PM Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
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