Jump to content

Newbie help please!


Scinner
 Share

Recommended Posts

Hi, Im trying to do a simple script, please take a look at it and tell me what I am doing wrong.

My question is in the code.

#include <GuiConstants.au3>

Const $0t = 95, $0l = 75, $0j = 40, $0v = 40 ;Klubbmän
Const $1t = 145, $1l = 70, $1j = 85, $1v = 40 ;Spjutmän
Const $2t = 130, $2l = 120, $2j = 170, $2v = 70 ;Yxmän
Const $3t = 160, $3l = 100, $3j = 50, $3v = 50 ;Scout
Const $4t = 370, $4l = 270, $4j = 290, $4v = 75 ;Paladin
Const $5t = 450, $5l = 515, $5j = 480, $5v = 80 ;Germansk Knekt
Const $6t = 1000, $6l = 300, $6j = 350, $6v = 70 ;Murbräcka
Const $7t = 900, $7l = 1200, $7j = 600, $7v = 60 ;Katapult
Const $8t = 35500, $8l = 26600, $8j = 25000, $8v = 27200 ;Stamledare
Const $1t = 7200, $1l = 5500, $1j = 5800, $1v = 6500 ;Nybyggare

GuiCreate("Travian - Germaner", 350, 150)

GuiCtrlCreateLabel("Trupptyp:", 25, 5)
$trupp = GuiCtrlCreatecombo("Välj...", 25, 20, 120, 100, $CBS_DROPDOWNLIST)
GUICtrlSetData($trupp,"Klubbmän|Spjutmän|Yxmän|Scout|Paladin|Germansk Knekt|Murbräcka|Katapult|Stamledare|Nybyggare")

GuiCtrlCreateLabel("Antal:", 183, 5)
$antal = GuiCtrlCreateInput("", 183, 20, 50, 20) ;<---- Input
$UpDown = GuiCtrlCreateUpDown($antal)

$knapp = GuiCtrlCreateButton("OK", 265, 19, 60, 22)

GuiCtrlCreateLabel("Trä", 45, 54)
$tree = GuiCtrlCreateInput("", 30, 74, 50, 20)

GuiCtrlCreateLabel("Lera", 123, 54)
$lera = GuiCtrlCreateInput("", 110, 74, 50, 20)

GuiCtrlCreateLabel("Järn", 204, 54)
$iron = GuiCtrlCreateInput("", 190, 74, 50, 20)

GuiCtrlCreateLabel("Vete", 283, 54)
$vete = GuiCtrlCreateInput("", 270, 74, 50, 20)

GuiCtrlCreateLabel("Summa Råvaror", 137, 100)
$summa = GuiCtrlCreateInput("", 150, 120, 50, 20)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
    Case $knapp
        $SelectedText = GUICtrlRead($trupp)
        $SelectedNr = GUICtrlRead($antal)
        If $SelectedText = "Välj..." Then
            MsgBox(0,"Fel", "Välj Trupptyp och Antal")
        EndIf
        If $SelectedNr = "" Then
            MsgBox(0,"Fel", "Välj Trupptyp och Antal")
        EndIf
        If $SelectedText = "Klubbmän" Then
            ConsoleWrite($0t * $antal) To $tree ; <--- This is wrong. I'd like to multiply $0t with
        EndIf                                   ;      $antal(input) and then post it in $tree when I push OK 
    ExitLoop                               ;        but I dont know how to code it??
EndSwitch
WEnd
; GUI MESSAGE LOOP
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
Link to comment
Share on other sites

I Got it working.

You still need to clear that box that the value is set to however. Couldn't really find it in all these swedish names.

Please notice all the changes I've made, as I've made all the same newbie mistakes :)

#include <GuiConstants.au3>

Global Const $CBS_DROPDOWNLIST = 0x0003
Dim $0t = 95, $0l = 75, $0j = 40, $0v = 40;Klubbmän
Dim $1t = 145, $1l = 70, $1j = 85, $1v = 40;Spjutmän
Dim $2t = 130, $2l = 120, $2j = 170, $2v = 70;Yxmän
Dim $3t = 160, $3l = 100, $3j = 50, $3v = 50;Scout
Dim $4t = 370, $4l = 270, $4j = 290, $4v = 75;Paladin
Dim $5t = 450, $5l = 515, $5j = 480, $5v = 80;Germansk Knekt
Dim $6t = 1000, $6l = 300, $6j = 350, $6v = 70;Murbräcka
Dim $7t = 900, $7l = 1200, $7j = 600, $7v = 60;Katapult
Dim $8t = 35500, $8l = 26600, $8j = 25000, $8v = 27200;Stamledare
Dim $1t = 7200, $1l = 5500, $1j = 5800, $1v = 6500;Nybyggare

Global $multiplied = 0

GuiCreate("Travian - Germaner", 350, 150)

GuiCtrlCreateLabel("Trupptyp:", 25, 5)
$trupp = GuiCtrlCreatecombo("Välj...", 25, 20, 120, 100, $CBS_DROPDOWNLIST)
GUICtrlSetData($trupp,"Klubbmän|Spjutmän|Yxmän|Scout|Paladin|Germansk Knekt|Murbräcka|Katapult|Stamledare|Nybyggare")

GuiCtrlCreateLabel("Antal:", 183, 5)
$antal = GuiCtrlCreateInput("", 183, 20, 50, 20);<---- Input
$UpDown = GuiCtrlCreateUpDown($antal)

$knapp = GuiCtrlCreateButton("OK", 265, 19, 60, 22)

GuiCtrlCreateLabel("Trä", 45, 54)
$tree = GuiCtrlCreateInput("", 30, 74, 50, 20)

GuiCtrlCreateLabel("Lera", 123, 54)
$lera = GuiCtrlCreateInput("", 110, 74, 50, 20)

GuiCtrlCreateLabel("Järn", 204, 54)
$iron = GuiCtrlCreateInput("", 190, 74, 50, 20)

GuiCtrlCreateLabel("Vete", 283, 54)
$vete = GuiCtrlCreateInput("", 270, 74, 50, 20)

GuiCtrlCreateLabel("Summa Råvaror", 137, 100)
$summa = GuiCtrlCreateInput("", 150, 120, 50, 20)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        case $GUI_EVENT_CLOSE
            ExitLoop
        Case $knapp
            If GUICtrlRead($trupp, 1) = "Välj..." Then
                MsgBox(0,"Fel", "Välj Trupptyp och Antal")
            EndIf
            If GUICtrlRead($trupp, 1) = "Klubbmän" Then
                $multiplied = $0t * $antal
                GUICtrlSetData($tree, $multiplied, 0); <--- This is wrong. I'd like to multiply $0t with
            EndIf                                ;    $antal(input) and then post it in $tree when I push OK 
    ;       but I dont know how to code it??
EndSwitch
WEnd
Edited by Edifice
Link to comment
Share on other sites

I Got it working.

You still need to clear that box that the value is set to however. Couldn't really find it in all these swedish names.

Please notice all the changes I've made, as I've made all the same newbie mistakes :)

I didn't get it to work at all.

ERROR: $CBS_DROPDOWNLIST previously declared as a 'Const'

And if I delete that declaration it works but for some reason $antal allways returns 6 no matter what the UpDown input is set to.

Edited by Scinner
Link to comment
Share on other sites

If you're using the script by Edifice then $antal is only a Control ID. You need GuiCtrlRead to get whatever is in the input.

I figured that out and made it work.

Thanks a bunch Edifice for pointing me in the right direction.

#include <GuiConstants.au3>

;$CBS_DROPDOWNLIST = 0x0003
Dim $0t = 95, $0l = 75, $0j = 40, $0v = 40;Klubbmän
Dim $1t = 145, $1l = 70, $1j = 85, $1v = 40;Spjutmän
Dim $2t = 130, $2l = 120, $2j = 170, $2v = 70;Yxmän
Dim $3t = 160, $3l = 100, $3j = 50, $3v = 50;Scout
Dim $4t = 370, $4l = 270, $4j = 290, $4v = 75;Paladin
Dim $5t = 450, $5l = 515, $5j = 480, $5v = 80;Germansk Knekt
Dim $6t = 1000, $6l = 300, $6j = 350, $6v = 70;Murbräcka
Dim $7t = 900, $7l = 1200, $7j = 600, $7v = 60;Katapult
Dim $8t = 35500, $8l = 26600, $8j = 25000, $8v = 27200;Stamledare
Dim $9t = 7200, $9l = 5500, $9j = 5800, $9v = 6500;Nybyggare

Global $multiplied = 0

GuiCreate("Travian - Germaner", 350, 150)

GuiCtrlCreateLabel("Trupptyp:", 25, 5)
$trupp = GuiCtrlCreatecombo("Välj...", 25, 20, 120, 100, $CBS_DROPDOWNLIST)
GUICtrlSetData($trupp,"Klubbmän|Spjutmän|Yxmän|Scout|Paladin|Germansk Knekt|Murbräcka|Katapult|Stamledare|Nybyggare")

GuiCtrlCreateLabel("Antal:", 183, 5)
$antal = GuiCtrlCreateInput("0", 183, 20, 50, 20);<---- Input
$updown = GuiCtrlCreateUpDown($antal)

$knapp = GuiCtrlCreateButton("OK", 265, 19, 60, 22)

GuiCtrlCreateLabel("Trä", 45, 54)
$tree = GuiCtrlCreateInput("", 30, 74, 50, 20)

GuiCtrlCreateLabel("Lera", 123, 54)
$lera = GuiCtrlCreateInput("", 110, 74, 50, 20)

GuiCtrlCreateLabel("Järn", 204, 54)
$iron = GuiCtrlCreateInput("", 190, 74, 50, 20)

GuiCtrlCreateLabel("Vete", 283, 54)
$vete = GuiCtrlCreateInput("", 270, 74, 50, 20)

GuiCtrlCreateLabel("Summa Råvaror", 137, 100)
$summa = GuiCtrlCreateInput("", 150, 120, 50, 20)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        case $GUI_EVENT_CLOSE
            ExitLoop
        Case $knapp
            If GUICtrlRead($trupp, 0) = "Välj..." Then
                MsgBox(0,"Fel", "Välj Trupptyp och Antal")
            EndIf
            If GUICtrlRead($trupp, 0) = "Klubbmän" Then
                $multiplied = $0t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $0l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $0j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $0v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $0t * GUICtrlRead($antal) + $0l * GUICtrlRead($antal) + $0j * GUICtrlRead($antal) + $0v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Spjutmän" Then
                $multiplied = $1t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $1l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $1j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $1v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $1t * GUICtrlRead($antal) + $1l * GUICtrlRead($antal) + $1j * GUICtrlRead($antal) + $1v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Yxmän" Then
                $multiplied = $2t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $2l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $2j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $2v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $2t * GUICtrlRead($antal) + $2l * GUICtrlRead($antal) + $2j * GUICtrlRead($antal) + $2v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Scout" Then
                $multiplied = $3t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $3l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $3j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $3v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $3t * GUICtrlRead($antal) + $3l * GUICtrlRead($antal) + $3j * GUICtrlRead($antal) + $3v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Paladin" Then
                $multiplied = $4t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $4l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $4j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $4v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $4t * GUICtrlRead($antal) + $4l * GUICtrlRead($antal) + $4j * GUICtrlRead($antal) + $4v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Germansk Knekt" Then
                $multiplied = $5t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $5l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $5j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $5v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $5t * GUICtrlRead($antal) + $5l * GUICtrlRead($antal) + $5j * GUICtrlRead($antal) + $5v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Murbräcka" Then
                $multiplied = $6t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $6l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $6j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $6v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $6t * GUICtrlRead($antal) + $6l * GUICtrlRead($antal) + $6j * GUICtrlRead($antal) + $6v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Katapult" Then
                $multiplied = $7t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $7l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $7j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $7v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $7t * GUICtrlRead($antal) + $7l * GUICtrlRead($antal) + $7j * GUICtrlRead($antal) + $7v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Stamledare" Then
                $multiplied = $8t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $8l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $8j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $8v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $8t * GUICtrlRead($antal) + $8l * GUICtrlRead($antal) + $8j * GUICtrlRead($antal) + $8v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
            If GUICtrlRead($trupp, 0) = "Nybyggare" Then
                $multiplied = $9t * GUICtrlRead($antal)
                GUICtrlSetData($tree, $multiplied)
                $multiplied = $9l * GUICtrlRead($antal)
                GUICtrlSetData($lera, $multiplied)
                $multiplied = $9j * GUICtrlRead($antal)
                GUICtrlSetData($iron, $multiplied)
                $multiplied = $9v * GUICtrlRead($antal)
                GUICtrlSetData($vete, $multiplied)
                $multiplied = $9t * GUICtrlRead($antal) + $9l * GUICtrlRead($antal) + $9j * GUICtrlRead($antal) + $9v * GUICtrlRead($antal)
                GUICtrlSetData($summa, $multiplied)
            EndIf
EndSwitch
WEnd
Link to comment
Share on other sites

Hi! Need some assistance again.

I have modyfied the script and added another function and ran in to some problems.

First off, the combo wont display anything at startup if I dont select a radio button first. How do I solve that?

Second, when I have selected "Trupptyp" (Trooptype) and "Antal" (Quantity) and press the OK button nothing happends. How do I solve that?

Would really appreciate some help!

[autoit]#include <GuiConstants.au3>

$CBS_DROPDOWNLIST = 0x0003

;Germaner

Dim $0t = 95, $0l = 75, $0j = 40, $0v = 40;Klubbm

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...