Page 1 of 1

self()

Posted: 04 Mar 2019 09:32
by altoclef
I don't understand why I get different results from the following statements in the same script:

Code: Select all

text self("file")."<br>".
     self("path")."<br>".
     self("base");

     Foo();

function Foo() {
    text self("file")."<br>".
         self("path")."<br>".
         self("base");
}			
First results:
C:\AppData\XYplorer\Scripts\Test.xys
C:\AppData\XYplorer\Scripts
Test
which is as I expect.

However, the results in Foo():
C:\AppData\XYplorer\Scripts\Test.xys
C:\AppData\XYplorer
I see in the Help for self()
file: current script file (empty if none)
path: current script file's path (app data if none)
base: current script file's base (empty if none)
As info type file is returning the same results in the two calls, I do not understand why, when called from Foo(), types path and base are returning results as if there is no script file.

Please could someone explain.

Re: self()

Posted: 04 Mar 2019 11:44
by SammaySarkar
functions have global scope. The scripting engine inspects the entire executing script chain and collects all functions into memory. Then functions are executed from this memory space, therefore they aren't executed from a file. this is as close to the truth as I can surmise.

Re: self()

Posted: 04 Mar 2019 12:12
by altoclef
Thank you for your suggestion, SammaySarkar. I have only recently started writing XY scripts, so I did not realise that functions have global scope - that is interesting and I shall bear that in mind when writing more in future.

However, I am not sure that that explains why self("file") can correctly report the full script path, but the other 2 options cannot. The more I think about this, the more I wonder if this is a bug.

Re: self()

Posted: 04 Mar 2019 12:21
by PeterH
Just a hint: <xxx> are variables, so even <br> is a (constant :-) ) variable.
Variables usually aren't quoted, so you can omit the quotes around it.

Vars in quotes are just *allowed* to combine them with other text inside (double!) quotes like "line1<br>line2"

So you can save some keys to enter...

Re: self()

Posted: 04 Mar 2019 13:03
by SammaySarkar
altoclef wrote:
04 Mar 2019 12:12
Thank you for your suggestion, SammaySarkar. I have only recently started writing XY scripts, so I did not realise that functions have global scope - that is interesting and I shall bear that in mind when writing more in future.
That's straight from the docs. Run this script to go there:::help "idh_scripting.htm#idh_scripting_udf";
However, I am not sure that that explains why self("file") can correctly report the full script path, but the other 2 options cannot. The more I think about this, the more I wonder if this is a bug.
Yeah, let's see what Don says.

Re: self()

Posted: 07 Mar 2019 15:16
by admin
That was a bug. :bug: Was...

Re: self()

Posted: 14 Mar 2019 18:22
by altoclef
Confirmed as fixed in 19.80. Thank you.