Page 1 of 1

User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 16:08
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

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 16:31
by highend
What exactly don't you understand?
Both parts have quite a bit of documentation in the help file :)

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 16:45
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...

:(

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 16:50
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 :)

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 16:57
by tiago
Script/Run Script.
For the adapt, of course...

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 17:01
by highend
Show a screenshot of what you pasted into that script window before you hit ok and after hitting ok, absolutely nothing happens?

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 17:37
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.

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 17:47
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.

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 18:00
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.

Re: User-Defined Functions and Include Statement 101

Posted: 28 Apr 2016 18:08
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!

Re: User-Defined Functions and Include Statement 101

Posted: 30 Apr 2016 19:25
by tiago
@SammaySarkar: thanks for the functions catalog, learned much from it as well as regarding inclusion.