Jump to content
Sign in to follow this  
satanttin

Assign a number to a variable?

Recommended Posts

Hello,

First i wanna tell you it's not a bot or whatever i got some spare time now and trying to make a text based game m'kay.

The problem i have is when i make a character the gold and exp start with 0 in the ini file it makes.

It should be 500 gold so it's not working correctly:( and tried anything i can think of and googled some functions but i think i did something wrong.

Hope someone can help me with this so i can continue:)

The full code is:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GName, $GClass, $GRace, $GGold, $GExp, $IName, $IClass, $IRace, $IGold, $IExp

Start()

Func Start()
$GStart = GUICreate("Name of Game", 204, 80, 377, 133)
$BNewGame = GUICtrlCreateButton("New Game", 40, 5, 121, 33)
GUICtrlSetOnEvent(-1, "NewGame")
$BLoadGame = GUICtrlCreateButton("Load Game", 40, 40, 121, 33)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func Main()
$GGold = IniRead (@ScriptDir & "\" & $GName & ".ini", $GName, "Gold", "default" )
$GExp = IniRead (@ScriptDir & "\" & $GName & ".ini", $GName, "EXP", "default" )
$GMain = GUICreate("Name of Game", 1004, 682, 255, 120)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Save", $MenuItem1)
GUICtrlSetOnEvent(-1, "Save")
$MenuItem3 = GUICtrlCreateMenuItem("Load", $MenuItem1)
GUICtrlSetOnEvent(-1, "Load")
$MenuItem4 = GUICtrlCreateMenuItem("Options", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("Character")
$MenuItem6 = GUICtrlCreateMenuItem("Status", $MenuItem5)
$MenuItem7 = GUICtrlCreateMenuItem("Inventory", $MenuItem5)
$MenuItem8 = GUICtrlCreateMenuItem("Battle", $MenuItem5)
$MenuItem9 = GUICtrlCreateMenu("Extra")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func Load()
$sIniFile = FileOpenDialog ( "Select your character", @ScriptDir & "\" & $GName & ".ini", "User Data (*.ini)")
If Not @error Then
        $GName = IniRead ($sIniFile, "Player", "Name", "Error")
        $GClass = IniRead ($sIniFile, "Player", "Class", "Error")
        $GRace = IniRead ($sIniFile, "Player", "Race", "Error")
        $GGold = IniRead ($sIniFile, "Player", "Gold", "Error")
        $GExp = IniRead ($sIniFile, "Player", "EXP", "Error")
    EndIf
EndFunc

Func NewGame()
$GNewGame = GUICreate("New Game", 244, 167, 451, 208)
$IName = GUICtrlCreateInput("Name", 56, 16, 129, 21)
$IClass = GUICtrlCreateInput("Class", 56, 43, 129, 21)
$IRace = GUICtrlCreateInput("Race", 56, 70, 129, 21)
$IGold = "500"
$IExp = "0"
$BStart = GUICtrlCreateButton("Start Game", 80, 100, 77, 33)
GUICtrlSetOnEvent(-1, "StartGame")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func Save()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = GUICtrlRead($IGold)
$GExp = GUICtrlRead($IExp)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
EndFunc

Func StartGame()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = GUICtrlRead($IGold)
$GExp = GUICtrlRead($IExp)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
Main()
EndFunc

Func Close()
   Exit
EndFunc

While 1
    Sleep(100)
WEnd

 

Share this post


Link to post
Share on other sites

Whats the difference between $igold & $ggold?

thats the only thing I saw (quick glance) that might be causing your issue...

$igold = 500

but your ini's are using $ggold....

Bill

Edited by l3ill

Share this post


Link to post
Share on other sites

[Name]
Name=Name
Class=Class
Race=Race
Gold=0
EXP=0

this is the ini file.

i used $IGgold because i used $IName and such aswell and i thought i need it because it was needed for the 3 text variables.

Share this post


Link to post
Share on other sites

$GGold = GUICtrlRead($IGold)

makes here no sense because $IGold is a value, not the control id.

 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

You have duplicate instructions, and instructions which are not placed in the proper function

Try this

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GName, $GClass, $GRace, $GGold, $GExp, $IName, $IClass, $IRace, $IGold, $IExp
Global $GStart, $GNewGame

Start()

Func Start()
$GStart = GUICreate("Name of Game", 204, 80, 377, 133)
$BNewGame = GUICtrlCreateButton("New Game", 40, 5, 121, 33)
GUICtrlSetOnEvent(-1, "NewGame")
$BLoadGame = GUICtrlCreateButton("Load Game", 40, 40, 121, 33)
GUICtrlSetOnEvent(-1, "Load")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func NewGame()
GuiDelete($GStart)
$GNewGame = GUICreate("New Game", 244, 167, 451, 208)
$IName = GUICtrlCreateInput("Name", 56, 16, 129, 21)
$IClass = GUICtrlCreateInput("Class", 56, 43, 129, 21)
$IRace = GUICtrlCreateInput("Race", 56, 70, 129, 21)
$BStart = GUICtrlCreateButton("Start Game", 80, 100, 77, 33)
GUICtrlSetOnEvent(-1, "StartGame")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func StartGame()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = 500
$GExp = 0
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
GuiDelete($GNewGame)
Main()
EndFunc

Func Load()
GuiDelete($GStart)
$sIniFile = FileOpenDialog ( "Select your character", @ScriptDir & "\*.ini", "User Data (*.ini)")
If Not @error Then
        $GName = StringRegExpReplace($sIniFile, '.+\\([^.]+)\.?.*', "$1")
        $GClass = IniRead ($sIniFile, $GName, "Class", "Error")
        $GRace = IniRead ($sIniFile, $GName, "Race", "Error")
        $GGold = IniRead ($sIniFile, $GName, "Gold", "Error")
        $GExp = IniRead ($sIniFile, $GName, "EXP", "Error")
    EndIf
Main()
EndFunc

Func Main()
;$GGold = IniRead (@ScriptDir & "\" & $GName & ".ini", $GName, "Gold", "default" )
;$GExp = IniRead (@ScriptDir & "\" & $GName & ".ini", $GName, "EXP", "default" )
$GMain = GUICreate("Name of Game", 1004, 682, 255, 120)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Save", $MenuItem1)
GUICtrlSetOnEvent(-1, "Save")
$MenuItem3 = GUICtrlCreateMenuItem("Load", $MenuItem1)
GUICtrlSetOnEvent(-1, "Load")
$MenuItem4 = GUICtrlCreateMenuItem("Options", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("Character")
$MenuItem6 = GUICtrlCreateMenuItem("Status", $MenuItem5)
$MenuItem7 = GUICtrlCreateMenuItem("Inventory", $MenuItem5)
$MenuItem8 = GUICtrlCreateMenuItem("Battle", $MenuItem5)
$MenuItem9 = GUICtrlCreateMenu("Extra")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func Save()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = GUICtrlRead($IGold)
$GExp = GUICtrlRead($IExp)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
EndFunc

Func Close()
   Exit
EndFunc

While 1
    Sleep(100)
WEnd
Edited by mikell

Share this post


Link to post
Share on other sites

Use these functions instead:

Func Save()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $IGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
EndFunc

Func StartGame()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = GUICtrlRead($IGold)
$GExp = GUICtrlRead($IExp)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $IExp)
Main()
EndFunc

Func Close()
    Save()
   Exit
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

 

You have duplicate instructions, and instructions which are not placed in the proper function

Try this

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GName, $GClass, $GRace, $GGold, $GExp, $IName, $IClass, $IRace, $IGold, $IExp
Global $GStart, $GNewGame

Start()

Func Start()
$GStart = GUICreate("Name of Game", 204, 80, 377, 133)
$BNewGame = GUICtrlCreateButton("New Game", 40, 5, 121, 33)
GUICtrlSetOnEvent(-1, "NewGame")
$BLoadGame = GUICtrlCreateButton("Load Game", 40, 40, 121, 33)
GUICtrlSetOnEvent(-1, "Load")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func NewGame()
GuiDelete($GStart)
$GNewGame = GUICreate("New Game", 244, 167, 451, 208)
$IName = GUICtrlCreateInput("Name", 56, 16, 129, 21)
$IClass = GUICtrlCreateInput("Class", 56, 43, 129, 21)
$IRace = GUICtrlCreateInput("Race", 56, 70, 129, 21)
$BStart = GUICtrlCreateButton("Start Game", 80, 100, 77, 33)
GUICtrlSetOnEvent(-1, "StartGame")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func StartGame()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = 500
$GExp = 0
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
GuiDelete($GNewGame)
Main()
EndFunc

Func Load()
GuiDelete($GStart)
$sIniFile = FileOpenDialog ( "Select your character", @ScriptDir & "\*.ini", "User Data (*.ini)")
If Not @error Then
        $GName = StringRegExpReplace($sIniFile, '.+\\([^.]+)\.?.*', "$1")
        $GClass = IniRead ($sIniFile, $GName, "Class", "Error")
        $GRace = IniRead ($sIniFile, $GName, "Race", "Error")
        $GGold = IniRead ($sIniFile, $GName, "Gold", "Error")
        $GExp = IniRead ($sIniFile, $GName, "EXP", "Error")
    EndIf
Main()
EndFunc

Func Main()
;$GGold = IniRead (@ScriptDir & "\" & $GName & ".ini", $GName, "Gold", "default" )
;$GExp = IniRead (@ScriptDir & "\" & $GName & ".ini", $GName, "EXP", "default" )
$GMain = GUICreate("Name of Game", 1004, 682, 255, 120)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Save", $MenuItem1)
GUICtrlSetOnEvent(-1, "Save")
$MenuItem3 = GUICtrlCreateMenuItem("Load", $MenuItem1)
GUICtrlSetOnEvent(-1, "Load")
$MenuItem4 = GUICtrlCreateMenuItem("Options", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("Character")
$MenuItem6 = GUICtrlCreateMenuItem("Status", $MenuItem5)
$MenuItem7 = GUICtrlCreateMenuItem("Inventory", $MenuItem5)
$MenuItem8 = GUICtrlCreateMenuItem("Battle", $MenuItem5)
$MenuItem9 = GUICtrlCreateMenu("Extra")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
EndFunc

Func Save()
$GName = GUICtrlRead($IName)
$GClass = GUICtrlRead($IClass)
$GRace = GUICtrlRead($IRace)
$GGold = GUICtrlRead($IGold)
$GExp = GUICtrlRead($IExp)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Name", $GName)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Class", $GClass)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Race", $GRace)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "Gold", $GGold)
IniWrite (@ScriptDir & "\" & $GName & ".ini" , $GName, "EXP", $GExp)
EndFunc

Func Close()
   Exit
EndFunc

While 1
    Sleep(100)
WEnd

Thanks ^^ now i can continue working on it when i have a class:)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...