Wicked667 Posted February 5, 2008 Share Posted February 5, 2008 This I made for a friend who needed something like this for an forum rpg but that's beside the point. What it does: input 1 is the kind of dice (d4/d6/d8 whatever any integer will do) and input 2 is the amount of dices, outcome is the combined number of the dice rolls. I'd like to see if someone has comments on things I can do better since I'm just starting with autoit, thx in advance. expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Dice roller", 235, 88, 303, 219) $dice = GUICtrlCreateInput("1", 16, 40, 33, 21) $amount = GUICtrlCreateInput("1", 64, 40, 33, 21) $roll = GUICtrlCreateButton("roll", 112, 40, 33, 25, 0) $Dc = GUICtrlCreateLabel("Type", 16, 8, 28, 17) $number = GUICtrlCreateLabel("Amount", 64, 8, 40, 17) $outcome = GUICtrlCreateLabel("Result:", 160, 48, 37, 17) $updown = GUICtrlCreateUpdown($dice) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Form2 Case $Form2 Case $Form2 Case $Form2 Case $dice Case $updown Case $amount Case $roll $d = GUICtrlRead($dice) $a = GUICtrlRead($amount) $1 = 1 $res=0 While $1 <= $a $dc = Random(1, $d, 1) $res = $res+$dc $1 = $1 +1 WEnd $outcome = GUICtrlCreateInput($res, 200, 40, 30, 21) Case $Dc Case $number Case $outcome EndSwitch WEnd Link to comment Share on other sites More sharing options...
weaponx Posted February 5, 2008 Share Posted February 5, 2008 Not much wrong with it. You don't need to assign variables to labels that have static text. #include <GUIConstants.au3> $Form2 = GUICreate("Dice roller", 235, 88, 303, 219) GUISetState(@SW_SHOW) $dice = GUICtrlCreateInput("1", 16, 40, 33, 21) $amount = GUICtrlCreateInput("1", 64, 40, 33, 21) $roll = GUICtrlCreateButton("roll", 112, 40, 33, 25, 0) ;Static labels GUICtrlCreateLabel("Type", 16, 8, 28, 17) GUICtrlCreateLabel("Amount", 64, 8, 40, 17) GUICtrlCreateLabel("Result:", 160, 48, 37, 17) $result = GUICtrlCreateLabel("00", 200, 48, 37, 17) $updown = GUICtrlCreateUpdown($dice) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $roll $d = GUICtrlRead($dice) $a = GUICtrlRead($amount) $1 = 1 $res=0 For $X = 1 to $a $dc = Random(1, $d, 1) $res += $dc Next GuiCtrlSetData($result,$res) EndSwitch WEnd Link to comment Share on other sites More sharing options...
Wicked667 Posted February 5, 2008 Author Share Posted February 5, 2008 (edited) Yeah good point made the gui with kodac and it put it in that code. Cheers edit: just noticed that the up and down is here in one part, was just a try that's why its only in the first square Edited February 5, 2008 by Wicked667 Link to comment Share on other sites More sharing options...
Wicked667 Posted February 5, 2008 Author Share Posted February 5, 2008 Now they want to make more roll options. I already made a version just making more inputs/roll buttons naming it $dice1/2/3/4/5 and same with cases. Now I'd like to make a option where you can fill in the amount of options. So first they have to give the $options to decide the amount of lines (line consists of the dice/amount/outcome). Then the window should be big enough to show it (each line adds 40) so that would be: $height = 48 + $options*40 $Form2 = GUICreate("Dice roller", 235, $height, 303, 219) if I'm right that is. Then the creating buttons the same idea with height. Pff.. getting a bit confused right now, too much new info at the same time to work with. Basicly it should add one var that then decides how much nex buttons come and where they come. Link to comment Share on other sites More sharing options...
weaponx Posted February 5, 2008 Share Posted February 5, 2008 This will put of the roll results into a listview. #include <GUIConstants.au3> GUICreate("listview items",220,250, 100,200) GUISetState() $listview = GUICtrlCreateListView (" # | Value",10,10,200,150);,$LVS_SORTDESCENDING) GuiCtrlCreateLabel("# Rolls", 10, 173) $numRolls = GuiCtrlCreateInput("1", 60, 170, 30, 20) GuiCtrlCreateLabel("# Sides", 10, 203) $numSides = GuiCtrlCreateInput("6", 60, 200, 30, 20) $buttonRoll = GUICtrlCreateButton ("Roll",120,180,70,30) Do $msg = GUIGetMsg () Switch $msg Case $buttonRoll For $X = 1 to GUICtrlRead($numRolls) GUICtrlCreateListViewItem($X & "|" & Random(1,GuiCtrlRead($numSides),1),$listview) Next EndSwitch Until $msg = $GUI_EVENT_CLOSE Link to comment Share on other sites More sharing options...
Wicked667 Posted February 5, 2008 Author Share Posted February 5, 2008 Not exactly what I ment but defenitly gave me a good idea, trying that out before asking more questions Big thx again Link to comment Share on other sites More sharing options...
Wicked667 Posted February 5, 2008 Author Share Posted February 5, 2008 (edited) Ok I've used the list stuff now but changed it so each line shows: Rolls | Dice | Result But I couldn't figure out how to clear the list, looked in the helpfile but couldn't find an option so help theyr would be appreciated here what I have now: #include <GUIConstants.au3> GUICreate("listview items",220,250, 100,200) GUISetState() $listview = GUICtrlCreateListView (" Rolls | Dice | Result",10,10,200,150);,$LVS_SORTDESCENDING) GuiCtrlCreateLabel("# Rolls", 10, 173) $numRolls = GuiCtrlCreateInput("1", 60, 170, 30, 20) GuiCtrlCreateLabel("# Sides", 10, 203) $numSides = GuiCtrlCreateInput("6", 60, 200, 30, 20) $buttonRoll = GUICtrlCreateButton ("Roll",120,180,70,30) Do $msg = GUIGetMsg () Switch $msg Case $buttonRoll $d = GUICtrlRead($numSides) $a = GUICtrlRead($numRolls) $1 = 1 $res=0 For $X = 1 to $a $dc = Random(1, $d, 1) $res += $dc Next GUICtrlCreateListViewItem($a & "|" & "d"&$d & "|" & $res,$listview) EndSwitch Until $msg = $GUI_EVENT_CLOSE ohw and how can I put my text in autoit code here? Edited February 5, 2008 by Wicked667 Link to comment Share on other sites More sharing options...
weaponx Posted February 5, 2008 Share Posted February 5, 2008 The changes you made to the script don't make sense to me, there is no point in doing multiple rolls because it will only show the result from the last roll. Link to comment Share on other sites More sharing options...
Wicked667 Posted February 5, 2008 Author Share Posted February 5, 2008 the output is the combined number if I try, for example 2 d6 can get everything from 2 to 12 or is that not what you ment? Link to comment Share on other sites More sharing options...
GaryFrost Posted February 5, 2008 Share Posted February 5, 2008 From about 3 years ago, might help you: http://www.autoitscript.com/forum/index.ph...ost&p=81402 SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
Wicked667 Posted February 5, 2008 Author Share Posted February 5, 2008 Well what I have now works perfectly, it's more about have I done ugly coding/useless coding and I need a clear list button (Know how to make a button but no how to clear the list)here a pic of what I've got now (each line is a different roll) Link to comment Share on other sites More sharing options...
Wicked667 Posted February 6, 2008 Author Share Posted February 6, 2008 (edited) Edit, new row for total.Current version looks like this:expandcollapse popup#include <GUIConstants.au3> #Include <GuiListView.au3> GUICreate("Diceroller",278,260, 100,210) GUISetState() $listview = GUICtrlCreateListView (" Dice | Type | Bonus | Result | Total",10,10,258,150);,$LVS_SORTDESCENDING) $List_h = GUICtrlGetHandle($Listview) GuiCtrlCreateLabel(" Amount", 10, 173) $numRolls = GuiCtrlCreateInput("1", 60, 170, 40, 20) GuiCtrlCreateLabel(" Type", 10, 203) $numSides = GuiCtrlCreateInput("6", 60, 200, 40, 20) GuiCtrlCreateLabel ("Bonus", 10, 233) $numBonus = GUICtrlCreateInput("0", 60, 230, 40, 20) $buttonRoll = GUICtrlCreateButton ("Roll",120,173,70,30) $buttonClear = GUICtrlCreateButton ("Clear",120,218,70,30) $updown = GUICtrlCreateUpdown($numRolls) $updown2 = GUICtrlCreateUpdown($numSides) $updown3 = GUICtrlCreateUpdown($numBonus) $total = 0 Do $msg = GUIGetMsg () Switch $msg Case $buttonRoll $d = GUICtrlRead($numSides) $a = GUICtrlRead($numRolls) $1 = 1 $res=0 For $X = 1 to $a $dc = Random(1, $d, 1) $res += $dc Next $res = $res+GuiCtrlRead($numBonus) $total = $total + $res GUICtrlCreateListViewItem($a & "|" & "d"&$d & "|" & GuiCtrlRead($numBonus) & "|" & $res & "|" & $total,$listview) Case $buttonClear $total = 0 _GUICtrlListView_DeleteAllItems($list_h) EndSwitch Until $msg = $GUI_EVENT_CLOSE Edited February 6, 2008 by Wicked667 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