Scripting: User-Defined Functions
Re: Scripting: User-Defined Functions
...talking about include...
It would be fine to expand the sysntax!
I was glad that I can include a bit of code by Include - but it is inconvenient to create an include file for just 1 or a few lines. Often in parallel to an existing file defining some functions.
So it would be fine to be able to:
- define some lines in a script file as an "Include Group", with a label naming it
- add 2nd operand to Include to address such a group (Analog to Load command.)
This way each file could define multiple "Include Groups"), and even a usual script could also supply includes.
Today we have multiple-script and -function files. This way we would add multiple-include to this.
(And yes: I would prefer to define all this in one file, be it .xys or .inc )
By the way: since some days I'm converting some old sub-scripts, including their use of perm and global variables, to functions!
Very fine - can't say it often enough
It would be fine to expand the sysntax!
I was glad that I can include a bit of code by Include - but it is inconvenient to create an include file for just 1 or a few lines. Often in parallel to an existing file defining some functions.
So it would be fine to be able to:
- define some lines in a script file as an "Include Group", with a label naming it
- add 2nd operand to Include to address such a group (Analog to Load command.)
This way each file could define multiple "Include Groups"), and even a usual script could also supply includes.
Today we have multiple-script and -function files. This way we would add multiple-include to this.
(And yes: I would prefer to define all this in one file, be it .xys or .inc )
By the way: since some days I'm converting some old sub-scripts, including their use of perm and global variables, to functions!
Very fine - can't say it often enough
Win11 Pro 223H2 Gerrman
Re: Scripting: User-Defined Functions
Yep, same here. These new features stand to make both xyscripts and <xyscripts> much cleaner!PeterH wrote:By the way: since some days I'm converting some old sub-scripts, including their use of perm and global variables, to functions!
Very fine - can't say it often enough
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Site Admin
- Posts: 60598
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Don't understand.SammaySarkar wrote:I really need include cmd to be available for one-liners. I've saved some frequent functions as an inc file, but none can be used in addressbar quickscripts because include wants to eat the whole line.
It's possible to script an alternative but nothing as simple as include "inc\xys.inc"
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
Stop include from demanding the whole line for itself.
When we use include in a single-line script, nothing else is possible because include requires the whole line.
I suggest include also works like this: so the command can be used in singleline scripts.
Why the | ? I suppose you search the script resource using a pattern to find-and-replace Include statements at runtime. The pattern-matching doesn't stop until encountering a newline.
Let it stop when it finds the | character. It can't be used in filenames.
When we use include in a single-line script, nothing else is possible because include requires the whole line.
I suggest include also works like this:
Code: Select all
::Include "fun.inc"| text 'hello';
Why the | ? I suppose you search the script resource using a pattern to find-and-replace Include statements at runtime. The pattern-matching doesn't stop until encountering a newline.
Let it stop when it finds the | character. It can't be used in filenames.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Site Admin
- Posts: 60598
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
I see your intention. But doing this could be a can of worms. I rather don't include a file into the middle of a line.
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
Can you make an exception when Include is the very first statement and at the beginning of line ?
Code: Select all
::include "Fun.inc"| text customecho("I promise I won't (can't) use any more Includes!");
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Site Admin
- Posts: 60598
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Not possible. The trailing part cannot be meaningfully appended to the contents of all possible included files. XY cannot know what "Fun.inc" is and it does not want to know.
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
keep pressing: append blindly?
keeping a new line at the end of included files can solve it.
keeping a new line at the end of included files can solve it.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Scripting: User-Defined Functions
Erm.. Sorry I forgot to check on this sooner but with v15.00.0501 the script doesn't even run when a function with more than 11 arguments is declared.admin wrote:Yes. Will be handled smoother in next beta.TheQwerty wrote: XY can crash when you start using a dozen or more arguments.
I suppose it's smoother than a crash but I think I preferred the crash simply because any feedback is better than none.
-
- Site Admin
- Posts: 60598
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Scripting: User-Defined Functions
Ah! The error message was generated but not shown. Pfff. Well, the feature is still inofficial and in progress... 15.10 will be the day, uh, version.
PS: Fixed in next beta.
PS: Fixed in next beta.
FAQ | XY News RSS | XY Twitter
Re: Scripting: User-Defined Functions
Cannot get the include statement to work in 15.00.0507
The file "<xyscripts>\MyFunctions.xyi" does exist
When I enter the following line at the top of a multi-script file.xys with multi-line sub-scripts:
I get an error that the hosting file.xys "does not contain any visible scripts."
Depending on various syntax variations I tried - with and w/o trailing semicolon, quotes, path hardwired - I sometimes also get the error "include file not found".
The file "<xyscripts>\MyFunctions.xyi" does exist
When I enter the following line at the top of a multi-script file.xys with multi-line sub-scripts:
Code: Select all
include MyFunctions.xyi
Depending on various syntax variations I tried - with and w/o trailing semicolon, quotes, path hardwired - I sometimes also get the error "include file not found".
Re: Scripting: User-Defined Functions
Do you use a non indented line with a script command after that include?
E.g. this doesn't work:
But this works:
E.g. this doesn't work:
Code: Select all
include "_functions.inc"
text "hello";
Code: Select all
include "_functions.inc"
text "hello";
<more commands>;
One of my scripts helped you out? Please donate via Paypal
Re: Scripting: User-Defined Functions
Ha, yes indeed. Upon closer examination you are right. When I make myself ignore all my comments on top, the original file starts like this:
I did not dare to change the indentation, because this is part of a larger script file, and I thought with Heredoc and all those syntax rules there is probably a good reason why this script template came with indented lines. Turns out, I can safely flush it to the left, and then "include" works.
However, if I also flush other, similar lines to the left, I get weird results, no longer seeing my menu entries, but rather the script code itself is showing on my context menu.
Code: Select all
/*** image file menu ***/
$image = <<<IMAGE
However, if I also flush other, similar lines to the left, I get weird results, no longer seeing my menu entries, but rather the script code itself is showing on my context menu.
Re: Scripting: User-Defined Functions
No... The first non "include ..." line must be non indented (this is only necessary if you include something, if not you can still begin with an indented line), not any other (apart from other include commands or subscript sections "<subscript 1>", etc.).
Btw, heredocs don't need a non indented opening line but a non intended closing (if they are the first line after an include this changes).
So again:
Works:
Doesn't:
Btw, heredocs don't need a non indented opening line but a non intended closing (if they are the first line after an include this changes).
So again:
Works:
Code: Select all
include "_functions.inc"
$a = <<<>>>
hello world
>>>;
text $a;
Code: Select all
include "_functions.inc"
$a = <<<>>>
hello world
>>>;
text $a;
One of my scripts helped you out? Please donate via Paypal
Re: Scripting: User-Defined Functions
In the conversations we had over time, I came to the conclusion that every script should have a Caption / Label, so that I think you are on the safe side with:(Don't forget to indent the $a= in this case...)
Code: Select all
include "_functions.inc"
"Main"
$a = <<<>>>
hello world
>>>;
text $a;
Win11 Pro 223H2 Gerrman