View previous topic :: View next topic |
Author |
Message |
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Thu Oct 13, 2016 2:53 pm Post subject: Saving trainer state to a .txt/.ini file? |
|
|
Okay so I read a few older threads on this and sort of getting the idea, but am still far off from my goal.
What I want to do is have OnClick events for saving/loading settings profiles in my table to a simple text file, so whenever it's loaded all checkboxes/editboxes/etc. will go back to whatever state they were saved as.
I'm using OpenDialog to open files and SaveDialog to save, but not sure what to do in between. Also using this thread as a reference for settings function in CE: http://forum.cheatengine.org/viewtopic.php?p=5650759 (no idea how to use that in this situation though)
Code: |
function LoadSettingsClick()
LoadSettings = UDF1.OpenDialog.execute()
-- something that reads a file and loads the settings values?
end
function SaveSettingsClick()
SaveSettings = UDF1.SaveDialog.execute()
-- something that writes the settings value to a text file?
end
|
|
|
Back to top |
|
|
predprey Master Cheater Reputation: 24
Joined: 08 Oct 2015 Posts: 486
|
Posted: Thu Oct 13, 2016 4:11 pm Post subject: |
|
|
the way I save to a file is to createStringlist() first then use the saveToFile() method of string lists.
Autoloading of Lua script would probably not be possible unless the user sets loading of Lua scripts to be auto, else he/she would have to reply yes to the load Lua script prompt.
The first part of the script would of course be to loadFromFile(), also a string list method, and parse the .txt/.ini file for flags.
Then, you want to implement a save function bound to the OnClose event handler of the main form, getMainForm().
You can optionally implement a InputQuery() prompt to the save function to ask the user if he/she wants to save.
Thereafter, parse the address list, getAddressList(), for the enabled/disabled status of all the memory records which should be stored as a boolean in the Active property, i.e. getAddressList()[Index].Active == true?
Finally, store the active records index in the .txt/.ini files using the stringlist, with each index on a newline, i.e. newStringList[LineIndex]. On loading the cheat table, the script would parse the text files for all the indexes and set the memory records at those indexes to active. Alternatively, you can use the Description of the memory records instead, or maybe even both.
|
|
Back to top |
|
|
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Thu Oct 13, 2016 4:43 pm Post subject: |
|
|
Thank you for the suggestions, I'm still a noobie to Lua so I'll have to play around with those methods you mentioned.
Also just to clarify better what I'm trying to do, instead of reading from one text file and auto loading those settings, I'd want the user to be able to choose from different profiles. So when the trainer is loaded it will be unchecked/unedited and the user can select the OnClick object to open a text file containing the settings values (example, UDF1.Checkbox.Checked = true or something like that) and another object to click for saving those values to a new or existing text file.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Thu Oct 13, 2016 4:53 pm Post subject: |
|
|
So the file you save should just have a single number in it that you read.
And your Lua would be hardcoded with all options to enable for each profile.
Code: | if value == 1 then
--load profile 1 settings
elseif value == 2 then
--load profile 2 settings
end |
edit: Unless you still want them to be able to choose which options are enabled in each profile themselves...
Then you'd use predprey's method except hook it to your Save Profile button instead of OnClose.
|
|
Back to top |
|
|
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Thu Oct 13, 2016 7:34 pm Post subject: |
|
|
I'm probably on the wrong track here, not familiar with stringlists or dialog objects unfortunately
Code: |
function SaveSettingsClick(sender)
SettingsList = createStringlist()
local SV = getSettings('TrainerState')
if UDF1.Checkbox.Checked then
SV.Value['CheckboxState'] = '1'
else
SV.Value['CheckboxState'] = '0'
end
SettingsList.add(SV.Value)
SaveSettings = createSaveDialog(sender)
if SaveSettings.execute() then
SettingsList.saveToFile(SaveSettings.Profile)
end
SaveSettings.destroy()
SettingsList.destroy()
end
|
|
|
Back to top |
|
|
predprey Master Cheater Reputation: 24
Joined: 08 Oct 2015 Posts: 486
|
Posted: Thu Oct 13, 2016 7:46 pm Post subject: |
|
|
looks fine.....i presume SaveSettings.Profile is the filepath for the .txt file?
|
|
Back to top |
|
|
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Fri Oct 14, 2016 1:37 pm Post subject: |
|
|
Sadly it didn't work for me, no errors are thrown and the SaveDialog comes up fine but nothing is actually saved to a file, and likewise for loading
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Fri Oct 14, 2016 6:33 pm Post subject: |
|
|
Profile isn't a valid member. You probably wanted: Code: | SaveSettings.FileName |
|
|
Back to top |
|
|
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Fri Oct 14, 2016 6:58 pm Post subject: |
|
|
Zanzer wrote: | Profile isn't a valid member. You probably wanted: Code: | SaveSettings.FileName |
|
Thanks, silly mistake on my part.
So now saving works and creates a text file, and if I do something like SettingsList.add('1') it will write to the file, but how would I go about storing my settings values and also reading from them in the load function? Sort of like how I'm trying to do in the sloppy example above with getSettings
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Fri Oct 14, 2016 7:43 pm Post subject: |
|
|
Code: | local records = getAddressList()
local strings = createStringlist()
for i = 0, records.Count - 1 do
local record = records.MemoryRecord[i]
if record.Active then
strings.add(record.Description)
end
end
-- save strings
strings.Destroy() |
Code: | -- load strings
local records = getAddressList()
for i = 0, strings.Count - 1 do
records.getMemoryRecordByDescription(strings[i]).Active = true
end
strings.Destroy() |
|
|
Back to top |
|
|
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Sat Oct 15, 2016 3:06 pm Post subject: |
|
|
Thanks Zanzer! I don't actually use AA scripts through the CE records I do it all through the Lua script, but I can probably work out the rest with that example.
Appreciate all the help guys! Cheers~
|
|
Back to top |
|
|
|