Jump to content

a new type of calc (help needed)


Recommended Posts

Here is what i have so far:
 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

GUICreate("Calculator", 260, 230)

; Digit Buttons
Local $CTRL_btn0 = GUICtrlCreateButton("0", 54, 171, 36, 29)
Local $CTRL_btn1 = GUICtrlCreateButton("1", 54, 138, 36, 29)
Local $CTRL_btn2 = GUICtrlCreateButton("2", 93, 138, 36, 29)
Local $CTRL_btn3 = GUICtrlCreateButton("3", 132, 138, 36, 29)
Local $CTRL_btn4 = GUICtrlCreateButton("4", 54, 106, 36, 29)
Local $CTRL_btn5 = GUICtrlCreateButton("5", 93, 106, 36, 29)
Local $CTRL_btn6 = GUICtrlCreateButton("6", 132, 106, 36, 29)
Local $CTRL_btn7 = GUICtrlCreateButton("7", 54, 73, 36, 29)
Local $CTRL_btn8 = GUICtrlCreateButton("8", 93, 73, 36, 29)
Local $CTRL_btn9 = GUICtrlCreateButton("9", 132, 73, 36, 29)
Local $CTRL_btnPeriod = GUICtrlCreateButton(".", 132, 171, 36, 29)

; Fiesta's Money Buttons
Local $CTRL_btnCopper = GUICtrlCreateButton("Copper", 8, 73, 43, 29)
Local $CTRL_btnSilver = GUICtrlCreateButton("Silver", 8, 106, 43, 29)
Local $CTRL_btnGold = GUICtrlCreateButton("Gold", 8, 138, 43, 29)
Local $CTRL_btnGems = GUICtrlCreateButton("Gems", 8, 171, 43, 29)

; Operators
Local $CTRL_btnChangeSign = GUICtrlCreateButton("+/-", 93, 171, 36, 29)
Local $CTRL_btnDivision = GUICtrlCreateButton("/", 171, 73, 36, 29)
Local $CTRL_btnMultiplication = GUICtrlCreateButton("*", 171, 106, 36, 29)
Local $CTRL_btnSubtract = GUICtrlCreateButton("-", 171, 138, 36, 29)
Local $CTRL_btnAdd = GUICtrlCreateButton("+", 171, 171, 36, 29)
Local $CTRL_btnAnswer = GUICtrlCreateButton("=", 210, 171, 36, 29)
Local $CTRL_btnInverse = GUICtrlCreateButton("1/x", 210, 138, 36, 29) ; not finished
Local $CTRL_btnSqrt = GUICtrlCreateButton("Sqrt", 210, 73, 36, 29)  ; not finished
Local $CTRL_btnPercentage = GUICtrlCreateButton("%", 210, 106, 36, 29)  ; not finished
Local $CTRL_btnBackspace = GUICtrlCreateButton("Backspace", 54, 37, 63, 29)  ; not finished
Local $CTRL_btnClearE = GUICtrlCreateButton("CE", 120, 37, 62, 29) ; not finished
Local $CTRL_btnClear = GUICtrlCreateButton("C", 185, 37, 62, 29)

; Input Area Stuff
GUISetState()
Local $CTRL_EditScreen = GUICtrlCreateEdit("", 8, 2, 239 , 23, BitOR($ES_MULTILINE, $ES_RIGHT), $WS_EX_STATICEDGE) ; multiline for text input
Local $CTRL_LblMemory = GUICtrlCreateLabel("", 12, 39, 27, 26, $SS_SUNKEN)

$i = 0
$input = GUICtrlCreateInput("", 8, 2, 239 , 23, ($ES_RIGHT), $WS_EX_STATICEDGE)

; Button Stuff
Local $msg
Do
    $msg = GUIGetMsg()
    if ($msg =  -3) Then
        $i = 1
    EndIf

    Select
    Case($msg = $CTRL_btn0)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "0")
    Case($msg = $CTRL_btn1)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "1")
    Case($msg = $CTRL_btn2)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "2")
    Case($msg = $CTRL_btn3)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "3")
    Case($msg = $CTRL_btn4)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "4")
    Case($msg = $CTRL_btn5)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "5")
    Case($msg = $CTRL_btn6)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "6")
    Case($msg = $CTRL_btn7)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "7")
    Case($msg = $CTRL_btn8)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "8")
    Case($msg = $CTRL_btn9)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & "9")
    Case ($msg = $CTRL_btnAdd)
        $num1 = GUICtrlRead($input)
        $operation = 0
        GUICtrlSetData($input, "")
    Case ($msg = $CTRL_btnSubtract)
        $num1 = GUICtrlRead($input)
        $operation = 1
        GUICtrlSetData($input, "")
    Case ($msg = $CTRL_btnMultiplication)
        $num1 = GUICtrlRead($input)
        $operation = 2
        GUICtrlSetData($input, "")
    Case ($msg = $CTRL_btnDivision)
        $num1 = GUICtrlRead($input)
        $operation = 3
        GUICtrlSetData($input, "")
    Case ($msg = $CTRL_btnCopper)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & " Copper ") ; 999 is max then converts to 1 Silver @ 1000
    Case ($msg = $CTRL_btnSilver)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & " Silver ") ; 999 is max then converts to 1 Gold @ 1000
    Case ($msg = $CTRL_btnGold)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & " Gold ") ; 99 is max then converts to 1 Gems @ 100
    Case ($msg = $CTRL_btnGems)
        $pnum = GUICtrlRead($input)
        GUICtrlSetData($input, $pnum & " Gems ") ; 21 is max converts no further
    Case ($msg = $CTRL_btnAnswer)
        If $operation = 0 Then
            _add()
        ElseIf $operation = 1 Then
            _subtract()
        ElseIf $operation = 2 Then
            _multiply()
        ElseIf $operation = 3 Then
            _divide()
        Else

        EndIf
        $operation = 4
    Case ($msg = $CTRL_btnClear)
        $num1 = 0
        $num2 = 0
        GUICtrlSetData($input, "")

    EndSelect

Until $i = 1

Func _add()
    $num2 = GUICtrlRead($input)
    $final = $num1 + $num2
    GUICtrlSetData($input, $final)
EndFunc

Func _subtract()
    $num2 = GUICtrlRead($input)
    $final = $num1 - $num2
    GUICtrlSetData($input, $final)
EndFunc

Func _multiply()
    $num2 = GUICtrlRead($input)
    $final = ($num1 * $num2)
    GUICtrlSetData($input, $final)
EndFunc

Func _divide()
    $num2 = GUICtrlRead($input)
    $final = ($num1 / $num2)
    GUICtrlSetData($input, $final)
 EndFunc

 
Now that parts i'm having problems with:
 
1. Answers in the format of xx Gems xx Gold xxx Silver xxx Copper if one of the buttons relating to those are pushed at any time (ex: 100 x 200 Silver or 300 copper + 20 gold etc)
2. making a cap on how high the above can go before rolling over into the next one example 1000 Copper should be 1 Silver and so on (in the comments)
3. Possibly adding a new input area for items (Price of 1 item [_____], X number of items per stack [_____], X amount of stacks [_____],  = non-editable area for the total price following #1's format [/////] Gems [/////] Gold [/////] Silver [/////] Copper). this could be just a button where the blank area is that pulls up a new dialog box to do all of this.
 
[___]'s are manual input boxes
 [/////]'s are non editable input boxes

Any and all help in creating this would be great

Edited by 3jameo3
Link to comment
Share on other sites

  • Moderators

3jameo3,

Welcome to the AutoIt forum. :)

Looking at some of the words used in your script, I would strongly recommend that you read the Forum rules (there is also a link at bottom right of each page) before posting again. There is no problem with the script you have posted - but you will understand why game-related scripts raise alarm bells here and why it is best to avoid obvious "gaming" terms in your scripts in future. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

To be honest its just a calculator to help with calculating the amount of money needed by a seller or buyer in said game. Yeah i can understand that cheating by use of a program is undesirable to say the least. Still would like some help to make my gamer life a bit easier i'm completely stuck on this one. Links to help understand or just scripts would be fine by me even its just a few commands and nothing else, i can always search the commands needed and learn about them. It really seemed easy in the beginning but i think i passed the beginner threshold on this one lol.

Thanks for the advice though Melba23 half the time I never even read the rules and mostly get corrected along the way then again the forums i've been on have around 100+ rules and after about 10 i lose interest and wait to be corrected lol. I like how your rules are short sweet and to the point lol so much easier to read.

Live and you learn best way to describe life in every manner possible.

Link to comment
Share on other sites

I think things should be kept simple, so here's what I came up with. You press a hotkey to bring up an inputbox, type an equation, and your answer is placed on the clipboard. You can type in numbers followed by the currency, if applicable. gem is gems, g is gold, s is silver, and c is copper, but you don't need to type c after copper if you don't want to. Let's say an item cost 2 gems, 5 gold, 2 silver, and 100 copper, there are 100 in a stack, and I want to buy 5 stacks. To find out how much this costs, I'd type "(2gem + 5g + 2s + 100) * 100 * 5" (without the quotations of course, and press enter. The program outputs the following: "(2gem + 5g + 2s + 100) * 100 * 5 = 1,002 gems, 501 gold,  and 50 silver". Just to make sure this program is working properly, you can type "1gem + 1g + 1s + 1", and make sure it is "1 gem, 1 gold, 1 silver,  and 1 copper". The program seems to be working well as far as I can tell, so here's the code.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/RM /SF = 1 /SV = 1 /PE
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;#include <array.au3>
If HotKeySet("^0", "_GO") = 0 Then
    MsgBox(262208, "Error", "I was unable to set ^0 as a hotkey, and must close the program. You can change the hotkey, or restart the application to try again.")
    Exit
EndIf
Opt("MustDeclareVars", 1)
;Testing purposes only
;_GO()
;Exit
While 1
    Sleep(1000)
WEnd
Func _GO()
    ;1 gem = 1000 gold = 1,000,000,000 copper
    ;1 gold = 1000 silver = 1,000,000 copper
    ;1 silver = 1000 copper
    HotKeySet("^0");Unset the hotkey while the inputbox is showing
    Local $Input = InputBox("Game Calculator", "Please type in your equation"), $Answer, $Split, $R
    If @error Then
        If MsgBox(262180, "Question", "Do you want to close this program?") = 6 Then
            MsgBox(262144, "Done", "The program has been closed.")
            Exit
        EndIf
    EndIf
    HotKeySet("^0", "_GO");Reset the hotkey
    If $Input == "" Then Return;If you hit the cancel button or don't type anything in, then just wait for another hotkey press.
    Switch StringLeft($Input, 1)
        Case "r", "R"
            $R = True
        Case Else
            $R = False
    EndSwitch
    ;Local $Input = "(1gem + 1g + 1s + 1c) * 1gem"
    If $R Then
        $Split = StringSplit($Input, "/");Only / is accepted as a division sign.
        If $Split[0] = 1 Then
            Do
                ClipPut($Input)
            Until ClipGet() = $Input
            MsgBox(262208, "Error", $Input & @CRLF & "You asked me to calculate a remainder, but I did not find a division sign.")
            Return
        EndIf
        $Split[1] = StringTrimLeft($Split[1], 1)
        For $C = 1 To $Split[0]
            _FormatString($Split[$C]);Just incase you are dividing one currency by another. I may as well not limit the options.
            ConsoleWrite("$Split[" & $C & "] = " & $Split[$C] & @CR)
        Next
        For $C = 3 To $Split[0]
            $Split[2] = $Split[2] * $Split[$C];Consolidate multiple division operations into one.
        Next
        $Answer = $Input & " = " & _ConvertCopper(Floor($Split[1] / $Split[2])) & " with " & _ConvertCopper(Mod($Split[1], $Split[2])) & " remaining."
    Else
        $Answer = $Input
        _FormatString($Answer)
        ;Convert copper
        $Answer = $Input & " = " & _ConvertCopper($Answer)
    EndIf
    Do
        ClipPut($Answer)
    Until ClipGet() = $Answer
    MsgBox(0, "Answer", $Answer)
EndFunc   ;==>_GO
Func _FormatString(ByRef $Answer)
    Local $Match, $Offset = 1, $Split
    ;Convert gems to copper
    While 1
        $Match = StringRegExp($Answer, "(\d+)gem", 1, $Offset)
        If @error Then
            ExitLoop
        EndIf
        $Offset = @extended
        $Answer = StringReplace($Answer, $Match[0] & "gem", $Match[0] * 1000000000);10^9
        ;_ArrayDisplay($Match,"$Match")
        ConsoleWrite("$Answer = " & $Answer & @CR)
    WEnd
    ;Convert gold to copper
    $Offset = 1
    While 1
        $Match = StringRegExp($Answer, "(\d+)g", 1, $Offset)
        If @error Then
            ExitLoop
        EndIf
        $Offset = @extended
        $Answer = StringReplace($Answer, $Match[0] & "g", $Match[0] * 1000000);10^6
        ;_ArrayDisplay($Match,"$Match")
        ConsoleWrite("$Answer = " & $Answer & @CR)
    WEnd
    ;Convert silver to copper
    $Offset = 1
    While 1
        $Match = StringRegExp($Answer, "(\d+)s", 1, $Offset)
        If @error Then
            ExitLoop
        EndIf
        $Offset = @extended
        $Answer = StringReplace($Answer, $Match[0] & "s", $Match[0] * 1000);10^3
        ;_ArrayDisplay($Match,"$Match")
        ConsoleWrite("$Answer = " & $Answer & @CR)
    WEnd
    ;Remove copper suffix, just in case
    $Offset = 1
    While 1
        $Match = StringRegExp($Answer, "(\d+)c", 1, $Offset)
        If @error Then
            ExitLoop
        EndIf
        $Offset = @extended
        $Answer = StringReplace($Answer, $Match[0] & "c", $Match[0]);10^3
        ;_ArrayDisplay($Match,"$Match")
        ConsoleWrite("$Answer = " & $Answer & @CR)
    WEnd
    $Offset = 1
    ;Add addition signs where reasonable
    While 1
        $Match = StringRegExp($Answer, "(\d+ \d+)", 1, $Offset)
        If @error Then
            ExitLoop
        EndIf
        $Offset = @extended
        $Split = StringSplit($Match[0], " ", 2)
        $Answer = StringReplace($Answer, $Match[0], $Split[0] & " + " & $Split[1])
    WEnd
    $Answer = Execute($Answer);Calculate copper
EndFunc   ;==>_FormatString
Func _ConvertCopper($Copper);I know there's a more efficient way to do this, so I'll type some faster code later.
    ;Check if this is a decimal
    ;If Int($Copper) < $Copper Then

    Local $Gems, $Gold, $Silver, $Array[4], $Count = -1, $Text = ""
    If $Copper > 999999999 Then;10^9 - 1
        $Count = 0
        $Array[$Count] = Floor($Copper / 1000000000)
        $Copper = Mod($Copper, 1000000000)
        If $Array[$Count] > 1 Then
            $Array[$Count] = _AddCommasInt($Array[$Count]) & " gems"
        Else
            $Array[$Count] = _AddCommasInt($Array[$Count]) & " gem"
        EndIf
    EndIf
    If $Copper > 999999 Then;10^6 - 1
        $Count += 1
        $Array[$Count] = Floor($Copper / 1000000) & " gold"
        $Copper = Mod($Copper, 1000000)
    EndIf
    If $Copper > 999 Then;10^3 - 1 = 999
        $Count += 1
        $Array[$Count] = Floor($Copper / 1000) & " silver"
        $Copper = Mod($Copper, 1000)
    EndIf
    If $Count > 0 Then
        If $Copper Then
            For $C = 0 To $Count
                $Text &= $Array[$C] & ", "
            Next
            $Text &= " and " & $Copper & " copper"
        Else
            Local $CMax = $Count - 1
            For $C = 0 To $CMax
                $Text &= $Array[$C] & ", "
            Next
            $Text &= " and " & $Array[$Count]
        EndIf
    Else
        If $Copper Then
            $Text = $Copper & " copper"
        Else
            $Text = $Array[$Count]
        EndIf
    EndIf
    Return $Text
EndFunc   ;==>_ConvertCopper
Func _AddCommasInt($N);Don't check if the number has a decimal because we know it'll be an intiger
    Local $E = StringLen($N) - 3, $S, $T
    If $E > 0 Then
        $S = Mod($E, 3)
        If $S Then
            $T = StringLeft($N, $S) & ","
        Else
            $T = ""
        EndIf
        $S += 1
        For $C = $S To $E Step 3
            $T &= StringMid($N, $C, 3) & ","
        Next
        $T &= StringMid($N, $E + 1)
        Return $T
    Else
        Return $N
    EndIf
EndFunc   ;==>_AddCommasInt
 
You can compile this to make the program even more efficient than it already is. The Directives at the top of the script will run AU3Stripper before the program is compiled.
 
If you have trouble typing in a calculation, explain what you're trying to calculate, and I'll see if I can show you the equation. I'm sure you'll figure it out though.
 
Addition signs are optional. I can type "1gem 1g 1s 1c" or "1gem 1g 1s 1" and I get "1 gem, 1 gold, 1 silver,  and 1 copper". If you want something other than an addition sign between two values, you'll have to type in the sign.
 
I also added an option to calculate a remainder. Type "R" or "r" before your equation to do this. For example: "r50g/3" is "16 gold, 666 silver,  and 666 copper with 2 copper remaining."
 
Multiple divisions work as well. "1 gold, 851 silver,  and 851 copper with 23 copper remaining."
 
Let me know what you think, and if there's something you'd like to add, feel free to explain your idea.
Edited by Oscis
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...