Changing the content of a passed parameter

13 views
Skip to first unread message

andre.tremblay

unread,
May 28, 2021, 11:34:57 AM5/28/21
to SuperCard Discussion
Hello, 

Being myself also in the process of rewriting and cleaning up old codes, I wonder about this possible issue; is it safe to modify a passed parameter inside a script or is it better to declare it as a variable first? 

An example: 

function ReplaceComma2Char226

  return replace(param(1),COMMA,numToChar(226))

end ReplaceComma2Char226

-- Or --

function ReplaceComma2Char226

  local SomeText=param(1)

  return replace(SomeText,COMMA,numToChar(226))

end ReplaceComma2Char226

---- 

Is the first example a possible source for error or these two examples are just practically the same?

----------

Sorry! I haven't find the way to have coloured scripts when starting a new post from the Google web page! 

Regards

André




MARK LUCAS

unread,
May 28, 2021, 6:02:02 PM5/28/21
to superca...@googlegroups.com
If they weren't passed by reference, parameters are functionally equivalent to local variables you create yourself (so you don't need to copy them to another local before modifying them).

Just keep in mind that if a param *does* contain a variable passed by reference, any changes you make to it will affect that variable's value in the calling script too.

HTH,
-Mark
Reply all
Reply to author
Forward
0 new messages