Digit's Values not getting extracted from Dictionary?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bluscream
Posts: 16
Joined: 10 Jan 2017, 23:12
Contact:

Digit's Values not getting extracted from Dictionary?

Post by Bluscream » 02 Feb 2019, 18:28

I have a dictionary that contains Letters and Digits and i can get the values of the letter keys just fine but not the ones from digits even though they're enclosed in " . It isn't important for the question but just in case you're wondering what the bluscream.ahk file that's included looks like: https://github.com/Bluscream/ahk-scripts/blob/master/Lib/bluscream.ahk

I tried what can be seen in the code. I have no idea what to do

Code: Select all

; Version 1
; Date 02/02/2019
#Include <bluscream>
#SingleInstance Force
Process Priority,, Below Normal
SetWorkingDir %A_ScriptDir%
#Warn
#Persistent
SetKeyDelay, 150
game_name := "LEGO" ; LEGO Jurassic World
game_title := "ahk_class TTalesWindow" ; ahk_exe LEGOJurassicWorld_DX11.EXE

chars := { "B" : "{Up}", "C" : "{Up 2}", "D" : "{Up 3}", "E" : "{Up 4}", "F" : "{Up 5}", "G" : "{Up 6}", "H" : "{Up 7}", "J" : "{Up 8}", "K" : "{Up 9}", "L" : "{Up 10}", "M" : "{Up 11}", "N" : "{Up 12}", "O" : "{Up 13}", "P" : "{Up 14}", "Q" : "{Up 15}", "R" : "{Up 16}", "S" : "{Down 18}", "T" : "{Down 17}", "U" : "{Down 16}", "V" : "{Down 15}", "W" : "{Down 14}", "X" : "{Down 13}", "Y" : "{Down 12}", "Z" : "{Down 11}", "0" : "{Down 10}", "1" : "{Down 9}", "2" : "{Down 8}", "3" : "{Down 7}", "4" : "{Down 6}", "5" : "{Down 5}", "6" : "{Down 4}", "7" : "{Down 3}", "8" : "{Down 2}", "9" : "{Down}" }

file := "codes.txt"

global noui := false
scriptlog("Started logging here...")

FileRead, LoadedText, %file%
codes := StrSplit(LoadedText, "`n", "`r")


Loop, % codes.MaxIndex()
{
    if !(WinActive(game_title)) {
        TrayTip, AutoHotKey, Bringing %game_name% to front to enter code...
        Sleep, 1000
        WinWaitActive, %game_title%
    }
    
    code := StrStrip(codes[A_Index])
    length := StrLen(code)
    FormatTime, timestamp, A_Now, hh:mm:ss
    scriptlog("[" . timestamp . "] Now processing code: " . code . " [" . length . "] (`r`n", "", true)
    splitted_code := StrSplit(code)
    for i, char in splitted_code {
        tosend := chars[char]
        scriptlog("i:" . i . " char:" . char . " tosend:" . tosend . "`r`n", "", true)
        if (tosend){
            SendEvent, % tosend
        }
        if (i < length)
            SendInput, {Right}
    }
    scriptlog(")`r`n","",true)
    SendInput, {Enter}
}
Expected results:

Code: Select all

[11:17:43] Started logging here...
[11:17:46] Now processing code: 28SPSR [6] (
i:1 char:2 tosend:{Down 8}
i:2 char:8 tosend:{Down 2}
i:3 char:S tosend:{Down 18}
i:4 char:P tosend:{Up 14}
i:5 char:S tosend:{Down 18}
i:6 char:R tosend:{Up 16}
)
Actual Results:

Code: Select all

[11:17:43] Started logging here...
[11:17:46] Now processing code: 28SPSR [6] (
i:1 char:2 tosend:
i:2 char:8 tosend:
i:3 char:S tosend:{Down 18}
i:4 char:P tosend:{Up 14}
i:5 char:S tosend:{Down 18}
i:6 char:R tosend:{Up 16}
)
gregster
Posts: 9095
Joined: 30 Sep 2013, 06:48

Re: Digit's Values not getting extracted from Dictionary?

Post by gregster » 02 Feb 2019, 18:49

Sorry, I haven't really looked closely at your code but this caught my eye:
i can get the values of the letter keys just fine but not the ones from digits even though they're enclosed in "
This might very well be the problem, because in AHK v1.x, an integer key is not the same as the same integer in quotation marks - which would be considered non-numeric:
https://autohotkey.com/docs/Objects.htm#Keys wrote:Quoted literal strings are considered purely non-numeric in v1.x, so x[1] and x["1"] are not equivalent. Additionally, if a quoted literal string is concatenated with another value (as in "0x" x), the result is treated as purely non-numeric. However, this does not apply to variables, so x[1] and x[y:="1"] are equivalent. This issue will be resolved in AutoHotkey v2, so scripts should avoid using quoted numeric literals as keys.
So, I would remove the quotes and try again...

Code: Select all

obj := { 1: "hello", "1" : "world"}
msgbox % obj[1] " - " obj["1"]
Post Reply

Return to “Ask for Help (v1)”