"Tracing"

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mcelvain
Posts: 58
Joined: Sat Apr 29, 2023 10:13 pm

"Tracing"

Post by mcelvain » Mon May 29, 2023 10:34 pm

Can anyone recommend a tutorial and/or example scripts for “tracing” variables?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: "Tracing"

Post by FourthWorld » Tue May 30, 2023 12:22 am

The trace stuff is for writing debuggers. It has almost no practical value beyond that.

If you have the ambition to write a debugger, we can point you to example code, which is how the few of us who've written debuggers learned.

If you have any other goal in mind, tell us what it is and we can probably find a simpler way to achieve it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mcelvain
Posts: 58
Joined: Sat Apr 29, 2023 10:13 pm

Re: "Tracing"

Post by mcelvain » Tue May 30, 2023 9:03 pm

Thank-you for responding, "FourthWorld!"

Intend to write a function — “BigVar” — called by an executing line in a script that passes the text of that line — “Liner” — , quoted list of variables which need to be seen in larger text — tVars — , variable containing entire script — myScript, and a title — tTITL —.

The function would put the values of the variables somewhere where I could see them, naming fields somewhere with the number of variables in tVars not to exceed number of flds.

It would populate those fields with corresponding values.

It would write a text file named with tTITL and fields named w values in a form that can be recalled.

It would write tTITL after a menu button to be used to recall.

[the menu button would have to be cleared at some point.

the fields likewise would be cleared at some point ]

It would compare LINER to myScript, returning the matched line as ’n’.

——

This is obviously a newbie workaround only.

ie.,

put BIGvar(tVars,tTITL) into n — to be honest, I’m not sure what to do with n yet.

I do want to use the “Recall” button to replay the advance of values over the course of the script, maybe hiliting lines in a text list field corresponding to LINER so I know where I am in the script.

I’m not shy about receiving constructive criticism for this, but remember that my level and skill sets are pretty low.

and eyes don’t work.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: "Tracing"

Post by dunbarx » Tue May 30, 2023 10:01 pm

Hi.

I am interested in your project after I learned that the "Tracing" part was not really what you meant.
Can you give a fast example of what the input and output of calling your function would look like?

Craig

mcelvain
Posts: 58
Joined: Sat Apr 29, 2023 10:13 pm

Re: "Tracing"

Post by mcelvain » Wed May 31, 2023 7:22 pm

Thanks so much for your time, Craig.

This is the generalized, admittedly inefficient gist of what I’m feeling for here:


Input:

Called in handler in line after variable assignment or variable update.

Output:
Separate stack named “BigVar”

———

Requires sending both name and value of variable.

———-

The called function must:

- call a second function to parce script for handlers ending in “mouseUp” or beginning w “Function”
-
- then match exact text in/provided by current line executing in handler yielding line number
-
- then extract names of assigned variables within
-
- Go to stack “BigVar”, clear fields & rename with first eight variable names (as prioritized upon declaration)
-
- Go back
-
- then read values currently coupled to these names
-
- then go stack “BigVar”

- use tTitl passed to it to know which text file to populate “BigVar” with
-
- do that
-
- try to place variable value into field with its name
-
- Write text file using tTitl & the Time for later recall
-
- add tTitl & the Time to a button menu of some kind for later recall
-
- Go back

------- example ---------

on BigVarPrep
local tIDs,tVars
go stack "/Users/admin/Library/Mobile Documents/com~apple~CloudDocs/BIGvariables.livecode"
dispatch "clearmost" to stack "/Users/admin/Library/Mobile Documents/com~apple~CloudDocs/BIGvariables.livecode"
put "1003,1005,1009,1007,1011,1013,1015,1017,1022,1024,1026,1028" into tIDs
repeat with i = 1 to number of items in tIDs
if i > number of items in tVars then exit repeat
set the name of fld id (item i of tIDs) to item 1 of tVars
end repeat
-- also clear out a menubutton which loads text file outputs of previous variable advances within the script
go back
end BigVarPrep

function BigVar tVarNom,tVarValue,tTITL -- do BigVar("x",xvalue,"XHandler")
local tIDs
put tVarNom & return & "------------" & return & tVarValue into fld tVarNom of stack "/Users/admin/Library/Mobile Documents/com~apple~CloudDocs/BIGvariables.livecode"
-- add menubutton previously cleared in "BigVarPrep"
-- add a writeFile here using tTITL, fld names in stack "BIGvariables" along with corresponding values, and properties or something of menu botton
--
end BigVar

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: "Tracing"

Post by mwieder » Thu Jun 01, 2023 5:34 pm

I'm only getting a vague understanding of what you have in mind, but I think maybe you want to have a historical record of the changes to variables as your code progresses. I do have something like that as an option in PowerDebug, but I rarely invoke it because it causes quite a strain on the system and as a result slows things down significantly.

If that is indeed what you have in mind then there are probably better ways to get to your end goal: for instance, you can set a watched variable that will trigger a breakpoint when a variable reaches a given value. But if you really want to get your hands dirty and create a historical record (hopefully I'm misunderstanding what you're doing) then I'd say that

A: you're about to embark on a long journey into undocumented and poorly documented regions of how the engine works. You're going to be setting a breakpoint on each line of code as you go, parsing the statement for variable assignment, storing and repeating
B: you have no place being in a beginner's forum - this is seriously wonky code.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: "Tracing"

Post by dunbarx » Thu Jun 01, 2023 6:57 pm

@Mark.

Is there anything remotely like the "setProp" control structure that deals with variables as opposed to custom properties? Why do I doubt there is?

Your second list of requirements seems more "doable" than the first. Is that an evolved version?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: "Tracing"

Post by dunbarx » Thu Jun 01, 2023 6:59 pm

mcelvain

Was I correct in saying that you want to "trigger" this activity whenever a variable is either created or updated?

If so, oh boy.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: "Tracing"

Post by dunbarx » Thu Jun 01, 2023 7:09 pm

This is a real rabbit hole, but it may be possible to use the "variableNames" property. You would create a dataSet of all variables and their values. Then check that list of values each and every line of code to see if there have been any changes. If there have, call your function gadget.

Each and every line.

To me that is the killer part. The processing of the data in that list is much more straightforward.

Craig

mcelvain
Posts: 58
Joined: Sat Apr 29, 2023 10:13 pm

Re: "Tracing"

Post by mcelvain » Thu Jun 01, 2023 10:01 pm

Thank-you for responding, Craig.

I’m definitely a beginner with SuperCard experience with bad eyesight who depends upon variable watching in order to learn LC.

My rush is to write a script to translate, in bulk, all my SC scripts to LC, so I can update X-Code so I can write iPhone standalones to help blind old cusses like me.

So, the BigVar pallet should help me do that, if it doesn’t fry my system bus first.

—-

Is there any way to get under the hood of LC’s variable-watcher?

I’d need to be able to continuously scan the running handler as the debugger does for unclosed loops and such.

I assume it parces the handler in order to debug.

It probably keeps an updating map of the parced result, including variables and their values.

As you observe, my script requires calling functions throughout the run.

SuperCard had the “idle” function which could compare global variables to themselves over time; changes could be acted upon.

Have not found such in LC.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: "Tracing"

Post by jacque » Fri Jun 02, 2023 5:41 pm

LC also has an idle message. You can also set the idle rate to an interval of your choice. It's rarely used because there are better ways to implement repeating events but it's there if you want it.

I do think your original request to enlarge the variable watcher is a better idea than going down a complex rabbit hole. As I understand it,, the variable watcher is a datagrid. There's probably a way to edit the template to adjust the text size, but I haven't looked into it. Maybe someone here knows where the template lives.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mcelvain
Posts: 58
Joined: Sat Apr 29, 2023 10:13 pm

Re: "Tracing"

Post by mcelvain » Fri Jun 02, 2023 9:54 pm

Thank-you for responding, Jacque.

Although I’ve now written the work-around, the only usefulness might be in the learning.

The feedback I’ve gotten from others at your level has directed me to specific tutorials which detail the train of logic from which their replies draw.

I can’t express how grateful I am for all your replies.

For example, the Message Box error has not recurred since I trimmed down my bg script.

When I develop a recipe for recreating the “something” dialog, I’ll share and reinstall LC.

I’ve learned from you all that using modal dialogs with sheets [as yet untried] will probably emulate SC’s “ask list” dialog.

What is fascinating also to learn are the stories you share of your own code development history.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: "Tracing"

Post by mwieder » Fri Jun 02, 2023 11:46 pm

which detail the train of logic
chortle
I misread that as "derail..."

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”