Jump to content

ok .. need some array help.


Recommended Posts

been a while since i tackled them.. and wasnt that gread at them last time

anyway. its coming up with a error, and cant seem to figure out why. and the help file isnt helping me much this time :huggles:

here it is, hopefully someone can help :D

;Save Function

Global $charactername , $characterlevel , $charactersex



;declare the array
for $a = 20 to 0 step -1
    for $b = 11 to 0 step -1
        for $c = 2 to 0 step -1
            for $d = 1 to 0 step -1
                Global $Inventory[$a][$b][$c][$d]
            Next
        Next
    Next
Next

;Sets All The Inventory Slots to null For test preferances
For $iainv = 20 To 0 Step -1

    $Inventory[$iainv][1][0][0] = "Empty" ;Name

    $Inventory[$iainv][2][0][0] = "-"   ;Item type, W = weapon, A = Armour, P = potion, M = Materials, AM = Ammo, S = Scroll
    $Inventory[$iainv][2][1][0] = "-"   ;Specific item type, ////W::  S = Sword, W = Wand, B = Bow, D = Dagger, C = Crossbow, A = Amulet, M = Mace.
                                                        ;////A:: A = Archer, C = Caster, D = Druid, W = Worrior,
                                                        ;////P:: H = HP, M = MP
                                                        ;////M:: A = Aramite(special), B = Bronze, C = Cotton, D = Deadwood, E = Slate, F = Feather, I = Iron, S = Steel
                                                        ;////AM:: B = Bolt, A = Arrow
                                                        ;////S:: F = Fire, S = Shock, I = Ice, E = Earth
    $Inventory[$iainv][2][2][0] = "0"   ;Ammount

    $Inventory[$iainv][3][0][0] = "0"   ;Level

    $Inventory[$iainv][4][0][0] = "0"   ;CurrentDuribility
    $Inventory[$iainv][4][1][0] = "0"   ;MaxDuribility

    $Inventory[$iainv][5][0][0] = "0"   ;MinDamage
    $Inventory[$iainv][5][1][0] = "0"   ;MaxDamage

    $Inventory[$iainv][6][0][0] = "0"       ;Defence

    $Inventory[$iainv][7][0][0] = "-"   ;1st Raw Material
    $Inventory[$iainv][7][1][0] = "-"   ;2nd Raw Material

    $Inventory[$iainv][8][0][0] = "-"       ;Class Specific , N = All , W = Worrior, A = Archer, C = Caster , D = druid

    $Inventory[$iainv][9][0][0] = "-"   ;1st MaterialNeeded
    $Inventory[$iainv][9][0][1] = "0"   ;Amount needed
    $Inventory[$iainv][9][1][0] = "-"   ;2ns MaterialNeeded
    $Inventory[$iainv][9][1][1] = "0"   ;Amount Needed
    $Inventory[$iainv][9][2][0] = "-"   ;3rd MaterialNeeded
    $Inventory[$iainv][9][2][1] = "0"   ;Amount Needed

    $Inventory[$iainv][10][0][0] = "0"  ;BuyCost
    $Inventory[$iainv][10][1][0] = "0"  ;SellCost
    $Inventory[$iainv][10][2][0] = "0"  ;RepairCost

    $Inventory[$iainv][11][0][0] = "0"  ;Hp Bonus
    $Inventory[$iainv][11][1][0] = "0"  ;Mp Bonus
    $Inventory[$iainv][11][2][0] = "0"  ;DefenceBonus

Next

Save()

Func Save()

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Bios", "Name", $charactername)
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Bios", "Level", $characterlevel)
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Bios", "Sex", $charactersex)

for $i = 20 to 0 step -1


IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][1]", $Inventory[$i][1])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][2][0]", $Inventory[$i][2][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][2][1]", $Inventory[$i][2][1])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][2][2]", $Inventory[$i][2][2])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][3]", $Inventory[$i][3])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][4][0]", $Inventory[$i][4][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][4][1]", $Inventory[$i][4][1])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][5][0]", $Inventory[$i][5][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][5][1]", $Inventory[$i][5][1])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][6]", $Inventory[$i][6])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][7][0]", $Inventory[$i][7][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][7][1]", $Inventory[$i][7][1])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][8]", $Inventory[$i][8])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][9][0][0]", $Inventory[$i][9][0][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][9][0][1]", $Inventory[$i][9][0][1])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][9][1][0]", $Inventory[$i][9][1][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][9][1][1]", $Inventory[$i][9][1][1])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][9][2][0]", $Inventory[$i][9][2][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][9][2][1]", $Inventory[$i][9][2][1])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][10][0]", $Inventory[$i][10][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][10][1]", $Inventory[$i][10][1])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][10][2]", $Inventory[$i][10][2])

IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][11][0]", $Inventory[$i][11][0])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][11][1]", $Inventory[$i][11][1])
IniWrite(@ScriptDir & "\Character\" & $charactername & ".ini", "Inv" & $i, "$Inventory[ " & $i & " ][11][2]", $Inventory[$i][11][2])

next
EndFunc

Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Link to comment
Share on other sites

  • Moderators

Thornhunt,

Perhaps if you declared the array correctly?

;WTF!!!!!

;declare the array
for $a = 20 to 0 step -1
    for $b = 11 to 0 step -1
        for $c = 2 to 0 step -1
            for $d = 1 to 0 step -1
                Global $Inventory[$a][$b][$c][$d]
            Next
        Next
    Next
Next

; This is how you do it!
Global $Inventory[21][11][3][2]

You need to put in the MAXIMUM number of elements in each dimension just the once. You need loops to fill and read an array, but not to declare it! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

C:\MyGame\Save.au3 (50) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$Inventory[$iainv][11][0][0] = "0"

^ ERROR

-------------------------

ok .. getting this.. anyidea ? cant see how its exceeding :S

Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Link to comment
Share on other sites

C:\MyGame\Save.au3 (50) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$Inventory[$iainv][11][0][0] = "0"

^ ERROR

-------------------------

ok .. getting this.. anyidea ? cant see how its exceeding :S

Array indexes are 0-based. Second subscript was declared [11], so the possible indexes are 0 thru 10.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

meaning i will have to declare it with

[21][12][3][2]

instead of

[21][11][3][1]

i dont think i follow you fully.

Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Link to comment
Share on other sites

meaning i will have to declare it with

[21][12][3][2]

instead of

[21][11][3][1]

i dont think i follow you fully.

No, he means you count from 0.

There is a Array tutorial on the wiki, maybe you should take a look at it: link

Link to comment
Share on other sites

  • Moderators

Thornhunt;

PsaltyDS and I are (unconsciously) doing a "good cop - bad cop" routime. Up to you to decide who is which! :huggles:

Ok, short array tutorial.

Arrays in AutoIt begin at 0 - so declaring $aArray[3] gives you the following elements:

$aArray[0]

$aArray[1]

$aArray[2]

Note that the highest element is 1 less that the number of elements.

Remember I told you that you needed to declare " the MAXIMUM number of elements in each dimension" - well that means that the top element is $aArray[MAXIMUM - 1].

So if you have 12 items you wish to put in an array you can do one of 2 things:

1. Declare $aArray[12] and then fill elements [0] to [11]

2. Declare $aArray[13], fill elements [1] to [12], and waste element [0]. (Actually Autoit often uses element [0] as a count of the other elements)

Guess which is considered best practice? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

PsaltyDS and I are (unconsciously) doing a "good cop - bad cop" routime. Up to you to decide who is which! :huggles:

Here's a hint: Melba23 is being helpful, while I brought my rubber hose and dental tools.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

PsaltyDS,

Hey, when do I get to have some fun! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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