Jump to content

Help with simplifing script please


Recommended Posts

Im making a script called RunePro for the game Diablo II, it's function will be for people to insert a rune name or abbreviation and all the info for that runeword will come up on the screen.

This is the main script...

;Title: RunePro
;Author: SupraNatural

;Include
#include <GuiConstants.au3>
#include <Rune Definitions.au3>
;Create Window
GuiCreate("RunePro", 755, 200)
GuiSetState()

;Credit
MsgBox(0,"Credit", "All Runeword pictures/text come from http://www.battle.net/diablo2exp/items/runewords.shtml")
;Create InputBox
$InputRuneWord = GUICtrlCreateInput ( "", 1,  179, 300, 20)
$btn = GUICtrlCreateButton ("OK", 330,  179, 60, 20)

;Gui Loop
Do
    $RuneWord = GUICtrlRead($InputRuneWord)
    
    $msg = GUIGetMsg()
    
If $msg = $btn Then
        
    If $RuneWord = $RuneWords[1][0] Then
        GuiCtrlCreatePic("CTA.gif",0,0, 754,168)
    ElseIf $RuneWord = $RuneWords[1][1] Then
        GuiCtrlCreatePic("CTA.gif",0,0, 754,168)
    EndIf
    
EndIf

Until $msg = $GUI_EVENT_CLOSE

This is the include script..

Dim $RuneWords[2][2]
$RuneWords[1][0] = "Call to Arms"
$RuneWords[1][1] = "CTA"

What i need help with is in this part.

If $RuneWord = $RuneWords[1][0] Then
        GuiCtrlCreatePic("CTA.gif",0,0, 754,168)
    ElseIf $RuneWord = $RuneWords[1][1] Then
        GuiCtrlCreatePic("CTA.gif",0,0, 754,168)
    EndIf

Is it possible to make it so that i don't have to make an IF statement for every rune? i.e. RuneWords[2][0], RuneWords[3][0], etc.. Any help is appreciated

EDIT: Here is the Pic i use in the script.

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Not sure why your using a multi-demensional array when the following should do it.

Dim $RuneWords[3]
$RuneWords[0] = 2
$RuneWords[1] = "Call to Arms"
$RuneWords[2] = "CTA"

For $x 1 to $RuneWords[0]
  If $RuneWord = $RuneWords[$x] Then
        GuiCtrlCreatePic("CTA.gif",0,0, 754,168)
    EndIf
next

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I forgot what i was thinking when i did that..hate it when that happens... Anyway, thats almost perfect except I need it to be a different picture for ever number. Like $RuneWords[1] = Cta.gif, $RuneWords[2] = venom.gif, etc, etc.

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Dim $RuneWords[3][2]
$RuneWords[0][0] = 2
$RuneWords[1][0] = "Call to Arms"
$RuneWords[1][1] = "Cta.gif"
$RuneWords[2][0] = "CTA"
$RuneWords[2][1] = "venom.gif"

For $x 1 to $RuneWords[0][0]
  If $RuneWord = $RuneWords[$x][0] Then
        GuiCtrlCreatePic$RuneWords[$x][1],0,0, 754,168)
    EndIf
next
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I think i got an idea, what if i made all the .gif files the same name as the runewords. I.E. they enter Black, and Black.Gif shows up. I can make a copy for the abbreviations too. The only thing is how do i get the text they entered into that, maybe using something like;

GuiCtrlCreatePic(GUICtrlRead($InputRuneWord),0,0, 754,168)

If that's even possible.

Edit: That didnt work, I just realized I can't add a .gif at the end.

Edit2:

GuiCtrlCreatePic(@ScriptDir & "\" & "Pics" & "\" & $RuneWord,0,0, 754,168)

This will work only if i add .gif to the end of the definition..hmm

Here is what i got so far, try it out and enter venom.gif or ven.gif.

Make sure you rename the Rune_Definitions.au3 to Rune Definitions.au3 and put the .gif files in a folder named pics like this -> Script Folder/Pics/.gif files

Rune_Definitions.au3

RunePro.au3

< - Venom.gif

< - VEN.gif

Same picture but one for the abbreviation.

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Why are you making a .gif with just text information? If you are just displaying text, there is no need for an image; it just wastes time and space. I would suggest using a multi-dimensional array, where $info[1][0] is the name that you type in, $info[1][1] is one section of the info, and so on. Then you display each part in a separate text box. if you want it all cool and black, you can still do that with styles and extended styles.

Also, this way abbreviations would work. Such as:

; warning, this might be super crappy because I'm running off 3 hours of sleep
$nameInput = "Dev"
For $i = 1 to $info[0][0] 
     If $nameInput = StringLeft ( $info[$i][0], StringLen($nameInput) ) Then
          ;Display info in corresponding labels or text boxes
     EndIf 
Next

This could also be done with a database, ini file (easiest IMO), or flat text file. All would work and be easier than an image for each item.

For the ini file, each section name could be the name, and the keys could correspond with the different categories of info. Grab all the section names, find the best match, and display all the keys into labels or text boxes.

Link to comment
Share on other sites

Im kinda confused what you did there and im not sure you fully understand what its supposed to do. Hoewever I do like the INI file idea, the pictures are just alot easier to say GuiCtrlCreatePic then INIread like 5 times for each runeword. The point of the program is for the user to enter a name of a runeword or its abbreviation (wish i could make it auto-complete but im not that good yet).

example:

1) User enter the name Venom or Ven

2)Venom.gif appears in window with all the information about what the venom runeword does.

Simple yet useful for the game, now I realize how much easier text would be so im going to try a few different things. Thanks for the help.

Edit: Also i want it to be on seperate lines, how can i make autoit do that?

example

RuneWord Stats:

1-2 damge

+100 HP

+201 MP

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Ok, it's really quite simple to use an .ini file. Here's an example file (I'm just making up crap):

[Venom]
Damage = 1-2
HP = +100
MP = +201

[Ice]
Damage = 2-4
HP = +40
MP = +400

I don't have time to write out the script for you, but I'll give it to you step by step.

1. read the section names: $Runes = IniReadSectionNames ( "filename.ini" )

this return an array containing all the section names (the names in brackets)

2. Using a For loop, go through each section name, and see if any of the section names match the user input, in part or whole. That's what my code above did.

3. When you get to a match, user InireadSection() or Iniread() to grab all the keys, and display their info.

$fileName = "file.ini"
$Runes =  IniReadSectionNames ( $fileName )
$nameInput = "Ven"   ;This is what the user typed
For $i = 1 to $Runes[0]   ;$Runes[0]is the size of the array

    ;the inputted text ("ven") and taking the the length of it (3)
     $length = StringLen($nameInput)
     
    ;Now we compare the first X (in this case 3) letters of each rune to the inputted text

     If $nameInput = StringLeft ( $Runes[$i], $length ) Then
          $Section = $Runes[$i]
           ExitLoop   ;optional, but just to save time. I THINK this is the proper use
     EndIf 
Next

;ok, now you know what section, so read the info. you can do this two ways but I'll 
;do it the long way for you to understand

;take each section and display it
$Damage = IniRead( $fileName, $Section, "Damage","0" )
$HP = IniRead( $fileName, $Section, "HP","0" )
$MP = IniRead( $fileName, $Section, "MP","0" )

;Now just display this info accordingly, in labels, text boxes or what not.

OK, so I basically wrote it for you... :whistle: I hope this helps, and if not...

:dance::dance:

Link to comment
Share on other sites

Do
    $RuneWord = GUICtrlRead($InputRuneWord)
    $msg = GUIGetMsg()
    $stats = IniReadSection( "RuneDefinitions.ini" , $runeword)
If $msg = $btn Then
        
    If $RuneWord = $RuneWords[1][0] Then
        For $i = 1 To $stats[0][0]
        GuiCtrlCreateLabel(@CRLF & $stats[$i][1], 20, 20, 180, 180)
        Next
        GUICtrlSetColor(-1,0xFFFFFF)
    ElseIf $RuneWord = $RuneWords[1][1] Then
        GuiCtrlCreateLabel($RuneWord, 10, 20, 200, 20)
        GUICtrlSetColor(-1,0xFFFFFF)
    EndIf
    
EndIf

Until $msg = $GUI_EVENT_CLOSE

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Do
    $RuneWord = GUICtrlRead($InputRuneWord)
    $msg = GUIGetMsg()
    $stats = IniReadSection( "RuneDefinitions.ini" , $runeword)
If $msg = $btn Then
        
    If $RuneWord = $RuneWords[1][0] Then
        For $i = 1 To $stats[0][0]
        GuiCtrlCreateLabel(@CRLF & $stats[$i][1], 20, 20, 180, 180)
        Next
        GUICtrlSetColor(-1,0xFFFFFF)
    ElseIf $RuneWord = $RuneWords[1][1] Then
        GuiCtrlCreateLabel($RuneWord, 10, 20, 200, 20)
        GUICtrlSetColor(-1,0xFFFFFF)
    EndIf
    
EndIf

Until $msg = $GUI_EVENT_CLOSE

<{POST_SNAPBACK}>

So what happens if the user types in an abbreviation?
Link to comment
Share on other sites

So what happens if the user types in an abbreviation?

<{POST_SNAPBACK}>

I get errors when i try to run your script;

RunePro.au3 (30) : ==> Subscript used with non-Array variable.:

For $i = 1 to $stats[0][0]

For $i = 1 to $stats^ ERROR

Edit: Heres what i got

Do
$msg = GUIGetMsg()
$fileName = "RuneDefinitions.ini"
$Runes =  IniReadSectionNames ( $fileName )
$nameInput = GUICtrlRead($InputRuneWord)  ;This is what the user typed
For $i = 1 to $Runes[0]  ;$Runes[0]is the size of the array

   ;the inputted text ("ven") and taking the the length of it (3)
     $length = StringLen($nameInput)
     
   ;Now we compare the first X (in this case 3) letters of each rune to the inputted text

     If $nameInput = StringLeft ( $Runes[$i], $length ) Then
          $Section = $Runes[$i]
           ExitLoop  ;optional, but just to save time. I THINK this is the proper use
     EndIf 
Next

;ok, now you know what section, so read the info. you can do this two ways but I'll 
;do it the long way for you to understand

;take each section and display it
$Equip = IniRead( $fileName, $Section, "Equip","0" )
$HP = IniRead( $fileName, $Section, "HP","0" )
$MP = IniRead( $fileName, $Section, "MP","0" )

        GuiCtrlCreateLabel($Equip, 20, 20, 180, 180)

Until $msg = $GUI_EVENT_CLOSE

And here is the error i get;

RunePro.au3 (46) : ==> Variable used without being declared.:

$Equip = IniRead( $fileName, $Section, "Equip","0" )

$Equip = IniRead( $fileName, ^ ERROR

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

I think i've got a solution! It's not waiting for the user to enter the name then click the OK button!

Edit: still getting the same undeclared error.

Edit2:

Do
    $msg = GUIGetMsg()
    $fileName = "RuneDefinitions.ini"
    $Runes =  IniReadSectionNames ( $fileName )
    $nameInput = GUICtrlRead($InputRuneWord)  ;This is what the user typed
If $msg = $btn Then 
    For $i = 1 to $Runes[0];$Runes[0]is the size of the array
        $length = StringLen($nameInput);the inputted text ("ven") and taking the the length of it (3)
     If $nameInput = StringLeft ( $Runes[$i], $length ) Then;Now we compare the first X (in this case 3) letters of each rune to the inputted text
            $Section = $Runes[$i]
            $Equip = IniRead( $fileName, $Section, "Equip","0" )
            $HP = IniRead( $fileName, $Section, "HP","0" )
            $MP = IniRead( $fileName, $Section, "MP","0" )
            GuiCtrlCreateLabel($Equip, 20, 20, 180, 180)
            ExitLoop  ;optional, but just to save time. I THINK this is the proper use
        EndIf 
    Next
EndIf

I put them into the loop and know when i type in "venom" or "ven" it just creates a blank black label.

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Ok, I wrote the entire program for you, but then you would never learn how to use autoit, so I don't know if I should give it to you. I can help you though.

One suggestion, use OnEvent mode, it is so much easier. Then use this function or something similar. It's really close to what I wrote before, but it actually sets the labels that need to be created somewhere else in the program.

Func getInfo()
    $Section = "0"
    $Runes =  IniReadSectionNames ( $fileName )
    $nameInput = GUICtrlRead($InputRuneWord);This is what the user typed
    For $i = 1 to $Runes[0];$Runes[0]is the size of the array
    
      ;the inputted text ("ven") and taking the the length of it (3)
         $length = StringLen($nameInput)
         
      ;Now we compare the first X (in this case 3) letters of each rune to the inputted text
    
         If $nameInput = StringLeft ( $Runes[$i], $length ) Then
              $Section = $Runes[$i]
               ExitLoop;optional, but just to save time. I THINK this is the proper use
         EndIf 
    Next
    
    
;ok, now you know what section, so read the info. you can do this two ways but I'll 
;do it the long way for you to understand
    
;take each section and display it. You need to have already created labels named $EquipLbl, $HPLbl, $MPLbl
    If $Section <> "0" Then
        GUICtrlSetData ( $EquipLbl, IniRead( $fileName, $Section, "Equip","0" ) )
        GUICtrlSetData ( $HPLbl, IniRead( $fileName, $Section, "HP","0" ) )
        GUICtrlSetData ( $MPLbl, IniRead( $fileName, $Section, "MP","0" ) )
    Else
        GUICtrlSetData ( $EquipLbl, "N/A" )
        GUICtrlSetData ( $HPLbl, "N/A" )
        GUICtrlSetData ( $MPLbl, "N/A" )
    EndIf    
            

EndFunc

Read the manual to figure out OnEvent mode. Otherwise you could still use the other way, and still have this function run if the button is pressed. Hopefully you can figure it out. If not, I have a complete working program.

Edited by Arrrghmatey
Link to comment
Share on other sites

Ok when i type in "venom" or "ven" it sets the information to all 0's and that is the default value if it isn't found, so I'm not sure what is wrong.

;Title: RunePro
;Author: SupraNatural

;Include
#include <GuiConstants.au3>
#include <Rune Definitions.au3>

Opt("GUIOnEventMode", 1)

;Create Window & Accesories
$mainwindow = GuiCreate("RunePro", 755, 250) 
;GUISetBkColor(0x000000)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
GuiCtrlCreateGroup("Runeword Stats", 5, 0,745,200)
$InputRuneWord = GUICtrlCreateInput ( "Enter runeword name/abbreviation.", 1,  222, 300, 20)
$getInfo = GUICtrlCreateButton ("OK", 330,  220, 60, 20)
GUICtrlSetOnEvent($getInfo, "getInfo")
$EquipLbl2 = GuiCtrlCreateLabel("Required Equipment", 20, 20, 100, 20)
$RunesLbl2 = GuiCtrlCreateLabel("Required Runes", 300, 20, 100, 20)
$StatsLbl2 =GuiCtrlCreateLabel("Runeword Stats", 600, 20, 100, 20)
$EquipLbl = GuiCtrlCreateLabel("N/A", 20, 40, 100, 100)
$RunesLbl = GuiCtrlCreateLabel("N/A", 300, 40, 100, 100)
$StatsLbl =GuiCtrlCreateLabel("N/A", 600, 40, 100, 100)
GUISetState(@Sw_Show)

;Credit
MsgBox(0,"Credit", "All runeword information comes from http://www.battle.net/diablo2exp/items/runewords.shtml")
MsgBox(0,"Notes", "BEFORE USING ANY RUNEWORDS READ THE NOTES.TXT FILE. PLEASE!")

;Idle Around
While 1
    Sleep(1000)
WEnd

;Exit function
Func Close()
    If @GUI_WINHANDLE = $mainwindow Then 
        Exit
    EndIf
EndFunc

;Read INI & Set Labels
Func getInfo()
    $fileName = "RuneDefinitions.ini"
    $Section = "0"
    $Runes =  IniReadSectionNames ( $fileName )
    $nameInput = GUICtrlRead($InputRuneWord);This is what the user typed
    For $i = 1 to $Runes[0];$Runes[0]is the size of the array
    
     ;the inputted text ("ven") and taking the the length of it (3)
         $length = StringLen($nameInput)
         
     ;Now we compare the first X (in this case 3) letters of each rune to the inputted text
    
         If $nameInput = StringLeft ( $Runes[$i], $length ) Then
              $Section = $Runes[$i]
               ExitLoop;optional, but just to save time. I THINK this is the proper use
         EndIf 
    Next
    
    
;ok, now you know what section, so read the info. you can do this two ways but I'll 
;do it the long way for you to understand
    
;take each section and display it. You need to have already created labels named $EquipLbl, $HPLbl, $MPLbl
    If $Section <> "0" Then
        GUICtrlSetData ( $EquipLbl, IniRead( $fileName, $Section, "Equip","0" ) )
        GUICtrlSetData ( $RunesLbl, IniRead( $fileName, $Section, "Runes","0" ) )
        GUICtrlSetData ( $StatsLbl, IniRead( $fileName, $Section, "Stats","0" ) )
    Else
        GUICtrlSetData ( $EquipLbl, "N/A" )
        GUICtrlSetData ( $RunesLbl, "N/A" )
        GUICtrlSetData ( $StatsLbl, "N/A" )
    EndIf   
            

EndFunc

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

Link to comment
Share on other sites

Show me your .ini file. Also, why include <Rune Definitions.au3>?? what's in it?

<{POST_SNAPBACK}>

Nothing in it, forgot it was there

[Venom]
Equip=3 Socket Weapons
Runes=Tal + Dol + Mal
Stats=Hit Causes Monster To Flee 25%
Stats=Prevent Monster Heal
Stats=Ignore Target's Defense
Stats=7% Mana Stolen Per Hit
Stats=Level 15 Poison Explosion (27 Charges)
Stats=Level 13 Poison Nova (11 Charges)
Stats=+273 Poison Damage Over 6 seconds

there is my ini file.

Edit: Took out Lbl in the ini file, and it works now except it only shows 1 line of the stats, how can i include all the lines?

Edited by SupraNatural

Visit http://www.blizzedout.com/forums/register....referrerid=8306 for the top blizzard hacks. WoW, TfT, D2/LOD, CS. You name it we got it!

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...