Jump to content

Save FileSelectFolder for next program start


Recommended Posts

Hello Autoit Community,

as always i´m a total beginner in coding & autoit this is my first programing after hello world :D, so please be patient.

Im trying to build a .exe to let people join a server with specific parameters.

Works fine as long as i define the path to the server exe:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Icon=beon.ico
#AutoIt3Wrapper_Outfile=BeON.exe
#AutoIt3Wrapper_Outfile_x64=BeON.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Description=BeON Community Launcher for DOBs Arma 3 Server #2
#AutoIt3Wrapper_Res_Fileversion=1.0.3.0
#AutoIt3Wrapper_Res_LegalCopyright=www.BeON.pw
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Local $hMainGUI = GUICreate("BeON - Community Launcher", 450, 167)
Local $oIE = _IECreateEmbedded() ; update (IE)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
GUICtrlCreateObj($oIE, 315, 130, 260, 37) ;updates seite aufrufen größe fenster
GUICtrlCreateLabel("Please select the BeON-Server you want to join:", 110, 20)
GUICtrlCreateLabel("___________________________________________________________________________", 0, 110)
GUICtrlCreateLabel("Your Version: 1.0.3", 218, 133)
GUICtrlCreateLabel("Visit us online www.BeON.pw", 162, 151)
; Server Button
Local $iOKButton = GUICtrlCreateButton("Join BeON  Server #1", 125, 50, 200)
GUICtrlSetOnEvent($iOKButton, "OKButton")
; Server Button ende
; Webiste Button
Local $website = GUICtrlCreateButton("Whats new ?", 125, 80, 200)
GUICtrlSetOnEvent($website, "website")
_IENavigate($oIE, "http://launcher.beon.pw/")
_IEAction($oIE, "stop")
; Website button ende
GUISetState(@SW_SHOW, $hMainGUI)
While 1
    Sleep(100) ;da gehste schlafen
WEnd
;Start -> Servere  Starten + Verbinen zu Server
Func OKButton()
    ShellExecute("C:\Program Files (x86)\XXXX\XXXX\server.exe", "0 0 -skipintro -mod=@mas18; -noSplash -noFilePatching -world=empty -connect=85.190.162.190 -port=2302")
EndFunc
;ENDE -> Arma 3 Starten
;Start -> Website
Func website()
    ShellExecute("http://beon.pw/")
EndFunc
;ENDE -> Website
Func CLOSEButton()
    Exit
EndFunc



But the user always store the server.exe in a different directory. So i searched the wiki and found the "FileSelectFolder function" to let the user select their directory. This works great:

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
    Local Const $sMessage = "Select a folder"

    ; Display an open dialog to select a file.
    Local $sFileSelectFolder = FileSelectFolder($sMessage, "")& "\hello.bat" ; just for tests, server.exe lator
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
        ShellExecute($sFileSelectFolder)
    EndIf
EndFunc   ;==>Example



But they have to select the folder everytime they launch the .exe thats not exactly what i was looking for.

So my question:

How to set this to: Only ask at first program launch and use the selected path evrey time they launch the program from now on ?

Or build a button wich says "select your server path", and stores the given path until you cklick the button again.

Thanks for your help.

kind regards BeON - Dominik

Edited by beon
Link to comment
Share on other sites

Game automation is prohibed here :/

Still i dont know if it is game automation or not since you just automate the start of an application...

I guess you wont get any help here about this.

For help you i'm just gonna say you got the logic already .... you answered to your question by yourself saying the logic.

You just have to found a way on how to do it in the help file ;)

 

build a button = GuiCtrlCreat ===> Helpfile

You can Use a $Var1 or $VarX to use any Control if you want to call them again later using this autoit Code :

Legende: X = your own characters

$VarX = GuiCtrlCreatXxxx

Then you will have to check the "Switch" in help file.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Okay thank you verry much.

I will try to get this working with you provided information.

Sorry for posting something that is prohibited, didnt knew that.

Edited by beon
Link to comment
Share on other sites

I don't know if this will be judged as game automation, the mods will decide.

I to use the FileSelectFolder in a few of my programs, and for me too, its a tiny problem that the users have to specify the same path all the time, so I will monitor this thread for an anserw for that :) I haven't yet tried to solve it but If I can come up with something I will share it with you, but myself is a beginner as well.

I'm sure it can be stored in a variable somehow

Edit: I think it can be done with the initial dir (optional) parameter, it would display the fullpath, which (from hre on I just guess) we should be able to save to somewhere(clipboard maybe? save it from clipboard and the clear clipboard?) and then save that in to your program for futre use

Edited by SorryButImaNewbie
Link to comment
Share on other sites

Well ok it s quit simple ...

$Var1 = FileSelectFolder ()

To stick to the topic maker exemple :

ShellExecute( $Var1 & "" , "0 0 -skipintro -mod=@mas18; -noSplash -noFilePatching -world=empty -connect=85.190.162.190 -port=2302")

This is how to get this fileselect in a Variable.

 

If you want an exemple about the exemple used in the help file you have to change

$Var1

by

$sFileSelectFolder

And also if you use the exemple function to use it in your script you have to change

Local $sFileSelectFolder = FileSelectFolder($sMessage, "")

by

Global $sFileSelectFolder = FileSelectFolder($sMessage, "")

Func Example()
    ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
    Local Const $sMessage = "Select a folder"

    ; Display an open dialog to select a file.
    Local $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
    EndIf
EndFunc   ;==>Example

If you want to setup a buttom for this

Change the function name as somthing like

Func SelectFolder()

When you make a GUI you have to get a switch...

You make your own buttom

$SelectFolder = GUICtrlCreateButton("Select Folder", 360, 175, 70, 20)

Switch
    Case $SelectFolder 
              SelectFolder()
EndSwitch

And the modified function :

Func SelectFolder()
    ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
    Local Const $sMessage = "Select a folder"

    ; Display an open dialog to select a file.
    Global $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
    EndIf
EndFunc   ;==>Example

All is here, HF





			
				


	Edited  by caramen
	
	

			
		

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

if you mean to the script user's have to not set this up after each script run you have to store it differently.

Somthing like in a INI file then here you have to use a differente way ...

 

You can keep the modified exemple of the help file like this (AND ADD An INIWRITE in the exemple function : )

Func SelectFolder()
    ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
    Local Const $sMessage = "Select a folder"

    ; Display an open dialog to select a file.
    Global $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
        Global $WhereisFolder = IniWrite ($SettingsFile, 'Folder', 'Location', $sFileSelectFolder )
    EndIf
EndFunc

Plz watch how to use IniFile in the Helpfile you dont got all info here. But check this line :

Global $WhereisFolder = IniWrite ($SettingsFile, 'Folder', 'Location', $sFileSelectFolder )

Ps : I am just helping your logic. You have to add much more lines of code to make this work, but you got at least, a way to do what you want depending on witch way you gonna choose.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

i would go

Global $sFileSelectFolder = 0


;Code



Func SelectFolder()
    ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
    Local Const $sMessage = "Select a folder"
if $sFileSelectFolder  = 0 then
    ; Display an open dialog to select a file.
    $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
    EndIf
endif
EndFunc   ;==>Example

then on runs after first, if file was selected, you can continue without selecting again.

P.S. next program loads (after exiting) - yes, what caramen said - ini

Edited by Zobengrauzis
Link to comment
Share on other sites

i would go

Global $sFileSelectFolder = 0


;Code



Func SelectFolder()
    ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
    Local Const $sMessage = "Select a folder"
if $sFileSelectFolder  = 0 then
    ; Display an open dialog to select a file.
    $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
    EndIf
endif
EndFunc   ;==>Example

then on runs after first, if file was selected, you can continue without selecting again.

P.S. next program loads (after exiting) - yes, what caramen said - ini

I whould do same ;) But i wont make the total code for them since they have to learn. The variable declaration is a basic.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Thanks for all the Help, i will try to get it done.

Now the only question, is this game automation or not? :)

(thank you guys, i update 4-5 of my scripts now)

 

This is just a programm to let our users easily join our servers with a famous modification wich needs to be loaded so this is what -mod= does. The user could also do this manually but thats not what we want our loved users to do.  Otherways an error is displayed: "you cant join because you are missing some mods". Nothing more nothing less.

 

Thanks again !

Edited by beon
Link to comment
Share on other sites

  • Moderators

beon & those who replied,

Why do you need a Mod to decide? Which part of:

 

Do not ask for help with AutoIt scripts, post links to, or start discussion topics on the following subjects:

[...]

Launching, automation or script interaction with games or game servers, regardless of the game.

is so hard to understand? :huh:

If you do find it that hard I can always arrange for a short holiday from posting so that you can read the >Forum rules at your leisure. ;)

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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