User-Defined Functions and Include Statement 101

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
tiago
Posts: 589
Joined: 14 Feb 2011 21:41

User-Defined Functions and Include Statement 101

Post by tiago »

Yet I do some XYplorer scripting plus having read proper Help sections I simply don't get User-Defined Functions and Include/include_once Statement.

Can someone try to enlighten a non-IT savvy on these?

This was raised by the following topic: http://www.xyplorer.com/xyfc/viewtopic. ... 10#p137510
Power-hungry user!!!

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: User-Defined Functions and Include Statement 101

Post by highend »

What exactly don't you understand?
Both parts have quite a bit of documentation in the help file :)
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: User-Defined Functions and Include Statement 101

Post by tiago »

I get the general idea is to avoid repetition of code but I don't know how to use it on an own written script.

I ran your snippet on that mentioned post and saw nothing. Tried to convert it to a simple script just to get more frustration...

Perhaps in a larger, real case example? Or using the same code on two different scripts?

...sorry...

:(
Power-hungry user!!!

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: User-Defined Functions and Include Statement 101

Post by highend »

Exactly like I did. Define one, use it anywhere.
I ran your snippet on that mentioned post and saw nothing. Tried to convert it to a simple script just to get more frustration...
How exactly did you run that because the "text" command produces a new window. It is already a simple script. One line to call the function and the function description itself :)
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: User-Defined Functions and Include Statement 101

Post by tiago »

Script/Run Script.
For the adapt, of course...
Last edited by tiago on 28 Apr 2016 17:01, edited 1 time in total.
Power-hungry user!!!

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: User-Defined Functions and Include Statement 101

Post by highend »

Show a screenshot of what you pasted into that script window before you hit ok and after hitting ok, absolutely nothing happens?
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: User-Defined Functions and Include Statement 101

Post by tiago »

Eh.
You changed the code, highend! I got it with a longer line 1 ('text...'), when I first test it.

Per this second test it works as expected and I'm able to understand from it, I guess. Will took time to examine.

Now, include st...? No, really cant get it.
Power-hungry user!!!

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: User-Defined Functions and Include Statement 101

Post by highend »

That was yesterday^^ I first showed a version that gets the neighbors for a specific file and afterwards changed it to position only. The former version worked fine as well...

Including is normally used to split code. E.g. you create a .xys file that contains all your (own) functions. E.g. generic ones, nothing specific that fits only for a single script. Instead of copying and pasting those functions into the current script you're working on you'll just include that file with an include statement. XY internally brings it's content into the scope of the current script so it can be executed from there. Of course this isn't limited to functions. You could also include files for e.g. translations. Whatever makes sense in the current context to make the code more readable / more generic.
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: User-Defined Functions and Include Statement 101

Post by bdeshi »

highend wrote:Including is normally used to split code. E.g. you create a .xys file that contains all your (own) functions.
I'm advocating the .xyi extension for such include-only files.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: User-Defined Functions and Include Statement 101

Post by tiago »

Hmmm, I see. Like the old song sings, "yesterday got nothing for me". :?

:D

Less generic, then. If I read you right a script using Include will resource to an external file making it... library dependent, so to speak. Of course it has usages specially for sys admins which is not my case. I'll try to learn the trick anyway. You never know...

Thanks much!
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: User-Defined Functions and Include Statement 101

Post by tiago »

@SammaySarkar: thanks for the functions catalog, learned much from it as well as regarding inclusion.
Power-hungry user!!!

Post Reply