Jump to content

Script just stops


Recommended Posts

Ok this worked just fine a minute ago, now once it gets to the Switch it will go through it once maybe then stop. anyone see anything wrong?

;Launch a Program
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit ; Close if [X] is clicked
            Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE) ; Minimize Window
            Case $Exit
                ExitLoop ; Close Window if File -> Exit is clicked
            Case $Reset
                Reset() ; Reset INI File
            Case $Update
                Update() ; Update to newest version of Game Launcher
            Case $Setup
                Setup() ; Setup Game launcher
            Case $Save
                Save() ; Save new button
            Case $Browse
                $Browser = FileOpenDialog("Please Select A Game Executable", @ProgramFilesDir,"Executables (*.exe)",1 + 2)
            If @error = 1 Then
                WinKill("Please Select A Game Executable")
                WinActivate("Game Launcher v" & $ver)
            EndIf
            GUICtrlSetData($NewPath_, $Browser)
                Sleep(3000)
    EndSwitch
            ;When Button is clicked, execute selected file
        For $p = 1 To $Progs
            If $nMsg = $Program_[$p] Then
                Run($Path_[$p][1])
                Sleep(3000)
                ExitLoop
            EndIf
        Next
    WEnd

EDIT: I found a problem but i dont know how to fix it, basically it wont exit the For loop.

Also i dont think its doing the while right, even with for loop commented out it stop

Edited by Mast3rpyr0
Link to comment
Share on other sites

Here is the whole script(Probably screwed it up trying to fix it lol):

;--------------------------------------------------------------------------------------
;            Game Launcher will allow a user to Manage and Launch              |
;                     Games from an Easy to Use GUI                |
;                                                                 |
;--------------------------------------------------------------------------------------

;Includes
#include <GUIConstants.au3>
#include <Constants.au3>
#include <array.au3>
#include <File.au3>

;Set vars
Global $ConfigINI = @ScriptDir & "\Config.ini" ; Set Location of INI file
Global $ver = IniRead($ConfigINI, "Version", "ver", "Not Found") ; Load Version ID into $ver
Global $Progs = IniRead($ConfigINI, "Progs", "num", "Not Found") ; Load Number of Progs from INI into $Progs
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name") ; Set Program Names to $Name_ Array
Global $Path_ = IniReadSection($ConfigINI, "Path") ; Set Program Paths to $Path_ Array
Global $New_name_ = IniRead($ConfigINI, "New", "name", "Not Found") ; Set Setup Variable Name to $New_name_
Global $New_path_ = IniRead($ConfigINI, "New", "path", "Not Found") ; Set Setup Variable Path to $New_path_

;Create GUI
$i = 1 ; program number
$x = 25 ; Horizontal position of buttons
$y = 80 ; vertiacl position of buttons
$MainWindow = GUICreate("Game Launcher v" & $ver, 415, 290) ; Create Main Window
$Tab1 = GUICtrlCreateTab(0, 0, 417, 273) ;Create Tab
$GamesTab = GUICtrlCreateTabItem("            Games            ");===>Games Tab
;Output some text here

For $x = 1 To $Progs
    $Program_[$i] = GUICtrlCreateButton($Name_[$i][1], $x, $y, 120, 17) ; Create and Position Buttons
    $i = $i + 1 ; Move to next Program
    $y = $y + 35 ; Move button down 35 pixels
Next

$SetupTab = GUICtrlCreateTabItem("            Setup            ");===>Setup Tab
;Output some text here
Global $NewPath_ = GUICtrlCreateInput($New_path_, 110, 78, 200, 20, -1)
Global $NewName_ = GUICtrlCreateInput($New_name_, 110, 113, 150, 20, -1)
$Browse = GUICtrlCreateButton("Browse", 320, 78, 50, 20)
GUICtrlCreateLabel("Program:", 25, 80, 60, 20)
GUICtrlCreateLabel("Name:", 25, 115, 60, 20)
$Save = GUICtrlCreateButton("Save New Button", 150, 160, 100)
GUICtrlSetOnEvent($Save, "Save")

;Create Menu
$File = GUICtrlCreateMenu("File") ; Create File drop down Menu
$Exit = GUICtrlCreateMenuItem("Exit", $File) ; Add Exit option in File Drop down
$Options = GUICtrlCreateMenu("Options") ; Create Options drop down Menu
$Update = GUICtrlCreateMenuItem("Update", $Options) ; Add Update option to Options drop down
$Reset = GUICtrlCreateMenuItem("Reset", $Options) ; Add Reset option to Options drop down
$Help = GUICtrlCreateMenu("Help") ; Create Help drop down Menu
$HelpFile = GUICtrlCreateMenuItem("Help", $Help) ; Add Help File option to Help drop down
$About = GUICtrlCreateMenuItem("About", $Help) ; Add About to Help drop down
GUISetState(@SW_SHOW) ; Show Window


;Launch a Program
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        ;MsgBox(0, "test", $nMsg)
        Case $GUI_EVENT_CLOSE
            Exit ; Close if [X] is clicked
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_HIDE) ; Minimize Window
        Case $Exit
            ExitLoop ; Close Window if File -> Exit is clicked
        Case $Reset
            Reset() ; Reset INI File
        Case $Update
            ;Update () ; Update to newest version of Game Launcher
        Case $Save
            Save() ; Save new button
        Case $Browse
            $Browser = FileOpenDialog("Please Select A Game Executable", @ProgramFilesDir, "Executables (*.exe)", 1 + 2)
            If @error = 1 Then
                WinKill("Please Select A Game Executable")
                WinActivate("Game Launcher v" & $ver)
            EndIf
            GUICtrlSetData($NewPath_, $Browser)
    EndSwitch
    ;If Button is clicked, execute selected file
    For $i = 1 To $Progs
        ;MsgBox(0,"test", "test")
        If $nMsg = $Program_[$i] Then
            Run($Path_[$i][1])
            Sleep(3000)
            ExitLoop
        EndIf
    Next
WEnd




;Functions
Func Reset()
    $Reset_ = MsgBox(4, "Reset Game Launcher v" & $ver, "Are you sure you want to Reset Gamer Launcher v" & $ver & "?")
    MsgBox(0, "Reset Game Launcher v" & $ver, $Reset_)
    If $Reset_ = 6 Then
        IniWrite($ConfigINI, "Progs", "num", "1")
    Else
    EndIf
EndFunc   ;==>Reset


Func Save()
    Dim $splitNewPath_, $szDrive, $szDir, $szFName, $szExt
    $splitNewPath_ = _PathSplit($NewPath_, $szDrive, $szDir, $szFName, $szExt)
    If $splitNewPath_ = "" Then
        MsgBox(0, "Error", "Please select a file with a correct Path")
    Else
        IniWrite($ConfigINI, "Path", $Progs + 1, GUICtrlRead($NewPath_))
        IniWrite($ConfigINI, "Name", $Progs + 1, GUICtrlRead($NewName_))
        IniWrite($ConfigINI, "Progs", "num", $Progs + 1)
        MsgBox(0, "Buttons Created", "New Button Created." & @CRLF & "Please restart Game Launcher v" & $ver & " for changes to take affect.")
    EndIf
EndFunc   ;==>Save

INI in @ScriptDir & "\Config.ini":

[Version]
ver=1.0

[Progs]
num=1

[Name]
1=IE

[Path]
1=C:\Program Files\Internet Explorer\iexplore.exe

[New]
name=Enter Name for Program
path=Enter Program Path

EDIT: Now using MadBoy's version of my script

Edited by Mast3rpyr0
Link to comment
Share on other sites

;--------------------------------------------------------------------------------------
;            Game Launcher will allow a user to Manage and Launch              |
;                     Games from an Easy to Use GUI                |
;                                                                 |
;--------------------------------------------------------------------------------------

;Includes
#include <GUIConstants.au3>
#include <Constants.au3>
#include <array.au3>
#include <File.au3>

;Set vars
Global $ConfigINI = @ScriptDir & "\script.ini" ; Set Location of INI file
Global $ver = IniRead($ConfigINI, "Version", "ver", "Not Found") ; Load Version ID into $ver
Global $Progs = IniRead($ConfigINI, "Progs", "num", "Not Found") ; Load Number of Progs from INI into $Progs
Global $Program_[$Progs + 1] ; Array to hold button control IDs
Global $Name_ = IniReadSection($ConfigINI, "Name") ; Set Program Names to $Name_ Array
Global $Path_ = IniReadSection($ConfigINI, "Path") ; Set Program Paths to $Path_ Array
Global $New_name_ = IniRead($ConfigINI, "New", "name", "Not Found") ; Set Setup Variable Name to $New_name_
Global $New_path_ = IniRead($ConfigINI, "New", "path", "Not Found") ; Set Setup Variable Path to $New_path_

;Create GUI
$i = 1 ; program number
$x = 25 ; Horizontal position of buttons
$y = 80 ; vertiacl position of buttons
$MainWindow = GUICreate("Game Launcher v" & $ver, 415, 290) ; Create Main Window
$Tab1 = GUICtrlCreateTab(0, 0, 417, 273) ;Create Tab
$GamesTab = GUICtrlCreateTabItem("            Games            ");===>Games Tab
;Output some text here

For $x = 1 To $Progs
    $Program_[$i] = GUICtrlCreateButton($Name_[$i][1], $x, $y, 120, 17) ; Create and Position Buttons
    $i = $i + 1 ; Move to next Program
    $y = $y + 35 ; Move button down 35 pixels
Next

$SetupTab = GUICtrlCreateTabItem("            Setup            ");===>Setup Tab
;Output some text here
Global $NewPath_ = GUICtrlCreateInput($New_path_, 110, 78, 200, 20, -1)
Global $NewName_ = GUICtrlCreateInput($New_name_, 110, 113, 150, 20, -1)
$Browse = GUICtrlCreateButton("Browse", 320, 78, 50, 20)
GUICtrlCreateLabel("Program:", 25, 80, 60, 20)
GUICtrlCreateLabel("Name:", 25, 115, 60, 20)
$Save = GUICtrlCreateButton("Save New Button", 150, 160, 100)
GUICtrlSetOnEvent($Save, "Save")

;Create Menu
$File = GUICtrlCreateMenu("File") ; Create File drop down Menu
$Exit = GUICtrlCreateMenuItem("Exit", $File) ; Add Exit option in File Drop down
$Options = GUICtrlCreateMenu("Options") ; Create Options drop down Menu
$Update = GUICtrlCreateMenuItem("Update", $Options) ; Add Update option to Options drop down
$Reset = GUICtrlCreateMenuItem("Reset", $Options) ; Add Reset option to Options drop down
$Help = GUICtrlCreateMenu("Help") ; Create Help drop down Menu
$HelpFile = GUICtrlCreateMenuItem("Help", $Help) ; Add Help File option to Help drop down
$About = GUICtrlCreateMenuItem("About", $Help) ; Add About to Help drop down
GUISetState(@SW_SHOW) ; Show Window


;Launch a Program
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        ;MsgBox(0, "test", $nMsg)
        Case $GUI_EVENT_CLOSE
            Exit ; Close if [X] is clicked
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_HIDE) ; Minimize Window
        Case $Exit
            ExitLoop ; Close Window if File -> Exit is clicked
        Case $Reset
            Reset() ; Reset INI File
        Case $Update
            ;Update () ; Update to newest version of Game Launcher
        Case $Save
            Save() ; Save new button
        Case $Browse
            $Browser = FileOpenDialog("Please Select A Game Executable", @ProgramFilesDir, "Executables (*.exe)", 1 + 2)
            If @error = 1 Then
                WinKill("Please Select A Game Executable")
                WinActivate("Game Launcher v" & $ver)
            EndIf
            GUICtrlSetData($NewPath_, $Browser)
    EndSwitch
    ;If Button is clicked, execute selected file
    For $i = 1 To $Progs
        ;MsgBox(0,"test", "test")
        If $nMsg = $Program_[$i] Then
            Run($Path_[$i][1])
            Sleep(3000)
            ExitLoop
        EndIf
    Next
WEnd




;Functions
Func Reset()
    $Reset_ = MsgBox(4, "Reset Game Launcher v" & $ver, "Are you sure you want to Reset Gamer Launcher v" & $ver & "?")
    MsgBox(0, "Reset Game Launcher v" & $ver, $Reset_)
    If $Reset_ = 6 Then
        IniWrite($ConfigINI, "Progs", "num", "1")
    Else
    EndIf
EndFunc   ;==>Reset


Func Save()
    Dim $splitNewPath_, $szDrive, $szDir, $szFName, $szExt
    $splitNewPath_ = _PathSplit($NewPath_, $szDrive, $szDir, $szFName, $szExt)
    If $splitNewPath_ = "" Then
        MsgBox(0, "Error", "Please select a file with a correct Path")
    Else
        IniWrite($ConfigINI, "Path", $Progs + 1, GUICtrlRead($NewPath_))
        IniWrite($ConfigINI, "Name", $Progs + 1, GUICtrlRead($NewName_))
        IniWrite($ConfigINI, "Progs", "num", $Progs + 1)
        MsgBox(0, "Buttons Created", "New Button Created." & @CRLF & "Please restart Game Launcher v" & $ver & " for changes to take affect.")
    EndIf
EndFunc   ;==>Save

I have changed the path of your .ini file (as i was too lazy to create all those dirs) and have changed some of the loops. Works for me when i create new program for new button. Dunno if that's what you wanted. Also i have moved functions to the bottom of the script for easier use.

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

ok well i guess this is either harder than i thought or its just my computer. Anyone one mind compiling and testing see if you can exit with the File > Exit option?

It's not your computer!

Read the help file for GuiCtrlCreateTabItem

To create a new control on an existing tabitem use GUISwitch($hWin,$tabitem) to select it and just create your new control. Don't forget to close your tabitem creation with GUICtrlCreateTabItem("").

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...