IF from GUI input?

05/23/2013 18:15 Shiw#1
Hi started coding autoit yesterday and created a small project for a game I play.

The GUI works fine but the IF statement does not seem to read the inputs correctly. What have I done wrong? Take in mind I started yesterday so if things could be explained that would be great. Thanks for your time :handsdown:

Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{END}", "Terminate")
#Region ### START Koda GUI section ### Form=
$craftool = GUICreate("SWG Crafting Script", 319, 206, 438, 229)
GUISetBkColor(0xBFCDDB)
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 297, 193)
GUICtrlSetBkColor(-1, 0x3399FF)
$Input1 = GUICtrlCreateInput("", 152, 32, 137, 21)
$Input2 = GUICtrlCreateInput("", 152, 72, 137, 21)
$Output = GUICtrlCreateInput("", 152, 112, 137, 21)
$Button3 = GUICtrlCreateButton("Calculate", 112, 144, 81, 33)
$Label1 = GUICtrlCreateLabel("Xerco's SWG Crafting Script v0.3", 16, 16, 161, 17)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$Label2 = GUICtrlCreateLabel("Input Crafting Exp per Item", 16, 40, 129, 17)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$Label3 = GUICtrlCreateLabel("Max Skill Experiance", 16, 72, 102, 17)
GUICtrlSetBkColor(-1, 0xBFCDDB)
$Label4 = GUICtrlCreateLabel("Items Left To Craft", 16, 112, 114, 17)
GUICtrlSetBkColor(-1, 0xBFCDDB)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $timesCraft, $itemExp , $maxExp, $data3, $ReadT1, $ReadT2, $peakExp, $timesCraft, $macro
While 1
	$peakExp = $maxExp * 1.5
	$nMsg = GUIGetMsg()
	$ReadI1 = GUICtrlRead($Input1)
	$ReadI2 = GUICtrlRead($Input2)
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Input1
			 $itemExp = GUICtrlRead($Input1)
			GUICtrlSetData($Input1, $itemExp)
		Case $Input2
			 $maxExp = GUICtrlRead($Input2)
			GUICtrlSetData($Input2, $maxExp)
		Case $Button3
			$timesCraft = GUICtrlRead($Output)
			GUICtrlSetData($Output, $peakExp / $itemExp)

	If $macro < 7 And $timesCraft > 0 Then
		WinActivate("SwgClient", "")
		Send($macro)
		Sleep(2000)
		MouseClick ( "left" , 160, 290, 2 )
		Sleep(2000)
		MouseClick ( "left" , 160, 290, 4 )
		Sleep(2000)
		Send("{ESC}")
		Sleep(500)
		Send("{ESC}")
		Sleep(500)
		Send("{ESC}")
		$timesCraft = $timesCraft - 1
		$macro = $macro + 1
			If $macro < 7 Then
			$macro = 1
		EndIf
EndIf
	EndSwitch
WEnd

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc
05/23/2013 20:21 .yorliK#2
Quote:
Originally Posted by Shiw View Post

While 1
$peakExp = $maxExp * 1.5
$nMsg = GUIGetMsg()
$ReadI1 = GUICtrlRead($Input1)
$ReadI2 = GUICtrlRead($Input2)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Input1
$itemExp = GUICtrlRead($Input1)
GUICtrlSetData($Input1, $itemExp)
Case $Input2
$maxExp = GUICtrlRead($Input2)
GUICtrlSetData($Input2, $maxExp)
Case $Button3
$timesCraft = GUICtrlRead($Output)
GUICtrlSetData($Output, $peakExp / $itemExp)
It seems that you give Input1 and Input 2 the order to SetData themself..

You can make new Buttons like $Button1 and $Button2 to SetData Input1 and Input2.

Type 1

Hope its like you want it..

MfG
Kilroy.
05/23/2013 22:28 Shiw#3
Ahh ok yeah I understand what went wrong. New to autoit and first time iv played around with a GUI ever.

The
Code:
If $macro < 7 And $timesCraft > 0 Then
does not seem to work even when the var $timesCraft has a greater number then 0. I also realised each time it completes the loop it resets the values as they are recalculated each time. How should I go about keeping the loop going but not recalculating the input 1 and input 2 values.

Each time the macro completes it should $timesCraft = $timesCraft - 1 until > 0
05/23/2013 23:10 WJNeeson#4
press f1 in scite and search for following functions:

do until
for next

maybe this will help u
05/23/2013 23:56 Shiw#5
Quote:
Originally Posted by #System View Post
press f1 in scite and search for following functions:

do until
for next

maybe this will help u
So many statements lol, thanks for pointing this out looks like what I was looking for.

Il post back with updated script.