self()

Discuss and share scripts and script files...
Post Reply
altoclef
Posts: 30
Joined: 12 Oct 2012 18:54

self()

Post 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.

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: self()

Post by bdeshi »

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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

altoclef
Posts: 30
Joined: 12 Oct 2012 18:54

Re: self()

Post 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.

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Re: self()

Post 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...
W7(x64) SP1 German
( +WXP SP3 )

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: self()

Post by bdeshi »

altoclef wrote: 04 Mar 2019 12:12Thank 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: self()

Post by admin »

That was a bug. :bug: Was...

altoclef
Posts: 30
Joined: 12 Oct 2012 18:54

Re: self()

Post by altoclef »

Confirmed as fixed in 19.80. Thank you.

Post Reply