Associative array not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
double_jumper
Posts: 5
Joined: 12 Jul 2015, 17:17

Associative array not working

12 Jul 2015, 17:28

I'm making this code to convert text into the monospaced unicode version, but for some reason "Monospace[A_LoopField]" returns an empty string. (don't worry about my sanity, I used a macro to make the array)

Code: Select all

Monospace := {"!": "!", """": """, "#": "#", "$": "$", "%": "%", "&": "&", "'": "'", "(": "(", ")": ")", "*": "*", "+": "+", ",": ",", "-": "-", ".": ".", "/": "/", "0": "0", "1": "1", "2": "2", "3": "3", "4": "4", "5": "5", "6": "6", "7": "7", "8": "8", "9": "9", ":": ":", ";": ";", "<": "<", "=": "=", ">": ">", "?": "?", "@": "@", "A": "A", "B": "B", "C": "C", "D": "D", "E": "E", "F": "F", "G": "G", "H": "H", "I": "I", "J": "J", "K": "K", "L": "L", "M": "M", "N": "N", "O": "O", "P": "P", "Q": "Q", "R": "R", "S": "S", "T": "T", "U": "U", "V": "V", "W": "W", "X": "X", "Y": "Y", "Z": "Z", "[": "[", "\": "\", "]": "]", "^": "^", "_": "_", "a": "a", "b": "b", "c": "c", "d": "d", "e": "e", "f": "f", "g": "g", "h": "h", "i": "i", "j": "j", "k": "k", "l": "l", "m": "m", "n": "n", "o": "o", "p": "p", "q": "q", "r": "r", "s": "s", "t": "t", "u": "u", "v": "v", "w": "w", "x": "x", "y": "y", "z": "z", "{": "{", "|": "|", "}": "}"}
Convert(input){
	Loop, parse, input
	{
		output := output . Monospace[A_LoopField]
	}
	return output
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Associative array not working

12 Jul 2015, 17:40

Monospace needs to be global, either use global Monospace := or declare global Monospace in Convert function
double_jumper
Posts: 5
Joined: 12 Jul 2015, 17:17

Re: Associative array not working

12 Jul 2015, 17:49

Thanks, it worked! I just assumed it was global by default since all variables are.
gilliduck
Posts: 265
Joined: 06 Oct 2014, 15:01

Re: Associative array not working

12 Jul 2015, 19:12

unless a variable is passed to a function, the function has no idea it exists (unless you declair global like HotKeyIt said)
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: Associative array not working

12 Jul 2015, 21:29

double_jumper wrote:I just assumed it was global by default since all variables are.
Functions are local by default.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Decar, doodles333, mikeyww and 233 guests