Sign in to follow this  
Followers 0
NewBe

IniWrite

8 posts in this topic

How can I write to a ini that is already created I don't want to have to keep writing a new ini :)

;so say this is my ini 

IniWrite("C:\Temp\myfile.ini", "test", "key", "old")

;but then I decide to change that value to this

IniWrite("C:\Temp\myfile.ini", "test", "key", "new")

Share this post


Link to post
Share on other sites

What you posted looks right to me... are you saying this is creating a new .ini file for you?


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

That will definitely update an existing file.

Share this post


Link to post
Share on other sites

well I tried it in my script that contains a lots of writes so either I messed up or it isn't over writing the old value... ill check

Share this post


Link to post
Share on other sites

well heres my game so far not finished yet still got a ways to go...

#Include <Misc.au3>
#include <String.au3>
#include <GUIConstants.au3>
Global $GUI , $Data , $Ini = @ScriptDir & "\Resources\Profiles\"
Opt("OnExitFunc" , "_Exit")

If _Singleton(@ScriptName , 1) = 0 Then
    Msgbox(0 , "Warning" , "An occurence of this game is already running")
    Exit
EndIf

If Not FileExists($Ini & "*.ini") Then
    $Data = InputBox("Welcome " & @UserName , "please give your profile a name" , @UserName , "" , 200 , 50)
    If $Data = "" Then 
        Exit
    Else
    ;Player
    IniWrite($Ini & $Data & ".ini" , "Player" , "Name" , $Data)
    IniWrite($Ini & $Data & ".ini" , "Player" , "Level" , 0)
    IniWrite($Ini & $Data & ".ini" , "Player" , "Health" , 100)
    IniWrite($Ini & $Data & ".ini" , "Player" , "Min" , 5)
    IniWrite($Ini & $Data & ".ini" , "Player" , "Max" , 10)
    IniWrite($Ini & $Data & ".ini" , "Player" , "Gold" , 0)
    IniWrite($Ini & $Data & ".ini" , "Player" , "Exp" , 0)
    ;Boss
    IniWrite($Ini & $Data & ".ini" , "Boss" , "Min" , 1)
    IniWrite($Ini & $Data & ".ini" , "Boss" , "Max" , 3)
    IniWrite($Ini & $Data & ".ini" , "Boss" , "Gold" , 5)
    IniWrite($Ini & $Data & ".ini" , "Boss" , "Exp" , 20)
    MsgBox(0 , "" , "please restart the game")
    Exit
EndIf
EndIf

_LoadProfile()

$GUI = GUICreate("" , 300, 180, Default , Default)
$Health = GUICtrlCreateProgress(0, 0, 100, 17) ;Player Health
$Boss = GUICtrlCreateProgress(200, 0, 100, 17) ;Boss Health

$Level = GUICtrlCreateLabel("Level: " & IniRead($Ini & $Data & ".ini" , "Player" , "Level" , 1) , 0 , 20 , 200 , 25)
$Damage = GUICtrlCreateLabel("Damage: " & IniRead($Ini & $Data & ".ini" , "Player" , "Min" , 5) & "-" & IniRead($Ini & $Data & ".ini" , "Player" , "Max" , 10) , 0, 40 , 200, 25) 
$Gold = GUICtrlCreateLabel("Gold: " & IniRead($Ini & $Data & ".ini" , "Player" , "Gold" , 0) , 0 , 60 , 200 , 25) 
$Exp = GUICtrlCreateLabel("Exp: " & IniRead($Ini & $Data & ".ini" , "Player" , "Exp" , 0) , 0 , 80 , 200 , 17) 

$BossDamage = GUICtrlCreateLabel("Damage: " & IniRead($Ini & $Data & ".ini" , "Boss" , "Min" , 1) & "-" & IniRead($Ini & $Data & ".ini" , "Boss" , "Max" , 3), 200 , 20 , 200 , 25) 
$BossGold = GUICtrlCreateLabel("Gold: " & IniRead($Ini & $Data & ".ini" , "Boss" , "Gold" , 5) , 200 , 40 , 200 , 25) ;Boss Gold
$BossExp = GUICtrlCreateLabel("Exp: " & IniRead($Ini & $Data & ".ini" , "Boss" , "Exp" , 20) , 200 , 60 , 200 , 25) ;Boss Exp

$Attack = GUICtrlCreateButton("Attack", 0, 100, 75, 25, 0) ;player
$Level = GUICtrlCreateButton("Level", 0, 125, 75, 25, 0) ;player
$Exit = GUICtrlCreateButton("Exit", 0, 150 , 75, 25, 0) ;player

_SetHealth($Health , IniRead($Ini & $Data & ".ini" , "Player" , "Health" , 100))
_SetHealth($Boss , 100 * IniRead($Ini & $Data & ".ini" , "Player" , "Level" , 1))

;DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00080000) ;fade in (interrupts _AnimateTitle)
GUISetState(@SW_SHOW)
_AnimateTitle($GUI , "Welcome " & IniRead($Data , "Player" , "Name" , @UserName) , 50)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            _Exit()
    ;   Case $Exit
    ;       _Exit()
        Case $Attack
            If GUICtrlRead($Health) = 0 Then 
            ;   _Dead()
            Else
            _Attack("Boss")
            _Attack("Player")
            EndIf
    EndSwitch
    If GUICtrlRead($Boss) = 0 Then _MonInfo()
WEnd

Func _SetHealth($Null , $Hitpoint)
    GUICtrlSetData($Null , $Hitpoint)   
EndFunc

Func _Attack($Target)
    $Ran1 = Random(IniRead($Ini & $Data & ".ini" , "Player" , "Min" , 5) , IniRead($Ini & $Data & ".ini" , "Player" , "Max" , 10))
    $Ran2 = Random(IniRead($Ini & $Data & ".ini" , "Boss" , "Min" , 1) , IniRead($Ini & $Data & ".ini" , "Boss" , "Max" , 3))
    If $Target = "Boss" Then 
    GUICtrlSetData($Boss , GUICtrlRead($Boss) - $Ran1)
    Else
    GUICtrlSetData($Health , GUICtrlRead($Health) - $Ran2)
    EndIf
EndFunc

Func _MonInfo()
    $CalcGold1 = StringTrimLeft(GUICtrlRead($Gold) , 5)
    $CalcGold2 = StringTrimLeft(GUICtrlRead($BossGold) , 5)
    $CalcExp1 = StringTrimLeft(GUICtrlRead($Exp) , 4)
    $CalcExp2 = StringTrimLeft(GUICtrlRead($BossExp) , 4)
    GUICtrlSetData($Gold , "Gold: " & $CalcGold1 + $CalcGold2)
    GUICtrlSetData($Exp , "Exp: " & $CalcExp1 + $CalcExp2)
    GUICtrlSetState($Attack , $GUI_DISABLE) 
    _SetHealth($Boss , 100 * IniRead($Ini & $Data & ".ini" , "Player" , "Level" , 1))
    ;_Save()
EndFunc

;Func _Dead()

Func _Save()
    ;Player
    IniWrite($Ini & $Data & ".ini" , "Player" , "Level" , 800) ;this part should over write the current ini :nuke: 
;   IniWrite($Ini & $Data & ".ini" , "Player" , "Health" , 100)
;   IniWrite($Ini & $Data & ".ini" , "Player" , "Min" , 5)
;   IniWrite($Ini & $Data & ".ini" , "Player" , "Max" , 10)
;   IniWrite($Ini & $Data & ".ini" , "Player" , "Gold" , 0)
;   IniWrite($Ini & $Data & ".ini" , "Player" , "Exp" , 0)
    
    ;Boss
;   IniWrite($Ini & $Data & ".ini" , "Boss" , "Min" , 1)
;   IniWrite($Ini & $Data & ".ini" , "Boss" , "Max" , 3)
;   IniWrite($Ini & $Data & ".ini" , "Boss" , "Gold" , 5)
;   IniWrite($Ini & $Data & ".ini" , "Boss" , "Exp" , 20)

EndFunc 

Func _LoadProfile()
    $Load = FileOpenDialog("Choose saved game" , $Ini , "Game Files (*.ini)")
    If $Load = "" Then 
        Exit
    Else
        $Data = $Load
    EndIf
EndFunc

Func _AnimateTitle($GuiHand, $sTitle, $iBuf)
    $sTitle = StringSplit($sTitle, "")
    For $i = $iBuf To 0 Step - 1
        Sleep(5)
        WinSetTitle($GuiHand, "", _StringRepeat(" ", $i) & $sTitle[1])
    Next
    Local $s
    For $i = 1 To $sTitle[0]
        Sleep(10)
        $s &= $sTitle[$i]
        WinSetTitle($GuiHand, "", $s)
    Next
EndFunc

Func _Exit()
;   _Save()
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00090000)
    Exit
EndFunc

if you look at the save function it should overwrite the current ini file but doesn't for some reason

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You have the _Save function commented out in the only places I see it being called

Func _MonInfo()
    $CalcGold1 = StringTrimLeft(GUICtrlRead($Gold) , 5)
    $CalcGold2 = StringTrimLeft(GUICtrlRead($BossGold) , 5)
    $CalcExp1 = StringTrimLeft(GUICtrlRead($Exp) , 4)
    $CalcExp2 = StringTrimLeft(GUICtrlRead($BossExp) , 4)
    GUICtrlSetData($Gold , "Gold: " & $CalcGold1 + $CalcGold2)
    GUICtrlSetData($Exp , "Exp: " & $CalcExp1 + $CalcExp2)
    GUICtrlSetState($Attack , $GUI_DISABLE)
    _SetHealth($Boss , 100 * IniRead($Ini & $Data & ".ini" , "Player" , "Level" , 1))
    ;_Save()
EndFuncoÝ÷ Ù«­¢+ÙÕ¹}á¥Ð ¤(ì}MÙ ¤(%±±
±° ÅÕ½ÐíÕÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½Ðí¹¥µÑ]¥¹½ÜÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°ÀÌØíU$°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÄÀÀÀ°ÅÕ½Ðí±½¹ÅÕ½Ðì°ÁàÀÀÀäÀÀÀÀ¤(%á¥Ð)¹Õ¹

So the _Save() function is never called

[edit] for more info [/edit]

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

woot found it my problem was the iniwrites path should of just of been $data

Thanks guys

Edited by NewBe

Share this post


Link to post
Share on other sites

Cool


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
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
Sign in to follow this  
Followers 0