Comparison of multi-dimensional array values failing

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Entropy42
Posts: 29
Joined: 11 Dec 2016, 12:34

Comparison of multi-dimensional array values failing

10 Nov 2017, 23:24

I have some code that iterates through two multi-dimensional array objects and tries to find out when the first field (the name) matches. It doesn't work. The first item of each array is the same, and I've checked it with the debugger. If I put a breakdpoint at the IF statement and check the values of card[1] and CardList[1,1] (or CardList[1][1], I've tried both notations), they both say the exact same text: "Adept", but it never enters the IF statement.

Code: Select all

ImportTSV("AHData.txt", AHData)	; this just imports a tab delimited text file and builds the array.  AHData is a 100x4 array and CardList is a 200x5 array
ImportTSV("Cards.txt", CardList)
Loop % Cardlist.MaxIndex() { 		; tried using "for i, item in CardList" but it would not write new fields to "item"
	i = A_Index
	for k, card in AHData {
		if (card[1] = CardList[i][1]) {
			if secondPrice
				CardList[i,6] = card[2]
           }
    }
}
As a secondary question, I originally had two for loops "for i, item in CardList" and "for k, card in AHData", and the comparison seemed to work, but the last line of the code would never do anything. It would get there, but it couldn't expand the array to add the 6th field?
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Comparison of multi-dimensional array values failing

11 Nov 2017, 05:37

Can You provide sample data? Would be easier to look into it.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Comparison of multi-dimensional array values failing

11 Nov 2017, 06:35

Code: Select all

if secondPrice
	CardList[i,6] = card[2]
Is secondPrice defined and not false? Also note, you must use the correct assignment operator, that is, :=.
Also make sure that there are no invisble characters in the data, such as leading or trailing spaces or tabs. Eg,

Code: Select all

data := "	hi"
msgbox % "->" data "<-"
msgbox % "->" trim(data) "<-"
Good luck. Cheers

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: macromint, peter_ahk, Spawnova, wineguy and 279 guests