Calling code:
Code: Select all
#
# Adds the specified text and a return to the log field.
#
command log msg
local lineCount
local lineHeight
local timestamp
local newLine = "<br>"
if the hilited of button "enabledBtn" of card "log" of me is not true then exit log
if msg is an array then
put formatArray( msg ) into msg -- Format the array and replace the contents of msg with the result.
end if
-- At this point msg should always be a string
-- However, if formatArray() was called it's still an array :-/
if the hilited of button "timestampsBtn" of card "log" of me is true and msg is not empty then
put "[" & the long time & "] " into timestamp
put " " after newLine
end if
lock screen
get the htmlText of field "output" of me
put ( "<p>" & timestamp & replaceText( msg, cr, newLine ) & "</p>" ) after it
set the htmlText of field "output" of me to it
put the effective textHeight of field "output" of card "log" of me into lineHeight
put the number of lines in field "output" of card "log" of me into lineCount
Set The VScroll Of field "output" of card "log" of me to lineHeight * lineCount
unlock screen
end log
Code: Select all
#
# Formats an array for logging.
# Based on http://lessons.livecode.com/s/lessons/m/4071/l/21022-how-do-i-display-an-array-in-human-readable-form
#
function formatArray theArray, indent
local idx -- The array key
local ret
#
# If the supplied value is not an aray then just return it as is.
#
if theArray is not an array then return theArray
return "it's an array"
get "array" & cr -- into "it"
put " " after indent
repeat for each key idx in theArray
put ( format( "%s[%s] => %s", indent, idx, formatArray ( theArray[idx], indent )) & cr ) after it
end repeat
delete the last character of it
put it into ret
return ret
end formatArray
At that point, ret contains a nicely formatted string.
When I step back to the calling handler, msg still contains the original array.
Strangely, the formatted output is displayed in the message box.
One other thing, I am calling log from the message box.
I must be missing something basic here.
Thanks in advance.
Dave