AmongKeysOfArray issues

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

AmongKeysOfArray issues

Post by pink » Mon Aug 13, 2018 8:10 pm

I have a property that is an array. In my setter handler, I am trying to fill in keys that might not be available.

Here is my code:

Code: Select all

private handler setData(in pData as Array)
	variable tCount as Number
	variable tKey as String

	put the number of elements in pData into mCount
	repeat with tCount from 1 up to mCount
		put tCount formatted as string into tKey
		if "value" is not among the keys of pData[tKey] then   ---THIS IS LINE 400
			put tKey into pData[tKey]["value"]
		end if
	end repeat
	put pData into mData
	redraw all
end handler
I created this button to test it, in this case "value" does not exist in tButton[3] so it want it filled in with pKey
on mouseUp
put "abc" into tButton[1]["value"]
put empty into tButton[2]["value"]
put empty into tButton[3]
set the buttonData of widget "MP Button Bar" to tButton
end mouseUp

but I keep getting this error:
button "Button": execution error at line 5 (LCB Error in file ButtonBar.lcb at line 400: No matching handler for arguments with types (<type: livecode.lang.string>,<type: livecode.lang.boolean>,<type: livecode.lang.string>,<type: livecode.lang.string>) - possible handlers (MCArrayEvalIsAmongTheKeysOfCaseless))
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1207
Joined: Thu Apr 11, 2013 11:27 am

Re: AmongKeysOfArray issues

Post by LCMark » Mon Aug 13, 2018 8:27 pm

@pink: The problem here is that pData[tKey] is not necessarily an array. Try:

Code: Select all

private handler setData(in pData as Array)
	variable tCount as Number
	variable tKey as String

	put the number of elements in pData into mCount
	repeat with tCount from 1 up to mCount
		put tCount formatted as string into tKey
		if not (pData[tKey] is an array) then
			put the empty array into pData[tKey]
		end if
		if "value" is not among the keys of pData[tKey] then   ---THIS IS LINE 400
			put tKey into pData[tKey]["value"]
		end if
	end repeat
	put pData into mData
	redraw all
end handler

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: AmongKeysOfArray issues

Post by pink » Mon Aug 13, 2018 8:31 pm

ah!!! that makes sense, thank you!!!!
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: AmongKeysOfArray issues

Post by pink » Mon Aug 13, 2018 8:33 pm

Should've also mentioned, works now.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Post Reply

Return to “LiveCode Builder”