Jump to content
Sign in to follow this  
OnTheFly

Strange array problem

Recommended Posts

OnTheFly

Hi, i've got a strange problem. (Or i done something dumb)

I got this code:

Dim $clicklist[12]
$clicklist["R"] = 8
$clicklist["_R"] = 16
$clicklist["R_"] = 24
$clicklist["L"] = 1
$clicklist["_L"] = 2
$clicklist["L_"] = 3
$clicklist["RL"] = 9
$clicklist["_RL"] = 18
$clicklist["DL"] = 4
$clicklist["DR"] = 32
$clicklist["DRL"] = 36
$clicklist["ALL"] = 64
;Check if it has a valid value
$click = IniRead("VelkyPortable/data/settings.ini", "controls", "click", "")
If $click = "" And Not $click = "R" And Not $click = "_R" And Not $click = "R_" And Not $click = "L" And Not $click = "L_" And Not $click = "L_" And Not $click = "RL" And Not $click = "_RL" And Not $click = "DL" And Not $click = "DR" And Not $click = "DRL" And Not $click = "ALL" Then
    MsgBox(48, "Warning!", "The key 'click' in settings.ini does not have a valid value. Using default 'ALL'")
    $click = $clicklist["ALL"]
Else
    $click = $clicklist[$click]
EndIf

MsgBox(0,"",$clicklist["_R"])

But the messagebox shows 64, when it should show 16. I f i comment the '$clicklist["ALL"] = 64' line, the MsgBox shows 36. So it seems to show the latest entry in the array. Why is this happening?

Share this post


Link to post
Share on other sites
PsaltyDS

Hi, i've got a strange problem. (Or i done something dumb)

I got this code:

Dim $clicklist[12]
$clicklist["R"] = 8
$clicklist["_R"] = 16
$clicklist["R_"] = 24
$clicklist["L"] = 1
$clicklist["_L"] = 2
$clicklist["L_"] = 3
$clicklist["RL"] = 9
$clicklist["_RL"] = 18
$clicklist["DL"] = 4
$clicklist["DR"] = 32
$clicklist["DRL"] = 36
$clicklist["ALL"] = 64
;Check if it has a valid value
$click = IniRead("VelkyPortable/data/settings.ini", "controls", "click", "")
If $click = "" And Not $click = "R" And Not $click = "_R" And Not $click = "R_" And Not $click = "L" And Not $click = "L_" And Not $click = "L_" And Not $click = "RL" And Not $click = "_RL" And Not $click = "DL" And Not $click = "DR" And Not $click = "DRL" And Not $click = "ALL" Then
    MsgBox(48, "Warning!", "The key 'click' in settings.ini does not have a valid value. Using default 'ALL'")
    $click = $clicklist["ALL"]
Else
    $click = $clicklist[$click]
EndIf

MsgBox(0,"",$clicklist["_R"])

But the messagebox shows 64, when it should show 16. I f i comment the '$clicklist["ALL"] = 64' line, the MsgBox shows 36. So it seems to show the latest entry in the array. Why is this happening?

You must be expecting AutoIt array syntax to match some other language you are familiar with, because AutoIt array indexes are only integers. A string reference will be auto-converted to 0, so every reference you made, including in the MsgBox(), was to $clicklist[0]. If you must make string associations like that in AutoIt, search this forum for "scripting.dictionary".

:)


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

Share this post


Link to post
Share on other sites
rudi

Hi, i've got a strange problem. (Or i done something dumb)

[array actions I'v not seen before... but I don't "array" too much ;) ]

use

#include <array.au3>

_ArrayDisplay($YourArray,"Title")

to check out your results.

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.