Re: A Function question... about remembering
This WebDNA talk-list message is from 2004
It keeps the original formatting.
numero = 55697
interpreted = N
texte = Scope, scope, scope....A WebDNA function executes in its own variable space (scope). This is a bigadvantage if you wish to create functions that anyone can use, as you do notneed to worry about cluttering up the 'global' scope with variables youcreate in your function, and you do not need to worry about variable namecollisions.You can create a 'global' variable from within your function, by setting the[text] 'scope' parameter to 'global'. Like this:[!] ### A FUNCTION ### [/!][function name=webdna_test][text scope=global]test_result=[math][testvariable]+100[/math][/text][/function]....[webdna_test testvariable=100]result = [test_result]You do not really need the [return] context in this case. However, you canuse the [return] context and then do this:[function name=webdna_test][return][math][params_string]+100[/math][/return][/function]....[text]test_result=[webdna_test 100][/text]result = [test_result]Notice how I just wrapped the function call with a text assignment? Sothere is no need to create a text variable from within the function code.Also notice the use of the [params_string] tag? Since your function onlyrequires one input, you can use the [params_string] tag from within thefunction to retrieve the parameter string that was passed into the function.This simplifies the calling of the function in that you do not need to'name' the input, i.e. [webdna_test 100] instead of [webdna_testtestvariable=100].Please view the WebDNA Lab tutorials for detailed explanations of Functionsand Scope.Hope this helps.-----Original Message-----From: Palle Bo Nielsen [mailto:powerpalle@powerpalle.dk]Sent: Sunday, January 25, 2004 6:04 AMTo: WebDNA-Talk@talk.smithmicro.comSubject: A Function question... about remembering[!] ### A FUNCTION ### [/!][function name=webdna_test][return][!] stupid and simple calculation ... [/!][text show=f]test_result=[math][testvariable]+100[/math][/text][/return][/function][!] ### THE TEMPLATE CODE ### [/!][webdna_test testvariable=100][text]test_result[/text]When I execute this code the result from the [Function] is 200 as itshould be. But let's say the Functions was somewhat more complicatedand the result was supposed to be use several time later in thetemplate. In that case I would have stored the value of <200> in a[text]test_result[/text] within the function and just presented the[text]-variable later on in the template when needed.But it seems that the content within a [text]test_result[/text], whenset within the Function-area and presented outside is not rememberedlater in the template - why is that?-------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list
.To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail toWeb Archive of this list is at: http://webdna.smithmicro.com/-------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list .To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/
Associated Messages, from the most recent to the oldest:
Scope, scope, scope....A WebDNA function executes in its own variable space (scope). This is a bigadvantage if you wish to create functions that anyone can use, as you do notneed to worry about cluttering up the 'global' scope with variables youcreate in your function, and you do not need to worry about variable namecollisions.You can create a 'global' variable from within your function, by setting the[text] 'scope' parameter to 'global'. Like this:[!] ### A FUNCTION ### [/!][function name=webdna_test][text scope=global]test_result=[math][testvariable]+100[/math][/text][/function]....[webdna_test testvariable=100]result = [test_result]You do not really need the [return] context in this case. However, you canuse the [return] context and then do this:[function name=webdna_test][return][math][params_string]+100[/math][/return][/function]....[text]test_result=[webdna_test 100][/text]result = [test_result]Notice how I just wrapped the function call with a text assignment? Sothere is no need to create a text variable from within the function code.Also notice the use of the [params_string] tag? Since your function onlyrequires one input, you can use the [params_string] tag from within thefunction to retrieve the parameter string that was passed into the function.This simplifies the calling of the function in that you do not need to'name' the input, i.e. [webdna_test 100] instead of [webdna_testtestvariable=100].Please view the WebDNA Lab tutorials for detailed explanations of Functionsand Scope.Hope this helps.-----Original Message-----From: Palle Bo Nielsen [mailto:powerpalle@powerpalle.dk]Sent: Sunday, January 25, 2004 6:04 AMTo: WebDNA-Talk@talk.smithmicro.comSubject: A Function question... about remembering[!] ### A FUNCTION ### [/!][function name=webdna_test][return][!] stupid and simple calculation ... [/!][text show=f]test_result=[math][testvariable]+100[/math][/text][/return][/function][!] ### THE TEMPLATE CODE ### [/!][webdna_test testvariable=100][text]test_result[/text]When I execute this code the result from the [function] is 200 as itshould be. But let's say the Functions was somewhat more complicatedand the result was supposed to be use several time later in thetemplate. In that case I would have stored the value of <200> in a[text]test_result[/text] within the function and just presented the[text]-variable later on in the template when needed.But it seems that the content within a [text]test_result[/text], whenset within the Function-area and presented outside is not rememberedlater in the template - why is that?-------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list .To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail toWeb Archive of this list is at: http://webdna.smithmicro.com/-------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list .To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/
"Scott Anderson"
DOWNLOAD WEBDNA NOW!
Top Articles:
Talk List
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...
Related Readings:
Generating Report Totals (1997)
Sun doesn't have an emailer app? (2000)
Summing Fields (1998)
Resume Catalog ? (1997)
SKU lookup (1997)
Help! WebCat2 bug (1997)
Size issues (2001)
UPS Shipping Docs (Where To Go) (1999)
Form based Redirect (2001)
generator prob (2001)
jpg and gif format thumbnails (2004)
Checking for blank form fields (sort of...) (1998)
apostrophe in search item (1997)
Passing Variable (was How to add product size) (1997)
[WebDNA] OT: undeliverable messages? (2009)
Banners and sort of random display (1997)
Conference? Heres my sniplete contribution! (1998)
Loop into field (1998)
SKU Question (1999)
webdna&domain name again (2003)