Jump to content

My stupid label won't update.


Recommended Posts

One of my labels is being a pain. Maybe I typed something wrong or something. I am not getting any errors, but my label won't update. Take a look at my script please. I marked my trouble spots on the the script with ";HELP HERE;;;;HELP HERE". Every thing related to the problem that I can think of is maked. Here it is.

#include <GUIConstants.au3>

#region - Global

Global $MainGUI; THE MAIN GUI
Global $Width = 700; THE WIDTH OF ALL GUIS
Global $Height = 500; THE HEIGHT OF ALL GUIS
Global $Filemenu; FILE MENU IN THE MAIN GUI 
Global $Newgameitem; ITEM IN THE FILE MENU OF THE MAIN GUI
Global $Exititem; ITEM IN THE FILE MENU OF THE MAIN GUI
Global $ButtonA; BUTTON NAMED 'A' IN THE MAIN GUI
Global $ButtonB; BUTTON NAMED 'B' IN THE MAIN GUI
Global $ButtonC; BUTTON NAMED 'C' IN THE MAIN GUI
Global $Questlabel; A LABEL USED TO TRANSMIT THE DATA FROM THE Quest.INI FILE TO THE MAIN GUI 
Global $msg; IS USED TO GET THE MESSAGES FROM THE GUI
Global $Newcount = IniRead ("Character.ini", "Counter", "count", "0" ) + 1; IS USED WITH - Iniwrite ( "Character.ini", "Counter", "count", $Newcount ) - SO THAT $Count = IniRead ("Character.ini", "Counter", "count", "0" ) - WILL EQUAL A NEW VALUE
Global $Count = IniRead ("Character.ini", "Counter", "count", "0" ); IS USED WITH $QuestA, $QuestB AND $QuestC SO THAT THEY WILL READ DIFFERENT LINES AS THE BUTTONS A, B AND C ARE PUSH AND THEN SEND THE DATA TO THE LABEL NAMED $Questlabel
Global $QuestA = IniRead ("Quest.ini", "QuestA",$Count,"error"); DATA TO BE SENT TO THE LABEL
Global $QuestB = IniRead ("Quest.ini", "QuestB",$Count,"error"); DATA TO BE SENT TO THE LABEL
Global $QuestC = IniRead ("Quest.ini", "QuestC",$Count,"error"); DATA TO BE SENT TO THE LABEL


Global $characterName = IniRead ( "character.ini", "character", "name", "unknown" )
Global $maxlife = IniRead ( "character.ini", "character", "maxlife", "unknown" ) 
Global $Life = IniRead ( "character.ini", "character", "life", "unknown" )
Global $def = IniRead ( "character.ini", "character", "def", "unknown" )
Global $tohit = IniRead ( "character.ini", "character", "tohit", "unknown" )
Global $dam = IniRead ( "character.ini", "character", "dam", "unknown" )

#region - Character Setup GUI Globals

Global $CharactersetupGUI; THE GUI THAT IS USED TO SET UP THE CHARACTER IN THE GAME AT THE START(THIS GUI IS STILL BARE)

#endregion
#region - Combat GUI Globals
Global $CombatGUI; THE GUI USED FOR COMBAT IN THE GAME(THIS GUI IS STILL BARE)
Global $ButtonAttack; A BUTTON IN THE COMBAT GUI THAT IS TO BE USED TO ATTACK
Global $ButtonDefend
Global $ButtonRun


#endregion
#endregion


#Region - RPG GUI Create
$MainGUI = GUICreate ("RPG",$width, $Height)

$Filemenu = GuiCtrlCreateMenu ("File")
$Newgameitem = GUICtrlCreateMenuitem ("New Game", $Filemenu)
$Exititem = GuiCtrlCreateMenuitem ("Exit", $Filemenu)
$ButtonA = GUICtrlCreateButton ("A.", 100,440,70,20)
$ButtonB = GUICtrlCreateButton ("B.", 235,440,70,20)
$ButtonC = GUICtrlCreateButton ("C.", 370,440,70,20)
$Questlabel = GUICtrlCreateLabel("Welcome to my RPG. Choose a button. Either button A,B or C and see what the result is.", 12,20, 509, 399);THE STARTING LINE OF THE LABEL
GUICtrlSetData($Questlabel,"Welcome to my RPG. Choose a button. Either button A,B or C and see what the result is.")
GUICtrlCreateGroup("",9,10,510,400)
;BETWEEN COLUMES 1 AND 2 AND ON TOP OF

GUICtrlCreateGroup($characterName ,550,10,140,400)
            
             
            GUICtrlCreateLabel ("Max Life",  565, 55, 40, 15)
            GUICtrlCreateLabel ("Life",  565, 70, 40, 15)
            GUICtrlCreateLabel ("Def",  565, 85, 40, 15)
            GUICtrlCreateLabel ("To Hit",  565, 100, 40, 15) 
            GUICtrlCreateLabel ("Dam",  565, 115, 40, 15) 
           ;COLUME 2            
GUICtrlCreateLabel ("Value",  635, 40, 40, 15) 
            GUICtrlCreateLabel ($MaxLife,  635, 55, 40, 15)
;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;           
$LifeLabel = GUICtrlCreateLabel ("unknown",  635, 70, 40, 15);;HELP HERE;;;;HELP HERE;;
GUICtrlSetData($LifeLabel,"unknown");;HELP HERE;;;;HELP HERE;;

            GUICtrlCreateLabel ($Def,  635, 85, 40, 15)
            GUICtrlCreateLabel ($ToHit,  635, 100, 40, 15) 
            

GuiSetState(@SW_SHOW)
#endregion

#region - Combat GUI Create
$CombatGUI = GUICreate ("Combat", $width, $Height)
$ButtonAttack = GUICtrlCreateButton ("Attack.", 100,440,70,20)
$ButtonDefend = GUICtrlCreateButton ("Defend", 315,440,70,20)
$ButtonRun = GUICtrlCreateButton ("Run.", 530,440,70,20)

;BETWEEN COLUMES 1 AND 2 AND ON TOP OF THEM
            GUICtrlCreateLabel ($characterName,  600, 25, 40, 15) 
        ;COLUME 1
            GUICtrlCreateLabel ("Stat",  565, 40, 40, 15) 
            GUICtrlCreateLabel ("Max Life",  565, 55, 40, 15)
            GUICtrlCreateLabel ("Life",  565, 70, 40, 15)           
            GUICtrlCreateLabel ("Def",  565, 85, 40, 15)
            GUICtrlCreateLabel ("To Hit",  565, 100, 40, 15) 
            GUICtrlCreateLabel ("Dam",  565, 115, 40, 15) 
           ;COLUME 2            
            GUICtrlCreateLabel ("Value",  635, 40, 40, 15) 
            GUICtrlCreateLabel ($MaxLife,  635, 55, 40, 15)
            GUICtrlCreateLabel ($Life,  635, 70, 40, 15)            
            GUICtrlCreateLabel ($Def,  635, 85, 40, 15)
            GUICtrlCreateLabel ($ToHit,  635, 100, 40, 15) 
            GUICtrlCreateLabel ($Dam,  635, 115, 40, 15) 
GuiSetState(@SW_HIDE)
#endregion

#region - Character Setup  GUI Create 
$CharactersetupGUI = GUICreate ("Character Setup", $width, $Height)
GuiSetState(@SW_HIDE)


#endregion

#Region - GUI SelectLoop

While 1
    $msg = GUIGetMsg()

Select

    Case $msg = -3;$GUI_EVENT_CLOSE
        Iniwrite ( "Character.ini", "Counter", "count", "0" ); THIS IS TEMPORARY LINE SO I DON'T HAVE TO REWRITE THE VALUE OF THE COUNT IN THE CHARACTER.INI FILE. I PLAN ON REMOVING IT WHEN I AM DONE SO THAT BY NOT RESETTING THE VAULE TO ZERO IT WILL BE LIKE AN AUTOMATIC WAY OF SAVING THE GAME IN PROGRESS.
    ExitLoop

    Case $msg = $Newgameitem
        GUISetState(@SW_HIDE,$MainGUI)
        GUISetState(@SW_SHOW,$CharactersetupGUI)
        GUISetState(@SW_HIDE,$CombatGUI)
    Case $msg = $exititem
            ExitLoop
;;HELP HERE;;;;HELP HERE;;;;HELP HERE;; 
    Case $msg = $ButtonA 
         Call("_NexlineonQuestA") 
         Call ("_Add1tolife");;HELP HERE;;;;HELP HERE;;;;HELP HERE;;         
         
    Case $msg = $ButtonB 
         Call("_NexlineonQuestB") 
         Call ("_Add1tolife");;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;

    Case $msg = $ButtonC 
        Call("_NexlineonQuestC")
        Call ("_Add1tolife");;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
        
    Case $QuestA = "combat"  
        call("_Swaptocombat")
        Call("_NexlineonQuestA")
        
    Case $QuestB = "combat"  
        call("_Swaptocombat")
        Call("_NexlineonQuestB")
        
    Case $QuestC = "combat"  
        call("_Swaptocombat")
        Call("_NexlineonQuestC")
    Case $msg = $ButtonRun 
        Call("_Swaptomaingui")
        
            
EndSelect

WEnd
#EndRegion
; Start - Functions
;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
Func _Add1tolife();;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
    If $Life < $maxlife Then;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
         $Lifeplusone = IniRead ("Character.ini", "character", "life", "0" ) + 1;;HELP HERE;;;;HELP HERE;;
         IniWrite ("Character.ini", "character", "life", $Lifeplusone );;HELP HERE;;;;HELP HERE;;;ADDS ONE TO THE VALUE LIFE IN THE INI FILE
         $Life = IniRead ( "character.ini", "character", "life", "unknown" );;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
         GUICtrlSetData($LifeLabel,$Life);;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
          EndIf;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;
EndFunc;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;

Func _Swaptocombat()
    GUISetState(@SW_HIDE,$MainGUI)
    GUISetState(@SW_HIDE,$CharactersetupGUI)
    GUISetState(@SW_SHOW,$CombatGUI)
EndFunc

Func _Swaptomaingui()
    GUISetState(@SW_SHOW,$MainGUI)
    GUISetState(@SW_HIDE,$CharactersetupGUI)
    GUISetState(@SW_HIDE,$CombatGUI)
EndFunc
Func _NexlineonQuestA()
    $Newcount = IniRead ("Character.ini", "Counter", "count", "0" ) + 1
         Iniwrite ( "Character.ini", "Counter", "count", $Newcount )
         $Count = IniRead ("Character.ini", "Counter", "count", "0" )
         $QuestA = IniRead ("Quest.ini", "QuestA",$Count,"error")
         GUICtrlSetData($Questlabel,$QuestA);CHANGES THE DATA IN THE LABEL TO $QuestA
EndFunc

Func _NexlineonQuestB()
    $Newcount = IniRead ("Character.ini", "Counter", "count", "0" ) + 1
         Iniwrite ( "Character.ini", "Counter", "count", $Newcount )
         $Count = IniRead ("Character.ini", "Counter", "count", "0" )
         $QuestB = IniRead ("Quest.ini", "QuestB",$Count,"error")
         GUICtrlSetData($Questlabel,$QuestB);CHANGES THE DATA IN THE LABEL TO $QuestB
EndFunc

Func _NexlineonQuestC()
    $Newcount = IniRead ("Character.ini", "Counter", "count", "0" ) + 1
         Iniwrite ( "Character.ini", "Counter", "count", $Newcount )
         $Count = IniRead ("Character.ini", "Counter", "count", "0" )
         $QuestC = IniRead ("Quest.ini", "QuestC",$Count,"error")
         GUICtrlSetData($Questlabel,$QuestC);CHANGES THE DATA IN THE LABEL TO $QuestC
EndFunc

Func _F()
EndFunc

Func _G()
EndFunc

Func _H()
EndFunc

Func _I()
EndFunc

Func _J()
EndFunc

The INI files are Quest and Character

[QuestA]
1=a1
2=a2
3=3a
4=a4
5=a5
6=a6
7=a7
8=a8
9=a9
10=a10
11=a11
12=a12
13=a13
14=a14
15=a15
16=a16
[QuestB]
1=b1
2=b2
3=b3
4=b4
5=b5
6=b6
7=b7
8=b8
9=b9
10=b10
11=b11
12=b12
13=b13
14=b14
15=b15
16=b16
[QuestC]
1=c1
2=c2
3=combat
4=c4
5=c5
6=c6
7=c7
8=c8
9=c9
10=c10
11=c11
12=c12
13=c13
14=c14
15=c15
16=c16
[1]
encountertext=
name=monster1
maxlife=20
life=1
def=9
tohit=8
dam=7
itemcode=
[2]
encountertext=
name=monster2
maxlife=20
life=1
def=9
tohit=8
dam=7
itemcode=
[Itemcode];code for reading the item
1=
[Itemcodetext];this well go with the itemcode, for display purpose only.
1=

AND

[character]
name=quick_sliver007
maxlife=20
life=3
def=9
tohit=8
dam=7
[Counter]
count=0

If you run this Script you can see that the $QuestLabel works just fine and I did it the same way I did the $LifeLabel. I just don't get why the label is not adding one to the life if it is less then the maxlife with every click of the buttons A,B and C.

Please help.

.

Link to comment
Share on other sites

One of my labels is being a pain. Maybe I typed something wrong or something. I am not getting any errors, but my label won't update.

Func _Add1tolife();;HELP HERE;;;;HELP HERE;;;;HELP HERE;;

    If $Life < $maxlife Then;;HELP HERE;;;;HELP HERE;;;;HELP HERE;;

<{POST_SNAPBACK}>

Put the following as the first line in the _Add1tolife function and run the script? Does the comparison equal 0 or 1?

MsgBox(4096, "DEBUG", $Life & "<" & $maxlife & " = " & ($Life < $maxlife))

The comparison of ($Life < $MaxLife) fails when their values are strings instead of "real" integers. Strings are compared one character at a time, so when, for example, $Life = "3" and $MaxLife = "20", the comparison ($Life < $MaxLife) returns 0 since 3 is greater than 2.

To resolve the problem, convert the strings to integers when they are being compared (see the "Number" function).

Phillip

Link to comment
Share on other sites

Put the following as the first line in the _Add1tolife function and run the script?  Does the comparison equal 0 or 1?

MsgBox(4096, "DEBUG", $Life & "<" & $maxlife & " = " & ($Life < $maxlife))

The comparison of ($Life < $MaxLife) fails when their values are strings instead of "real" integers.  Strings are compared one character at a time, so when, for example, $Life = "3" and $MaxLife = "20", the comparison ($Life < $MaxLife) returns 0 since 3 is greater than 2.

To resolve the problem, convert the strings to integers when they are being compared (see the "Number" function).

<{POST_SNAPBACK}>

THANK YOU. I didn't know that.

Here is the result.

1st is the way the label starts and the way I really want it to.

$LifeLabel = GUICtrlCreateLabel ($life,  635, 70, 40, 15) 
GUICtrlSetData($LifeLabel,$life)

And here is the function to change it.

Func _Add1tolife()
    If $NLife < $Nmaxlife Then
         $Lifeplusone = IniRead ("Character.ini", "character", "life", "0" ) + 1
         $Nlifeplusone = Number($Lifeplusone)
         IniWrite ("Character.ini", "character", "life", $NLifeplusone )
         $Life = IniRead ( "character.ini", "character", "life", "unknown" )
         $Nlife = Number($life)
         GUICtrlSetData($LifeLabel,$NLife)
          EndIf

Thank you again. I have a feeling this script is going to be very long when I am done with it. I also think I will be hitting this forum atleast 20 more times with this script, but I hope not. Well any ways, what do you think of this script so for.

.

Link to comment
Share on other sites

Hey quick_sliver007,

That worked for me too, but I had to initialize $NLife and $Nmaxlife to get it to work (I assume you did that but did not post that part). Anyway good job on applying "Number". Since you're doing so well, I didn't want to tell you exactly what to do.

I can't be certain of you plans, but I don't see where $Life is currently being used after calling function _Add1tolife. If that is correct, you do not have to update it. If you will be needing it, and you want $Life to be a string, you could use the "String" function to convert $NLife instead of reading the INI file (which is always slower than working in RAM).

Here's how I see it:

Func _Add1tolife()
   If $NLife < $Nmaxlife Then
      $NLife = Number(IniRead("Character.ini", "character", "life", "0")) + 1
      IniWrite("Character.ini", "character", "life", $NLife)
      GUICtrlSetData($LifeLabel, $NLife)
   EndIf
EndFunc  ;==>_Add1tolife

Phillip

Link to comment
Share on other sites

Hey quick_sliver007,

That worked for me too, but I had to initialize $NLife and $Nmaxlife to get it to work (I assume you did that but did not post that part).  Anyway good job on applying "Number".  Since you're doing so well, I didn't want to tell you exactly what to do.

I can't be certain of you plans, but I don't see where $Life is currently being used after calling function _Add1tolife.  If that is correct, you do not have to update it.  If you will be needing it, and you want $Life to be a string, you could use the "String" function to convert $NLife instead of reading the INI file (which is always slower than working in RAM).

Here's how I see it:

Func _Add1tolife()
   If $NLife < $Nmaxlife Then
      $NLife = Number(IniRead("Character.ini", "character", "life", "0")) + 1
      IniWrite("Character.ini", "character", "life", $NLife)
      GUICtrlSetData($LifeLabel, $NLife)
   EndIf
EndFunc  ;==>_Add1tolife

<{POST_SNAPBACK}>

I still don't know much about strings yet. I didn't even know about Autoit until about 4-5 weeks ago and it is my only Exp with programing. I been using the INI file because I plan on using it as a Saved game file in the program. Also I don't plan on using a load game, more like you start off where you last Saved. So $life will be need ever time the user opens the program. While I am at it, I got a question. Can that Au3 file named Encrypt be included and be used to read the Ini files if I encrypt them. Also to write Encrypted to the Ini file Character. To keep the user of the program from playing with their stats in the Character.ini and from reading a head in the Quest.ini. I mean after I complie the game, will the encryption work or does that only work in the uncomplied version. I am saving this part of the coding for last. But, I would like to know if I can plan on that part working or not.

And I just thought of something else. That I will try later. Can I avoid all of those IniWrite with this instead.

Func _Add1tolife()

      $ReadLife = GuictrlRead($LifeLabel)
      $ReadMaxlife = GuictrlRead($MaxLifeLabel)
      $Nlife = Number($ReadLife)
      $NMaxlife = Number($ReadMaxLife)  
   If $NLife < $Nmaxlife Then
      GUICtrlSetData($LifeLabel, $NLife + 1)
   EndIf
EndFunc ;==>_Add1tolife

Would this save Ram by reading from the GUI instead of the Ini file. Keep everthing in the program.

And if the menu item save is click then to write it in the Ini file. like in my while 1 function

Case $msg = $save

ini write ect.........

Edited by quick_sliver007

.

Link to comment
Share on other sites

An encryption script could be included in your script, and the ini file could be encrypted/decrypted on the fly. However, the file ENCRYPT.AU3 in the AutoIt Advanced folder is not what you want. It's simply a GUI that interfaces with the script that actually does the encryption. What you want is the function that the GUI calls (look up "_StringEncrypt" in the help file).

Your new _Add1tolife function would reduce hard disk activity but not RAM as RAM is needed to store the values for each variable. However, everything in the GUI is in RAM, so I believe getting the values from there will be faster that from the INI file, depending on circumstances. For example, if you request the same data from the GUI a number of times, and each time you have to transpose the data from a strings to a numbers, then it is probably better to read and transpose that value once and save it in its own variable. With all data in RAM, updating the INI file could be done only when the script terminates.

All of that said, unless you really need to optimize your script for performance issues, you don't have to be concerned with this stuff. Just keep it in mind while you concentrate on just getting everything working.

If you want to optimize the _Add1tolife function, take a look at the following:

Between the GUISetState function and While function, add this line:

Global $NLife = 0, $Nmaxlife = Number($maxlife)

In the Case $msg = -3 section (for when you are ready to remove the temporary code that sets Counter to zero), update the Character.INI file (if desired, encrypt the data here).

IniWrite("Character.ini", "Counter", "count", $NLife)
;;;                IniWrite("Character.ini", "Counter", "count", "0"); ...TEMPORARY...

Then define the _Add1tolife function like this:

Func _Add1tolife()
   If $NLife < $Nmaxlife Then
      $NLife = $NLife + 1
      GUICtrlSetData($LifeLabel, $NLife)
   EndIf
EndFunc;==>_Add1tolife

Have fun!

Phillip

Link to comment
Share on other sites

An encryption script could be included in your script, and the ini file could be encrypted/decrypted on the fly.  However, the file ENCRYPT.AU3 in the AutoIt Advanced folder is not what you want.  It's simply a GUI that interfaces with the script that actually does the encryption.  What you want is the function that the GUI calls (look up "_StringEncrypt" in the help file).

Your new _Add1tolife function would reduce hard disk activity but not RAM as RAM is needed to store the values for each variable.  However, everything in the GUI is in RAM, so I believe getting the values from there will be faster that from the INI file, depending on circumstances.  For example, if you request the same data from the GUI a number of times, and each time you have to transpose the data from a strings to a numbers, then it is probably better to read and transpose that value once and save it in its own variable.  With all data in RAM, updating the INI file could be done only when the script terminates.

All of that said, unless you really need to optimize your script for performance issues, you don't have to be concerned with this stuff.  Just keep it in mind while you concentrate on just getting everything working.

If you want to optimize the _Add1tolife function, take a look at the following:

Between the GUISetState function and While function, add this line:

Global $NLife = 0, $Nmaxlife = Number($maxlife)

In the Case $msg = -3 section (for when you are ready to remove the temporary code that sets Counter to zero), update the Character.INI file (if desired, encrypt the data here).

IniWrite("Character.ini", "Counter", "count", $NLife)
;;;                   IniWrite("Character.ini", "Counter", "count", "0"); ...TEMPORARY...

Then define the _Add1tolife function like this:

Func _Add1tolife()
   If $NLife < $Nmaxlife Then
      $NLife = $NLife + 1
      GUICtrlSetData($LifeLabel, $NLife)
   EndIf
EndFunc;==>_Add1tolife

Have fun!

<{POST_SNAPBACK}>

Thank you Phil for all of the Information. I just got done looking at the _StringEncrypt. I think will use it for when saving the character's stats, but not in the quest file. Because of the amount that would be needed to encrypted in the Quest file would be large and would slow down the program way too much. I may use _StringReverse just to make it harder for people to read a head in the quest file.

.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...