self()

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

self()

Post by altoclef » 04 Mar 2019 09:32

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.

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

Re: self()

Post by SammaySarkar » 04 Mar 2019 11:44

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.

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

Re: self()

Post by altoclef » 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.

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: 2574
Joined: 21 Nov 2005 20:39
Location: Germany

Re: self()

Post by PeterH » 04 Mar 2019 12:21

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 )

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

Re: self()

Post by SammaySarkar » 04 Mar 2019 13:03

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.

admin
Site Admin
Posts: 46917
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: self()

Post by admin » 07 Mar 2019 15:16

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

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

Re: self()

Post by altoclef » 14 Mar 2019 18:22

Confirmed as fixed in 19.80. Thank you.

Post Reply