Bad, bad broken SE

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Bad, bad broken SE

Post by RCozens » Thu Mar 10, 2022 7:25 pm

RCozens wrote:
Wed Mar 09, 2022 8:05 pm
I have changed the name of the string to "boardMix", made it a global instead of a local variable and placed the replace command in a function; but the SE now shows the replace command working as it should.
Craig, Jacque, et al:

What I had not done was pass boardMix as a parameter to the function. Without seeing Craig's code I cannot be sure what I've found is the source of the "error"; but it demonstrates a possible answer: if boardMix is passed by value, its value in the SE will not change until the function ends.

Here's my code:

Code: Select all

global boardMix

function replaceIt theString
   replace space with "." in theString
   return theString
end replaceIt

function replaceIt2 @theString
   replace space with "." in theString
   return theString
end replaceIt2

on mouseUp
   put field 2 into boardMix
   put empty into field "New String"
   put replaceIt(boardMix) into boardMix
   put boardMix into field "New String"
   put field 2 into boardMix
   put empty into field "New String"
   put replaceIt2(boardMix) into boardMix
   put boardMix into field "New String"
end mouseUp
I placed breakpoints at both function calls and stepped into and out of the functions.
The SE shows boardMix changes immediately in replaceIt2, where it is passed by reference; but not until replaceIt (which is passed the string by value) is stepped out of.

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

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

Re: Bad, bad broken SE

Post by dunbarx » Thu Mar 10, 2022 8:29 pm

Hi.

My handler passed by value. You have done far more work on this than I have. Mine fixed itself. Don't know why, I do not ask.

But until it goes south again, I cannot contribute to my own thread. :roll:

Craig

Post Reply

Return to “Talking LiveCode”