Jump to content

Closed


Recommended Posts

Ok so i have this loop at the bottom of my script that will run through my array and set up each button on the screen

Basicaly if there is more than one program set in the $Programs_ array it will keep launching the second one.

Any ideas of fixes?

GameLaunch.au3

;--------------------------------------------------------------------------------------
;            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>
#include <INetUpdater.au3>

;Set vars
Global $ConfigINI = @ScriptDir & "\Config.ini" ; Set Location of INI file
Global $ver = IniRead($ConfigINI, "Version", "ver", "0") ; Load Version ID into $ver
Global $Progs = IniRead($ConfigINI, "Progs", "num", 0) ; 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_ = "Enter Program Name"
Global $New_path_ = "Enter Program Path"
Global $DefaultINI = "[Version]" & @CRLF & $ver & @CRLF & @CRLF & "[Progs]" & @CRLF & "num=0" & @CRLF & @CRLF & "[Name]" & @CRLF & @CRLF & "[Path]" & @CRLF


;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
GUICtrlCreateLabel("Select a game to Execute", 150, 45)
While $i < $Progs
    $Program_[$i] = GUICtrlCreateButton($Name_[$i][1], $x, $y, 120, 22) ; Create and Position Buttons
    $i = $i + 1 ; Move to next Program
    $y = $y + 35 ; Move button down 35 pixels
WEnd

$SetupTab = GUICtrlCreateTabItem("            Setup            ");===>Setup Tab
GUICtrlCreateLabel("Create a new Launch Button", 150, 45)
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")
GUICtrlCreateTabItem("")

;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
If $Progs = 0 Then
    GUICtrlSetState($SetupTab, $GUI_SHOW)
    GUISetState(@SW_SHOW)
Else
    GUISetState(@SW_SHOW)
EndIf

;Launch a Program
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        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 Buttons information
        Case $Browse
            Global $Browser = FileOpenDialog("Please Select A Game Executable", @ProgramFilesDir, "Executables (*.exe)", 1 + 2)
            GUICtrlSetData($NewPath_, $Browser)
        EndSwitch
        For $p = 1 To $Progs
            If $nMsg = $Program_[$p] Then
                Run($Path_[$p][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 Game Launcher v" & $ver & "?")
    If $Reset_ = 6 Then
        FileOpen($ConfigINI, 2)
        FileWrite($ConfigINI, $defaultINI)
        FileClose($ConfigINI)
        MsgBox(0, "Reset Complete", "Game Launcher v" & $ver & " will now shutdown")
        Exit
    Else
    EndIf
EndFunc   ;==>Reset


Func Save()
    If $NewPath_ = "" Or $NewPath_ = "Enter Program Path" 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 & "Game Launcher v" & $ver & " will now shutdown")
        Exit
    EndIf
EndFunc   ;==>Save

Func Update()
    SplashTextOn("Game Launcher " & $ver, "Checking for updates....", 250, 30, -1, -1, 0)
    _INetUpdater($ver, "http://gamelaunch.bravehost.com/Update", "Version.ini", "Setup.exe")
    SplashOff()
EndFunc ;==>Update

Config.ini

[Version]
ver=Beta

[Progs]
num=2

[Name]
1=Auda1
2=Auda2


[Path]
1=C:\Program Files\Audacity\audacity.exe
2=C:\Program Files\Audacity\audacity.exe

Mast3rpyr0

Edited by Mast3rpyr0
Link to comment
Share on other sites

Well its hard to know what half the variables in the for loop are with a snippet like that but, i think you for loop needs to look like this:

For $i = 0 To $Progs
Link to comment
Share on other sites

hmm nope i get an imideate error that the variable is outa range. Updated the snippet above to the full program

Maybe........ Im still not sure... but i see $progs = the number of programs set by the ini. I think Ubound would be better. Try this.

;--------------------------------------------------------------------------------------
;            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>
#include <INetUpdater.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_ = "Enter Program Name"
Global $New_path_ = "Enter Program 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
GUICtrlCreateLabel("Select a game to Execute", 150, 45)
For $i = 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
GUICtrlCreateLabel("Create a new Launch Button", 150, 45)
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")
GUICtrlCreateTabItem("")

;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
If $Progs = 0 Then
    GUICtrlSetState($SetupTab, $GUI_SHOW)
    GUISetState(@SW_SHOW)
Else
    GUISetState(@SW_SHOW)
EndIf

;Launch a Program
While 1
    $nMsg = GUIGetMsg()
        If $nMsg = $GUI_EVENT_CLOSE Then
            ExitLoop
        ElseIf $nMsg = $GUI_EVENT_MINIMIZE Then
            GUISetState(@SW_HIDE) ; Minimize Window
        ElseIf $nMsg = $Exit Then
            ExitLoop ; Close Window if File -> Exit is clicked
        ElseIf $nMsg = $Reset Then
            Reset() ; Reset INI File
        ElseIf $nMsg = $Update Then
            Update () ; Update to newest version of Game Launcher
        ElseIf $nMsg = $Save Then
            Save() ; Save Buttons information
        ElseIf $nMsg = $Browse Then
            Global $Browser = FileOpenDialog("Please Select A Game Executable", @ProgramFilesDir, "Executables (*.exe)", 1 + 2)
            GUICtrlSetData($NewPath_, $Browser)
        EndIf
            For $i = 0 To UBound($Program_)-1
        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 Game Launcher v" & $ver & "?")
    If $Reset_ = 6 Then
        IniWrite($ConfigINI, "Progs", "num", "0")
        IniDelete ($ConfigINI, "Name")
        IniDelete ($ConfigINI, "Path")
        MsgBox(0, "Reset Complete", "Game Launcher v" & $ver & " will now shutdown")
        Exit
    Else
    EndIf
EndFunc   ;==>Reset


Func Save()
    If $NewPath_ = "" Or $NewPath_ = "Enter Program Path" 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 & "Game Launcher v" & $ver & " will now shutdown")
        Exit
    EndIf
EndFunc   ;==>Save

Func Update()
    SplashTextOn("Game Launcher " & $ver, "Checking for updates....", 250, 30, -1, -1, 0)
    _INetUpdater($ver, "http://gamelaunch.bravehost.com/Update", "Version.ini", "Setup.exe")
    SplashOff()
EndFunc ;==>Update
Link to comment
Share on other sites

Now it says $Path_ isnt an Array

Which technically it isnt when the config is reset.

Ill improve on this function and see what happens

EDIT: Well that didnt do anythign but i think i made my reset a little better, instead of deleting parts of it it now should rewrite the entire thing.

Edited by Mast3rpyr0
Link to comment
Share on other sites

Now it says $Path_ isnt an Array

Which technically it isnt when the config is reset.

Ill improve on this function and see what happens

EDIT: Well that didnt do anythign but i think i made my reset a little better, instead of deleting parts of it it now should rewrite the entire thing.

If you rewrite or just improve you need to be a bit more careful with some things. For example, you had

Global $Progs = IniRead($ConfigINI, "Progs", "num", "Not Found") ; Load Number of Progs from INI into $Progs

This sort of thing can cause problems because you are setting $progs to a string if there are no programs in your ini, and then later you try to use it as an integer. It would be better to have

Global $Progs = IniRead($ConfigINI, "Progs", "num", 0)

and then later only do the for loop if $Progs > 0.

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

For $i = 0 To $Progs -1

it could be if you array is from 1 to 10 then the for loop has to be

from i = 0 to $progs - 1

because the array reads the first value at 0 and the last value at 10 -1>> 9

maybe try that

if you havent already

Edited by tommygun101
Link to comment
Share on other sites

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

"For" loop automatically increments $i, you don't need to do it manually.

"be smart, drink your wine"

Link to comment
Share on other sites

Ok i got the loop working and everything works fine except positioning of buttons. after every 5 i want it to make a new column. It makes the 2nd column for the 6th buttons but on the 7th starts the 3rd column instead of continuing the 2nd until there are 10 buttons.

Heres my If statement that i think should work fine but i guess not.

If $i > 5 And $i < 10 Then
        $x = $x + 140
        $y = 80
        ElseIf $i > 10 And $i < 15 Then
                $x = $x + 140
        $y = 80
        EndIf

Also if this could be made into 1 statement that would be great.

Posted Image

Edited by Mast3rpyr0
Link to comment
Share on other sites

Ok i got the loop working and everything works fine except positioning of buttons. after every 5 i want it to make a new column. It makes the 2nd column for the 6th buttons but on the 7th starts the 3rd column instead of continuing the 2nd until there are 10 buttons.

Heres my If statement that i think should work fine but i guess not.

If $i > 5 And $i < 10 Then
        $x = $x + 140
        $y = 80
        ElseIf $i > 10 And $i < 15 Then
                $x = $x + 140
        $y = 80
        EndIf
oÝ÷ Ø    l¢'í+¢é]méu觶lµ«^éí¶­Â¥u· ­æ­h!¶Úþ-v¶)ò¦'¢oùÞæçyøéø¦ú®¢×¢g­)à²Ø¥+'ßÛkmÂ+a¶­{¦¦W´ß¬b±©l¢IèÂv¬ªê-çíªê-~Úrí®ZÝ7ë(¬¶ËZÇ®­ëh¤ZèZ¶'ÇÊ·ö·¦¢ø§Múŧ+¢Ë5ãJqz÷«É»­¶íéÚ~׫廭¶ì§Ú-éÞÆÚèÂØ^f¤zØ^nëm¢{·¶¨½êí«H¶§*.Á©í²¶§X¤zØb±«­¢+Ù%ÀÌØí¤ÐìÔ¹ÀÌØí¤±ÐìÄÀQ¡¸($ÀÌØíàôÄÐÀ($ÀÌØíä¬ôàÀ)±Í%ÀÌØí¤ÐìÄÀ¹ÀÌØí¤±ÐìÄÔQ¡¸($ÀÌØíàôÈàÀ($ÀÌØíä¬ôàÀ)±Í%ÀÌØí¤ÐìÄÔ¹ÀÌØí¤±ÐìÈÀQ¡¸($ÀÌØíàôÐÈÀ($ÀÌØíä¬ôàÀ)¹%
Link to comment
Share on other sites

mmmm not quite but it did stop button 7 and 8 showing outa place, now it just doesnt show em at all. it will only goto 6 buttons now

could you post the whole part of code that you're currently having trouble with?
Link to comment
Share on other sites

While $i <= $Progs
    $Program_[$i] = GUICtrlCreateButton($Name_[$i][1], $x, $y, 120, 22) ; Create and Position Buttons
    $i = $i + 1 ; Move to next Program
    $y = $y + 35 ; Move button down 35 pixels
If $i > 5 And $i < 10 Then
    $x = 165
    $y = 80
ElseIf $i > 10 And $i < 15 Then
    $x = 305
    $y = 80
ElseIf $i > 15 And $i < 20 Then
    $x = 445
    $y = 80
ElseIf $i < 5 Then
EndIf
WEnd

Link to comment
Share on other sites

  • Developers

While $i <= $Progs
    $Program_[$i] = GUICtrlCreateButton($Name_[$i][1], $x, $y, 120, 22) ; Create and Position Buttons
    $i = $i + 1 ; Move to next Program
    $y = $y + 35 ; Move button down 35 pixels
If $i > 5 And $i < 10 Then
    $x = 165
    $y = 80
ElseIf $i > 10 And $i < 15 Then
    $x = 305
    $y = 80
ElseIf $i > 15 And $i < 20 Then
    $x = 445
    $y = 80
ElseIf $i < 5 Then
EndIf
WEnd
3 things:

1. Don't make promises you can't keep.. :)

2. What is the problem, or do you want us to try and guess ?

3. Would you mind changing the "SHOUTING" Sig ?

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1) After this is fixed its done

2)I think this about says it...

Posted Image

3)Its no bigger than your sig

EDIT: I got it fixed. Thanks for your code bert.

While $i <= $Progs
    $Program_[$i] = GUICtrlCreateButton($Name_[$i][1], $x, $y, 120, 22) ; Create and Position Buttons
    $i = $i + 1 ; Move to next Program
    $y = $y + 35 ; Move button down 35 pixels
If $i == 6 Then
    $x = 165
    $y = 80
ElseIf $i == 11 Then
    $x = 305
    $y = 80
EndIf
WEnd
Edited by Mast3rpyr0
Link to comment
Share on other sites

  • Developers

3)Its no bigger than your sig

Wasn't talking about size of the total sig ..... just about the Bold/FontSize and childishness of it in my humble opinion .

but just do as you please ... :)

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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