Displaying array elements

Ask gaming related questions (AHK v1.1 and older)
larabee
Posts: 8
Joined: 06 Aug 2018, 16:06

Displaying array elements

09 Aug 2018, 14:14

Hi, I could do with some help.

I have a snippet of code, where I am at a point where my pointer shows that i wanna inform the user that we are working with the variable NrOfFound pointing to the first occurance of the array (ie. NrOfFound = 1). Does not matter, it could as well be 2 or 3... but it was 1 when i noticed. The line FoundArray[NrOfFound] was suddenly not usable. The code follows:

Code: Select all

FoundSomething:
	FoundArray[1] := "Resists"			; added while debugging
	MsgBox FoundLine = %FoundLine% 	
	FoundLine := FoundArray[NrOfFound]	; this was meant to be OK from start
	MsgBox FoundLine = %FoundLine%		; added as debuginfo
	FoundLine := FoundArray[1]			; Added
	MsgBox FoundLine = %FoundLine%		; still not working
	FoundLine := "Resists"				; THIS works ofc, but is unusable
	MsgBox FoundLine = %FoundLine%
	ListVars
	MsgBox F o u n d  - FoundPos = %FoundAnt% Pos = %Pos% TextLine = %TextLine% NrOfFound = %NrOfFound% FoundLine = %FoundLine%
	return
FoundArray := ["Resists", "NoMore", "Died"]


So sorry, the snippet was originally meant to contain only like two the lines: FoundLine = FoundArray[NrOfFound] and then MsgBox FoundLine = %FoundLine% but has swelled because of alll the extra info when debugging.

The program has reached a point where it has found the occurance when the variable NrOfFound = 1. Now the code should assign he value of FoundArray[1] (which I think should be the word "Resists") to the variable FoundLine. However no code - except the unusable FoundLine := "Resists" does that. Any help would be highly appreciated. Anybody, please? How can I display the value of FoundArray[NrOfFound] (= Resists) ?? :thumbdown:
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Displaying array elements

09 Aug 2018, 14:59

FoundLine := FoundArray[NrOfFound] already does just that:

Code: Select all

Array := ["Resists", "NoMore", "Died"]
Nr := 1
Line := Array[Nr]
MsgBox % Line
larabee
Posts: 8
Joined: 06 Aug 2018, 16:06

Re: Displaying array elements

09 Aug 2018, 16:33

Yes indeed, very smart. The declaration of an array must ofc come before it is used. I thought i had gotten the syntax with arrays all wrong. Anyways, thanks a lot for your help.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 43 guests