Page 2 of 10
Re: Scripting: User-Defined Functions
Posted: 10 Apr 2015 21:11
by admin
Yep.
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 01:12
by PeterH
Oh - something I'd call a bug
with Includes
After I have included a (.inc-) file, this will be remembered in the current state, even after termination of the "including script".
If, after finding an error, I change the file and restart the original script to include and execute the new .inc version, still the old is executed.
The only way I found in the moment: stop/restart XY. That can't be planned??
(I "prefer" some bugs in my scripts - for debugging I have to restart XY several times
to load the changed .inc)
So, if loading of Includes should be optimized:
at least when the last script terminates, i.e. when no more script is active, all Includes should be dropped.
(And yes: if I have a script loading a script loading a script..., and several happen to include the same file, it's enough to load it only once.)
Or did I understand something wrong?
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 10:03
by admin
Cannot confirm. Everytime the include statement is met the file is freshly read from disk.
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 11:02
by admin
PeterH wrote:One (rather old) wish (from Load)
: for include it would be very fine, if it also could replace itself with the contents of a variable (instead of a file). With this you could build a kind of script-generator. (Again: name it "Macro ability".) If it's not too difficult...
Not possible. You have to find another way to build your script-generator.
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 12:15
by PeterH
admin wrote:Cannot confirm. Everytime the include statement is met the file is freshly read from disk.
Tested with minimal version: always reproducible, even from Fresh;
2 files, both in xyscript folder
tinc.xys:
Code: Select all
// test refresh of a chged .inc
include "tinc.inc"
"Label"
$r = t(0);
Echo "r = $r";
tinc.inc:
- run tinc.xys
result shows 1 OK
- change tinc.inc to add 2 instead of 1
- run tinc.xys again
result shows 1 again, should be 2
- if I run it in step mode the stmt in the function still shows + 1, not + 2
- restart XY, run again
result is 2, as expected.
So what's wrong here?
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 14:12
by bdeshi
nothing wrong here on my pc.
edit. also OK in ::fresh and "fresh vanilla"
(new <xypath>, new <xydata>) .
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 15:30
by klownboy
After changing the +1 to +2 my result was the same, like PeterH's until I restarted XY. So, what would account for the different result from Sammay's?
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 15:48
by admin
Aaaahh!! Got it! Yep,
. Only comes when you load a script from file! Hence did not see it first.
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 16:09
by bdeshi
loading from a file here all the time!
::load 'tinc.xys';
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 16:12
by admin
I meant using User | Run Script | Load selected script file.
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 16:14
by bdeshi
Oh... "Aaaahh!!" me too!
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 17:18
by PeterH
Really wouldn't have thought of that
Running from
Scripting/Load Selected Script File shows that problem, while
::load tinc; doesn't!
The ::load even "repairs" the situation when the load by Scripting Menu fails
Glad that it wasn't a bad dream
Re: Scripting: User-Defined Functions
Posted: 11 Apr 2015 17:32
by admin
A bit of explanation: I always optimize for performance, not for maintenance. That's why sometimes several entry points and pathways exist for effectively identical functionality. In this case I forgot to add a line of reset code in one of them. So your updated functions were correctly read and added, but *after* the old functions (that had not been reset). Since the first function wins by the current logic, your updated functions never were used.
Re: Scripting: User-Defined Functions
Posted: 12 Apr 2015 11:35
by PeterH
Thanks for the info.
Now, knowing that ::load works OK, I can continue to test
Re: Scripting: User-Defined Functions
Posted: 12 Apr 2015 11:40
by admin
Fixed version coming soon...