[1.3b55] Parameter for defineFunction() to Ignore Output

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

[1.3b55] Parameter for defineFunction() to Ignore Output

Post by zEal »

I'd like to request a third optional parameter for defineFunction() in the form of a boolean that tells the defined function to act as if there was no output and return the value of macro.return.

To maintain compatibility with existing functions, this parameter should default to false.

If that's possible. :)

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by Craig »

zEal wrote:I'd like to request a third optional parameter for defineFunction() in the form of a boolean that tells the defined function to act as if there was no output and return the value of macro.return.

To maintain compatibility with existing functions, this parameter should default to false.

If that's possible. :)
Can you do me a favor?
I have created a patch http://lmwcs.com/maptool/CustomBuilds/P ... efFunc.txt that adds this functionality but I am away from my machine that has all my maptool campaigns and wont have access to it this weekend.
As this change also effects macro link and [macro():] execution (although I really don't expect it to have major effects) I was wondering if you have the source in eclipse if you could apply the patch and give it a bit of a work out with what ever macros you are currently using.

The changes are
defineFunction(function, macroName [, ignoreOutput [,newScope]])

Where
ignoreOutput - defaults to 0, if 1 output will be ignored and macro.return is returned from the function.

newScope - defaults to 1, if 0 the function is executed with the current variable scope so it can read,update,create variables from the calling scope.

If neither ignoreOutput or newScope is defined then it should have exact same behavior. newScope is a bit icky programing wise but it allows for functions that are like varsFromStrProp()/varsToStrProp() to be created.

If you are not able to get a chance to give it a go let me know.

Thanks
Last edited by Craig on Fri Apr 17, 2009 12:39 pm, edited 1 time in total.

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by zEal »

Will do, I'll get back to you after I've put it through the works some.
Craig wrote:newScope - defaults to 1, if 0 the function is executed with the current variable scope so it can read,update,create variables from the calling scope.
This is the greatest! Oh man, so many possibilities.

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by zEal »

Craig wrote:newScope is a bit icky programing wise but it allows for functions that are like varsFromStrProp()/varsToStrProp() to be created.
If you mean the functionality, it's only one-third icky :P read/update seems natural, but being able to create variables in a parent's scope does seem a bit odd; in this particular instance I like it though.

All of my existing macros seem to work exactly as they did before; I also created some macros to test the new functionality and it seems to work exactly as intended from all of my testing so far.

Some things I discovered:

You can redefine defineFunction() :lol: (yeah I know it should work that way, I just never thought of doing it before now)

ignoreOutput works so well that if you don't set a value to macro.return you don't even have to worry about h:iding the call. (e.g. a custom varsFromStrProp could be called with [myVarsToStrProp()] and create all the variables without returning any output at all, nothing.) I like it.

User avatar
Mrugnak
Dragon
Posts: 745
Joined: Mon Jul 21, 2008 7:38 pm

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by Mrugnak »

Hm. This looks like it might have really interesting potential for my GURPS dieroller, for fixing the tooltip issue (the tooltip recursion nightmare that I was fighting with earlier). I'll have to think about how best to implement it, though.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by Rumble »

zEal wrote:
You can redefine defineFunction() :lol: (yeah I know it should work that way, I just never thought of doing it before now)

Here's the trick: can you redefine oldFunction()?

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by zEal »

Rumble wrote:
zEal wrote:
You can redefine defineFunction() :lol: (yeah I know it should work that way, I just never thought of doing it before now)

Here's the trick: can you redefine oldFunction()?
I just tested this, and you can redefine oldFunction(). I'm not sure what you'd ever want to do that for, or how you'd get it to work well, but you never know... maybe someone will think of some wildly fantastic reason to redefine oldFunction() /shrug

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by zEal »

Everything is still working great, including macroLink and [macro():], so I've been trying to break it.

I was curious about how far this newScope=0 would go, so I made a couple test macros to see.
onCampaignload

Code: Select all

[defineFunction("scopeTest", "scopeTest@this", 1, 0)]
scopeTest

Code: Select all

[if(loopVar != 5), code:
{
    [loopVar = loopVar+1]
    [set("Scope"+loopVar, "fromChild"+loopVar)]
    [scopeTest()]
}]
Test

Code: Select all

[h: loopVar = 0]
[scopeTest()]
[Scope1]<br>[Scope2]<br>[Scope3]<br>[Scope4]<br>[Scope5]<br>
..as expected it returned:
fromChild1
fromChild2
fromChild3
fromChild4
fromChild5


Of course now I wanted to know just how far it would go... 20 worked, must try more... 50 worked. At that point I realised my test sucked, so I rewrote scopeTest()

Code: Select all

[if(loopVar != 60), code:
{
    [loopVar = loopVar+1]
    [testVar = json.append(testVar, loopVar)]
    [scopeTest()]
}]
and Test

Code: Select all

[h: loopVar = 0]
[h: testVar = '[0]']
[scopeTest()]
[r: testVar]
60 worked.. 70 worked.. 80.. StackOverflowError >.< I imagine launching from Eclipse gives me the default stack-size(2MB I think), and it's not like I think anyone should be doing that, but there you have it. :)

User avatar
trevor
Codeum Arcanum (RPTools Founder)
Posts: 11311
Joined: Mon Jan 09, 2006 4:16 pm
Location: Austin, Tx
Contact:

Re: [1.3b55] Parameter for defineFunction() to Ignore Output

Post by trevor »

Patch from Craig applied for 1.3b56
Dreaming of a 1.3 release

Post Reply

Return to “Resolved”