I'm a new user of Auto Hotkeys and I'm looking for some help with a simple Load/Save system I've added into a game I am making.
I've been hunting through the forums for a way to do things in my program, and on most occasions I have found a way to get things working without having to ask... but this one eludes me!
The characters (at the moment, for testing) only have 3 key variables: Pname,PClass, and PRace. I'm aware there are much easier ways to achieve this as it stands, but these files will eventually become much more complicated, and will be sent between machines by email, so ideally I need to have the save games in separate files.
For the example, these will be Name, Class and Race Respectively.
I have made a save file system that works ok:
Code: Select all
SaveChar:
;Checks to see if character information has been added (vTest = 'None') and if not, returns to Opening Menu Gui
If (Pname = Test) and (PRace = Test) and (PClass = Test)
{
MsgBox, No Character Selected!
goto, OpenScr
}
;Warning that saving the character will overwrite existing, and go back to Opening Screen if no.
MsgBox, 4, , This will overwrite an existing character with this filename. Are you sure?
IfMsgBox, No
goto, OpenScr
;Deletes the existing file
FileDelete, %A_ScriptDir%\Program Files\Saved Characters\%PName%.ahk
;Creates the new save file as a .ahk
FileAppend,
(
PName = %Pname%
PClass = %PClass%
PRace = %PRace%
)
, %A_ScriptDir%\Program Files\Saved Characters\%Pname%.ahk
Msgbox, Character Saved Successfully!
Code: Select all
PName = Name
PClass = Class
PRace = Race
Code: Select all
LoadChar:
;Checks to ensure can overwrite if existing, if no return to Gui
MsgBox, 4, , This will overwrite the current character. Are you Sure?
IfMsgBox, No
goto, OpenScr
;Prompt to select Character file
FileSelectFile, CharLoadFile , Options, %A_ScriptDir%\Program Files\Saved Characters, Select Your Character!, Documents (*.ahk)
;Reads the file, and adds to vCharLoadFileContents
FileRead, CharLoadFileContents, %CharLoadFile%
;Adds the text from the specified file path to temp.ahk
FileAppend, %CharLoadFileContents%, temp.ahk
;Runs Ahk2exe.exe to convert temp.ahk to an exe
RunWait, Ahk2exe.exe /in temp.ahk
;Runs temp.exe to add the new variables
RunWait temp.exe
;Deletes the temporary files
FileDelete, temp.ahk
FileDelete, temp.exe
;Adds other details for the new character
goto, Add%Prace%Stats
Code: Select all
PName = Name
PClass = Class
PRace = Race
The next stage of the process gives an error I added for when there are no details in the Pname, PClass and Prace parameters, so the program isn't seeing the loaded details.