Save system Topic is solved
Save system
Is it possible to make a save system that stores variables in a text file? Then load it from the text file after?
Re: Save system
Yes. IniWrite/-Read
Re: Save system
Could u give an example or something?
Re: Save system
Something like this?
IniWrite, Cookies, text.txt, Section ---- Idk what section means?
IniWrite, Cookies, text.txt, Section ---- Idk what section means?
Re: Save system
Code: Select all
memoryCardPath := A_ScriptDir . "\memoryCard.ini" ; the path of the "memory card"
defaultValue := A_Space ; the value if the variable couln't be loaded
IniRead, var, % memoryCardPath, test, var, % A_Space ; read the value at section "test", key "var"
Gui, Add, Edit, vInput, % var
Gui, Add, Button,, &Save
Gui, Show, AutoSize
return ; end of the auto-execute part of the script
ButtonSave:
Gui, Submit
IniWrite, % input, % A_ScriptDir . "\memoryCard.ini", test, var ; save the value
Reload
return
[EDIT]
Capital cities is a section and Kazakhstan=Astana one of the section's key-value pair:
Code: Select all
[capital cities]
Kazakhstan=Astana
Ouzbekistan=Tachkent
Kirghizstan=Bichkek
Turkmenistan=Achgabat
Tadjikistan=Douchanbé
Last edited by A_AhkUser on 21 Oct 2017, 15:13, edited 2 times in total.
Re: Save system
I'll type back tomorrow if it works
Re: Save system
This is my code
How do i save all the variables in a txt file? Then make the user able to load it again?
How do i save all the variables in a txt file? Then make the user able to load it again?
Code: Select all
#NoEnv
#SingleInstance Force
;/////Variables
DeleteCookies := 0
Shop := 0
DeleteCookiesProducerCost = 10
FastDeleterCost = 50
Perclick := 1
Cps := 0
;/////Gui
SetTimer, CookiesCounter, 50
Gui, Add, Text, x1200 y10, Bitcoin Clicker
Gui, Add, Button, x100 y100 w100 h100 vButtonToBeHidden1 gDeleteCookiesUpgrade, Automatic Miner: %DeleteCookiesProducerCost%
Gui, Add, Button, x250 y40 w100 h100 vButtonToBeHidden2 gCookiePerClick, Fast Miner: %FastDeleterCost%
Gui, Add, Button, x400 y100 w500 h500 vButtonToBeHidden3 gClickMe, ClickMe
Gui, Add, Button, x250 y40 w100 h100 vClose1 gClose, Close
GuiControl, Hide, Close1
Gui, Add, Button, x25 y200 w100 h100 vButtonToBeHidden4 gHideShow, Upgrades
Gui, +AlwaysOnTop +MinimizeBox
Gui, Add, Text, x592 y50 w150 vDeleteCookies, Cookies Deleted: %DeleteCookies%
Gui, Add, Text, x600 y10 w150 vCps, CPS: %Cps%
Gui, Show, w1300 h650
return
;/////SetTimer
ClickMe:
DeleteCookies+=Perclick
SetTimer, CookiesCounter, 50
SetTimer, CookiesPerSecond, 1000
return
;/////Labels
CookiesCounter:
GuiControl,, DeleteCookies, Bitcoins Mined: %DeleteCookies%
GuiControl,, ButtonToBeHidden1, Automatic Miner: Price $%DeleteCookiesProducerCost%
GuiControl,, ButtonToBeHidden2, Fast Deleter: Price $%FastDeleterCost%
GuiControl,, Cps, BPS: %Cps%
return
CookiesPerSecond:
DeleteCookies+=Cps
return
CookiePerClick:
if DeleteCookies >= %FastDeleterCost%
{
DeleteCookies -= FastDeleterCost
FastDeleterCost *= 4
Perclick *= 2
}
return
DeleteCookiesUpgrade:
if DeleteCookies >= %DeleteCookiesProducerCost%
{
DeleteCookies -= DeleteCookiesProducerCost
DeleteCookiesProducerCost += 20
Cps += 1
}
return
HideShow:
{
GuiControl, Hide, ButtonToBeHidden1
GuiControl, Hide, ButtonToBeHidden2
GuiControl, Hide, ButtonToBeHidden3
GuiControl, Hide, ButtonToBeHidden4
GuiControl, Show, Close1
}
return
Close:
{
GuiControl, Show, ButtonToBeHidden4
GuiControl, Show, ButtonToBeHidden3
GuiControl, Show, ButtonToBeHidden2
GuiControl, Show, ButtonToBeHidden1
GuiControl, Hide, Close1
}
return
;/////Something
F12::Reload
GuiClose:
Esc::ExitApp
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: Save system
Hope this will help, this is the basic of using ini files. You can incorporate as you need it per your script.
The gist here is for you to see how and why it works and use it in your script accordingly and youll have a future reference of knowledge for future scripts.
Its actually pretty simple.
The problem with your code is i dont know what and when you need values to be stored in file and when read.
I tried your app but honestly, no idea by code or by gui what is important and what not. Firstly, isnt there supposed to be a stop button for Automatic miner button or is it for reload? Also, do the stored values need to be reset at some point? Dont know why it needs to be more than 10 for autoMiner to work and why when it activates it first restarts to 0. Best way to help is to show a standalone example and one incorporated so hope this works out for you and shows how to use it. ^^
All i can think of is to store the main counter value and hence read it on startup like this:
You might notice there is a script name, version and author. Its for tracking purposes if you have a coding friend and if at any point you plan to release it, its always good to track its version and have in mind if any changes are made by a new version of script to have something to compare to if some modifications need to be applied to the ini file.
Just to give you an idea, like this:
The gist here is for you to see how and why it works and use it in your script accordingly and youll have a future reference of knowledge for future scripts.
Its actually pretty simple.
Code: Select all
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, Force
; For easier overview and edit of your files and folder structure.
ApplicationName=Some Name
; This will place a folder with the %ApplicationName% (Some Name) and a Config.ini file inside it in Documents.
; You can use scripts folder instead or any other location with %A_ScriptDir%
ConfigPath=%A_MyDocuments%\%ApplicationName%
ConfigName=Config.ini
; This will check if the file and/or folder exist and create one if it doesnt with starting variables.
IfNotExist, %ConfigPath%\%ConfigName%
{
FileCreateDir, %ConfigPath%
FileAppend,
(
[GENERAL]
name=%ApplicationName%
version=1.0.0
author=your name
[COUNTER]
Cookies=0
Coffee=0
Tea=0
Milk=0
), %ConfigPath%\%ConfigName%
}
; This will read the variables if the file exists.
IfExist, %ConfigPath%\%ConfigName%
{
IniRead, Cookies, %ConfigPath%\%ConfigName%, COUNTER, Cookies, ERROR
if (Cookies == "ERROR")
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, Cookies
}
else
if (Cookies = "")
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, Cookies
}
}
; You can do this for any and all variables that need to be set when script loads.
; If not, load the values from file on demand. Your choice.
Return
Now all you have to do to add or modify a variable is this:
; Write to file on demand:
F1::
; Your manipulations.
Cookies:=20
; Note, you can use same variable name for config and in script so its easier to work with them. At least for me. :)
IniWrite, %Cookies%, %ConfigPath%\%ConfigName%, COUNTER, Cookies
Return
; Read file on demand:
F2::
IniRead, Cookies, %ConfigPath%\%ConfigName%, COUNTER, Cookies, ERROR
Return
F3::
if Cookies > 10
Milk:=1
IniWrite, %Milk%, %ConfigPath%\%ConfigName%, COUNTER, Cookies
Return
F4::
; This will simply create a variable in the Config.ini if it doesnt exist.
IniWrite, 1, %ConfigPath%\%ConfigName%, FOOD, Bacon
; IniWrite, (what you want to write to ini), (file location and name), (Section where the variables will be under), (Variable name in the ini)
Return
Esc::ExitApp
I tried your app but honestly, no idea by code or by gui what is important and what not. Firstly, isnt there supposed to be a stop button for Automatic miner button or is it for reload? Also, do the stored values need to be reset at some point? Dont know why it needs to be more than 10 for autoMiner to work and why when it activates it first restarts to 0. Best way to help is to show a standalone example and one incorporated so hope this works out for you and shows how to use it. ^^
All i can think of is to store the main counter value and hence read it on startup like this:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
ApplicationName=AutoMiner
; Btw, i use folder instead of directy the config name for potential additional assets.
ConfigPath=%A_ScriptDir%\%ApplicationName%
ConfigName=Config.ini
IfNotExist, %ConfigPath%\%ConfigName%
{
FileCreateDir, %ConfigPath%
FileAppend,
(
[GENERAL]
name=%ApplicationName%
version=1.0.0
author=The Amazing Me, theimmersion :P
[COUNTER]
DeleteCookies=0
), %ConfigPath%\%ConfigName%
}
IfExist, %ConfigPath%\%ConfigName%
{
IniRead, DeleteCookies, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies, ERROR
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (DeleteCookies == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
else
if (DeleteCookies = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
}
;/////Variables
; DeleteCookies := 0 - COMMENTED OUT THIS LOCAL VARIABLE SINCE WE READ IT ON STARTUP AND STORE MODIFIED VALUES
Shop := 0
DeleteCookiesProducerCost = 10
FastDeleterCost = 50
Perclick := 1
Cps := 0
;/////Gui
SetTimer, CookiesCounter, 50
Gui, Add, Text, x1200 y10, Bitcoin Clicker
Gui, Add, Button, x100 y100 w100 h100 vButtonToBeHidden1 gDeleteCookiesUpgrade, Automatic Miner: %DeleteCookiesProducerCost%
Gui, Add, Button, x250 y40 w100 h100 vButtonToBeHidden2 gCookiePerClick, Fast Miner: %FastDeleterCost%
Gui, Add, Button, x400 y100 w500 h500 vButtonToBeHidden3 gClickMe, ClickMe
Gui, Add, Button, x250 y40 w100 h100 vClose1 gClose, Close
GuiControl, Hide, Close1
Gui, Add, Button, x25 y200 w100 h100 vButtonToBeHidden4 gHideShow, Upgrades
Gui, +AlwaysOnTop +MinimizeBox
Gui, Add, Text, x592 y50 w150 vDeleteCookies, Cookies Deleted: %DeleteCookies%
Gui, Add, Text, x600 y10 w150 vCps, CPS: %Cps%
Gui, Show, w1300 h650
return
;/////SetTimer
ClickMe:
DeleteCookies+=Perclick
SetTimer, CookiesCounter, 50
SetTimer, CookiesPerSecond, 1000
return
;/////Labels
CookiesCounter:
; Store the value everytime it changes. You can instead add a save button.
IniWrite, %DeleteCookies%, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
GuiControl,, DeleteCookies, Bitcoins Mined: %DeleteCookies%
GuiControl,, ButtonToBeHidden1, Automatic Miner: Price $%DeleteCookiesProducerCost%
GuiControl,, ButtonToBeHidden2, Fast Deleter: Price $%FastDeleterCost%
GuiControl,, Cps, BPS: %Cps%
return
CookiesPerSecond:
DeleteCookies+=Cps
return
CookiePerClick:
if DeleteCookies >= %FastDeleterCost%
{
DeleteCookies -= FastDeleterCost
FastDeleterCost *= 4
Perclick *= 2
}
return
DeleteCookiesUpgrade:
if DeleteCookies >= %DeleteCookiesProducerCost%
{
DeleteCookies -= DeleteCookiesProducerCost
DeleteCookiesProducerCost += 20
Cps += 1
}
return
HideShow:
{
GuiControl, Hide, ButtonToBeHidden1
GuiControl, Hide, ButtonToBeHidden2
GuiControl, Hide, ButtonToBeHidden3
GuiControl, Hide, ButtonToBeHidden4
GuiControl, Show, Close1
}
return
Close:
{
GuiControl, Show, ButtonToBeHidden4
GuiControl, Show, ButtonToBeHidden3
GuiControl, Show, ButtonToBeHidden2
GuiControl, Show, ButtonToBeHidden1
GuiControl, Hide, Close1
}
return
;/////Something
F12::Reload
GuiClose:
Esc::ExitApp
Just to give you an idea, like this:
Code: Select all
ConfigPath=%A_ScriptDir%\%ApplicationName%
ConfigName=Config.ini
IfNotExist, %ConfigPath%\%ConfigName%
{
FileCreateDir, %ConfigPath%
APPENDFILE:
FileAppend,
(
[GENERAL]
name=%ApplicationName%
version=2.0.0
author=The Amazing Me, theimmersion :P
[NewSectionName]
Jo=0
[OldSection]
Oj=1
), %ConfigPath%\%ConfigName%
IfExist, %ConfigPath%\%ConfigName%
{
IniRead, AppVersion, %ConfigPath%\%ConfigName%, COUNTER, version, ERROR
if (AppVersion < 2.0.0)
{
FileDelete, %ConfigPath%\%ConfigName%
GoSub, APPENDFILE
msgbox, Updated to new version.
}
else
{
msgbox, Hello World!
}
}
ExitApp
Re: Save system
I dont seem to understand this line?
Code: Select all
ConfigPath=%A_MyDocuments%\%ApplicationName%
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: Save system
Its for consistency.
ConfigPath - is used to have a consistent path system in your script. Like if you use on multiple places and need to change location, it will affect all.
A_MyDocuments - is a built in variable from AHK that uses documents folder.
ApplicationName - is also a global variable to name the folder the same as your script for consistency.
You can even have a trick like this:
Take the script name and remove the extension.
ScriptName = % regexreplace(A_scriptname, "^.+\\|\.[^.]+$")
Set app name to script name.
ApplicationName:=ScriptName
Now everytime you rename your script file, it will automatically apply that name within the script. You can use it in GUI etc...
Gui,Show,,%ApplicationName%
For instance, if the AHK script is called AutoMiner.ahk or AutoMiner.exe (it works even if you compile it), that name will be used for whatever you need.
Like, naming the Config.ini to the scripts name instead or creating folders by the Scripts name etc. Like other Apps do.
ConfigPath - is used to have a consistent path system in your script. Like if you use on multiple places and need to change location, it will affect all.
A_MyDocuments - is a built in variable from AHK that uses documents folder.
ApplicationName - is also a global variable to name the folder the same as your script for consistency.
You can even have a trick like this:
Take the script name and remove the extension.
ScriptName = % regexreplace(A_scriptname, "^.+\\|\.[^.]+$")
Set app name to script name.
ApplicationName:=ScriptName
Now everytime you rename your script file, it will automatically apply that name within the script. You can use it in GUI etc...
Gui,Show,,%ApplicationName%
For instance, if the AHK script is called AutoMiner.ahk or AutoMiner.exe (it works even if you compile it), that name will be used for whatever you need.
Like, naming the Config.ini to the scripts name instead or creating folders by the Scripts name etc. Like other Apps do.
Re: Save system
Okay
Re: Save system
So i wanna save the Config file inside the marked folder. Can u please help me?
https://gyazo.com/c56441c152a8a04eeae9720c30da096b
https://gyazo.com/c56441c152a8a04eeae9720c30da096b
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: Save system
ConfigPath=%A_ScriptDir%\Scripts
Essentially, the %A_ScriptDir% makes sure its always where the script is, after that you can place the ini side by side with the script file itself or any folder you like.
You can put an absolute address as well. You can put C:\Users\YourUserName\Desktop\Blah etc... Tho its not recommended unless you know what your doing.
Always use a script inside its own folder (root) and all files and folders that are created to be inside that root folder of the script to prevent loose files all over PC. xD
Essentially, the %A_ScriptDir% makes sure its always where the script is, after that you can place the ini side by side with the script file itself or any folder you like.
You can put an absolute address as well. You can put C:\Users\YourUserName\Desktop\Blah etc... Tho its not recommended unless you know what your doing.
Always use a script inside its own folder (root) and all files and folders that are created to be inside that root folder of the script to prevent loose files all over PC. xD
Re: Save system
So this is the code. But it doesn't seem to work?
Code: Select all
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; For easier overview and edit of your files and folder structure.
Bitcoin=Save
; This will place a folder with the %ApplicationName% (Some Name) and a Config.ini file inside it in Documents.
; You can use scripts folder instead or any other location with %A_ScriptDir%
ConfigPath=%A_ScriptDir%\Scripts\%ApplicationName%
ConfigName=Config.ini
; This will check if the file and/or folder exist and create one if it doesnt with starting variables.
IfNotExist, %Script%\%ConfigName%
{
FileCreateDir, %ConfigPath%
FileAppend,
(
[GENERAL]
name=%ConfigName%
version=1.0.0
author=Jonas353
[COUNTER]
DeleteCookies
Shop
DeleteCookiesProducerCost
FastDeleterCost
Perclick
Cps
), %ConfigPath%\%ConfigName%
}
; This will read the variables if the file exists.
IfExist, %ConfigPath%\%ConfigName%
{
IniRead, DeleteCookies, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies, ERROR
if (DeleteCookies == "ERROR")
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
else
if (DeleteCookies = "")
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
}
; You can do this for any and all variables that need to be set when script loads.
; If not, load the values from file on demand. Your choice.
Return
; Write to file on demand:
F1::
; Your manipulations.
DeleteCookies:=20
; Note, you can use same variable name for config and in script so its easier to work with them. At least for me. :)
IniWrite, %DeleteCookies%, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
Return
; Read file on demand:
F2::
IniRead, DeleteCookies, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies, ERROR
Return
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: Save system
Because you set folder structure to:
ConfigPath=%A_ScriptDir%\Scripts\%ApplicationName%
while checking for:
IfNotExist, %Script%\%ConfigName%
It should be:
IfNotExist, %ConfigPath%\%ConfigName%
And again, be careful so with what you do so you dont make loose files all over your PC. xD
ConfigPath=%A_ScriptDir%\Scripts\%ApplicationName%
while checking for:
IfNotExist, %Script%\%ConfigName%
It should be:
IfNotExist, %ConfigPath%\%ConfigName%
And again, be careful so with what you do so you dont make loose files all over your PC. xD
Re: Save system
Okay
And yeah don't worry
[EDIT]
I did what u said and it doesnt work.
And yeah don't worry
[EDIT]
I did what u said and it doesnt work.
Code: Select all
ConfigPath=%A_ScriptDir%\Script\%ApplicationName%
ConfigName=Config.ini
; This will check if the file and/or folder exist and create one if it doesnt with starting variables.
IfNotExist, %ConfigPath%\%ConfigName%
Last edited by Jonas353 on 23 Oct 2017, 08:14, edited 1 time in total.
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: Save system
Works fine on my end. Try this as is (dont edit, just use it):
Look if the following folders are created with ini file inside where the script is:
Scripts\AutoMiner\Config.ini
If it works, than theres a mistake in your overall script. Try compare and see what might be the issue.
This is the script you sent as demo and i applied a read write ini structure.
Look if the following folders are created with ini file inside where the script is:
Scripts\AutoMiner\Config.ini
If it works, than theres a mistake in your overall script. Try compare and see what might be the issue.
This is the script you sent as demo and i applied a read write ini structure.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
ApplicationName=AutoMiner
; Btw, i use folder instead of directy the config name for potential additional assets.
ConfigPath=%A_ScriptDir%\Scripts\%ApplicationName%
ConfigName=Config.ini
IfNotExist, %ConfigPath%\%ConfigName%
{
FileCreateDir, %ConfigPath%
FileAppend,
(
[GENERAL]
name=%ApplicationName%
version=1.0.0
author=your name
[COUNTER]
DeleteCookies=0
), %ConfigPath%\%ConfigName%
}
IfExist, %ConfigPath%\%ConfigName%
{
IniRead, DeleteCookies, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies, ERROR
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (DeleteCookies == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
else
if (DeleteCookies = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
}
;/////Variables
; DeleteCookies := 0 - COMMENTED OUT THIS LOCAL VARIABLE SINCE WE READ IT ON STARTUP AND STORE MODIFIED VALUES
Shop := 0
DeleteCookiesProducerCost = 10
FastDeleterCost = 50
Perclick := 1
Cps := 0
;/////Gui
SetTimer, CookiesCounter, 50
Gui, Add, Text, x1200 y10, Bitcoin Clicker
Gui, Add, Button, x100 y100 w100 h100 vButtonToBeHidden1 gDeleteCookiesUpgrade, Automatic Miner: %DeleteCookiesProducerCost%
Gui, Add, Button, x250 y40 w100 h100 vButtonToBeHidden2 gCookiePerClick, Fast Miner: %FastDeleterCost%
Gui, Add, Button, x400 y100 w500 h500 vButtonToBeHidden3 gClickMe, ClickMe
Gui, Add, Button, x250 y40 w100 h100 vClose1 gClose, Close
GuiControl, Hide, Close1
Gui, Add, Button, x25 y200 w100 h100 vButtonToBeHidden4 gHideShow, Upgrades
Gui, +AlwaysOnTop +MinimizeBox
Gui, Add, Text, x592 y50 w150 vDeleteCookies, Cookies Deleted: %DeleteCookies%
Gui, Add, Text, x600 y10 w150 vCps, CPS: %Cps%
Gui, Show, w1300 h650
return
;/////SetTimer
ClickMe:
DeleteCookies+=Perclick
SetTimer, CookiesCounter, 50
SetTimer, CookiesPerSecond, 1000
return
;/////Labels
CookiesCounter:
; Store the value everytime it changes. You can instead add a save button.
IniWrite, %DeleteCookies%, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
GuiControl,, DeleteCookies, Bitcoins Mined: %DeleteCookies%
GuiControl,, ButtonToBeHidden1, Automatic Miner: Price $%DeleteCookiesProducerCost%
GuiControl,, ButtonToBeHidden2, Fast Deleter: Price $%FastDeleterCost%
GuiControl,, Cps, BPS: %Cps%
return
CookiesPerSecond:
DeleteCookies+=Cps
return
CookiePerClick:
if DeleteCookies >= %FastDeleterCost%
{
DeleteCookies -= FastDeleterCost
FastDeleterCost *= 4
Perclick *= 2
}
return
DeleteCookiesUpgrade:
if DeleteCookies >= %DeleteCookiesProducerCost%
{
DeleteCookies -= DeleteCookiesProducerCost
DeleteCookiesProducerCost += 20
Cps += 1
}
return
HideShow:
{
GuiControl, Hide, ButtonToBeHidden1
GuiControl, Hide, ButtonToBeHidden2
GuiControl, Hide, ButtonToBeHidden3
GuiControl, Hide, ButtonToBeHidden4
GuiControl, Show, Close1
}
return
Close:
{
GuiControl, Show, ButtonToBeHidden4
GuiControl, Show, ButtonToBeHidden3
GuiControl, Show, ButtonToBeHidden2
GuiControl, Show, ButtonToBeHidden1
GuiControl, Hide, Close1
}
return
;/////Something
F12::Reload
GuiClose:
Esc::ExitApp
Re: Save system
It works now. I dont know how to thank you but THANKS!
- theimmersion
- Posts: 181
- Joined: 09 Jul 2016, 08:34
- Location: Serbia
Re: Save system Topic is solved
No problem.
Tho, you must do small changes to the script of mine as i just placed IniWrite in the self executing loop just for testing purposes.
You should change it so that it writes to the ini where the changes are actually applied and remove it from the self execution because its bad practice to write over and over again stuff that never changes.
Tho, you must do small changes to the script of mine as i just placed IniWrite in the self executing loop just for testing purposes.
You should change it so that it writes to the ini where the changes are actually applied and remove it from the self execution because its bad practice to write over and over again stuff that never changes.
Re: Save system
dammit! So it doesnt load all other things than DeleteCookies
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
ApplicationName=AutoMiner
; Btw, i use folder instead of directy the config name for potential additional assets.
ConfigPath=%A_ScriptDir%\Scripts\%ApplicationName%
ConfigName=Config.ini
IfNotExist, %ConfigPath%\%ConfigName%
{
FileCreateDir, %ConfigPath%
FileAppend,
(
[GENERAL]
name=%ApplicationName%
version=1.0.0
author=Jonas353
[COUNTER]
DeleteCookies=0
DeleteCookiesProducerCost=10
FastDeleterCost=50
Perclick := 1
Cps=0
), %ConfigPath%\%ConfigName%
}
IfExist, %ConfigPath%\%ConfigName%
{
IniRead, DeleteCookies, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies, ERROR
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (DeleteCookies == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
else
if (DeleteCookies = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
}
IniRead, DeleteCookies, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies, ERROR
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (DeleteCookiesProducerCost == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 10, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookiesProducerCost
}
else
if (DeleteCookiesProducerCost = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 10, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookiesProducerCost
}
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (FastDeleterCost == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 50, %ConfigPath%\%ConfigName%, COUNTER, FastDeleterCost
}
else
if (Perclick = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 50, %ConfigPath%\%ConfigName%, COUNTER, FastDeleterCost
}
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (Perclick == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 1, %ConfigPath%\%ConfigName%, COUNTER, Perclick
}
else
if (Perclick = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 1, %ConfigPath%\%ConfigName%, COUNTER, Perclick
}
; Makes sure if for whatever reason the variable is missing to give it a default of 0.
if (Cps == "ERROR") ; Usually indicating of the variable missing from the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, Cps
}
else
if (Cps = "") ; Usually indicating of the variable being empty in the file.
{
IniWrite, 0, %ConfigPath%\%ConfigName%, COUNTER, Cps
}
}
;/////Variables
; DeleteCookies := 0
Shop := 0
;DeleteCookiesProducerCost = 10
;FastDeleterCost = 50
;Perclick := 1
;Cps := 0
;/////Gui
SetTimer, CookiesCounter, 50
Gui, Add, Text, x1200 y10, Bitcoin Clicker
Gui, Add, Button, x100 y100 w100 h100 vButtonToBeHidden1 gDeleteCookiesUpgrade, Automatic Miner: %DeleteCookiesProducerCost%
Gui, Add, Button, x250 y40 w100 h100 vButtonToBeHidden2 gCookiePerClick, Fast Miner: %FastDeleterCost%
Gui, Add, Button, x400 y100 w500 h500 vButtonToBeHidden3 gClickMe, ClickMe
Gui, Add, Button, x250 y40 w100 h100 vClose1 gClose, Close
GuiControl, Hide, Close1
Gui, Add, Button, x25 y200 w100 h100 vButtonToBeHidden4 gHideShow, Upgrades
Gui, +AlwaysOnTop +MinimizeBox
Gui, Add, Text, x592 y50 w150 vDeleteCookies, Cookies Deleted: %DeleteCookies%
Gui, Add, Text, x600 y10 w150 vCps, CPS: %Cps%
Gui, Show, w1300 h650
return
;/////SetTimer
ClickMe:
DeleteCookies+=Perclick
SetTimer, CookiesCounter, 50
SetTimer, CookiesPerSecond, 1000
return
;/////Labels
CookiesCounter:
; Store the value everytime it changes. You can instead add a save button.
IniWrite, %DeleteCookies%, %ConfigPath%\%ConfigName%, COUNTER, DeleteCookies
GuiControl,, DeleteCookies, Bitcoins Mined: %DeleteCookies%
GuiControl,, ButtonToBeHidden1, Automatic Miner: Price $%DeleteCookiesProducerCost%
GuiControl,, ButtonToBeHidden2, Fast Deleter: Price $%FastDeleterCost%
GuiControl,, Cps, BPS: %Cps%
return
CookiesPerSecond:
DeleteCookies+=Cps
return
CookiePerClick:
if DeleteCookies >= %FastDeleterCost%
{
DeleteCookies -= FastDeleterCost
FastDeleterCost *= 4
Perclick *= 2
}
return
DeleteCookiesUpgrade:
if DeleteCookies >= %DeleteCookiesProducerCost%
{
DeleteCookies -= DeleteCookiesProducerCost
DeleteCookiesProducerCost += 20
Cps += 1
}
return
HideShow:
{
GuiControl, Hide, ButtonToBeHidden1
GuiControl, Hide, ButtonToBeHidden2
GuiControl, Hide, ButtonToBeHidden3
GuiControl, Hide, ButtonToBeHidden4
GuiControl, Show, Close1
}
return
Close:
{
GuiControl, Show, ButtonToBeHidden4
GuiControl, Show, ButtonToBeHidden3
GuiControl, Show, ButtonToBeHidden2
GuiControl, Show, ButtonToBeHidden1
GuiControl, Hide, Close1
}
return
;/////Something
F12::Reload
GuiClose:
Esc::ExitApp
Who is online
Users browsing this forum: NullRefEx, ShatterCoder and 107 guests