[1.3b55] Parameter for defineFunction() to Ignore Output
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
[1.3b55] Parameter for defineFunction() to Ignore Output
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.
To maintain compatibility with existing functions, this parameter should default to false.
If that's possible.
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
Can you do me a favor?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.
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.
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
Will do, I'll get back to you after I've put it through the works some.
This is the greatest! Oh man, so many possibilities.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.
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
If you mean the functionality, it's only one-third icky 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.Craig wrote:newScope is a bit icky programing wise but it allows for functions that are like varsFromStrProp()/varsToStrProp() to be created.
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() (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.
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
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.
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
zEal wrote:
You can redefine defineFunction() (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()?
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
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() /shrugRumble wrote:zEal wrote:
You can redefine defineFunction() (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()?
Re: [1.3b55] Parameter for defineFunction() to Ignore Output
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.
onCampaignloadscopeTestTest
..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()and Test60 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.
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)]
Code: Select all
[if(loopVar != 5), code:
{
[loopVar = loopVar+1]
[set("Scope"+loopVar, "fromChild"+loopVar)]
[scopeTest()]
}]
Code: Select all
[h: loopVar = 0]
[scopeTest()]
[Scope1]<br>[Scope2]<br>[Scope3]<br>[Scope4]<br>[Scope5]<br>
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()]
}]
Code: Select all
[h: loopVar = 0]
[h: testVar = '[0]']
[scopeTest()]
[r: testVar]
- 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
Patch from Craig applied for 1.3b56
Dreaming of a 1.3 release