Jump to content
  • 0

Running included scripts from the including script


jostikas

Question

Posted (edited)

Hi! Hoping someone has already solved this:

I have a larger project divided into several script files that include each-other.

One file defines a bunch of `const` values (naming of IO pins), which the others use. However, if the script file with the values hasn't been run, then the other files get the values as `undefined`.

For me, it's not a problem to run the prerequisites. But the end-user (someone on the factory floor) doesn't need to know the implemetation details, they need to press "run" and get a pass/fail at the end.

So: can I somehow invoke the prerequisite included scripts from the final "main" script, or perform a "run all" (not preferred, as I would like to use the same prerequisites for different "main" scripts)?

Recreate:

  1. Open included project
  2. Run script "file 1"
  3. check result
  4. Run script "file 2", then run "file 1"
  5. Compare result with step 3.

What I get:

In step 2: `undefined`. In step 4: `0`.

What I wish to get:

In step 2: `0`.

Include problem.dwf3work

Edited by jostikas
need -> wish
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hi @jostikas

Currently the tabs are concatenated in order they appear, the active tab and the included ones.
The next version will make sure the active tab is the last one so your example will work at first try.

Thank you for the observation.

Link to comment
Share on other sites

  • 0
Posted (edited)

EDIT: This has an easy enough workaround! If you're still on vacation, then vacate away, please!

Thank you! Works with the included minimal sample.

However, it still fails in cases of nested includes, even if all the requirements are also included -- if classes are instanced before their dependencies have been included by the running script.

To recreate:

  • Open included project
  • Run script "file 3"
  • Run script "file 4"
  • Run script "file 3"

Expected:
Identical behaviour when "file 3" is run.

Actual:

First run gets "undefined", second gets "0xdeadd00d"

Additional notes:

The fact that I need to include all the dependencies of the dependencies is not intuitive.
I realize that this is probably slowly getting out of the scope of what is supposed to be a simple scripting interface, requiring a deeper dependency management method. Maybe simplest would be to automatically add include guards around scripts, and do depth-first inclusion, like C preprocessor, but automated. What that entails in terms of backwards-compatibility and complexity for you, I don't know.

A feasible workaround would be to enable reordering of file tabs, so users could manually manage include order.

Include problem extended.dwf3work

Edited by jostikas
Rest is important.
Link to comment
Share on other sites

  • 0

Hi @jostikas

I originally intended the Script for simple automation tasks, someone requested support for multiple files, and then the include...
The next sw version supports tab reordering and recursive include.

image.png

Link to comment
Share on other sites

  • 0
Posted (edited)

Recursive include now (3.22.25) causes a crash with files that include each other.

Recreate:

  1. Open Script
  2. Add new file
  3. Include file 1 from file 2
  4. Include file 2 from file 1
  5. Run file 1

Expected:

Nothing, as both files are empty

Actual behaviour:

Crash.

If I had to guess, the flag that a particular file has already been included, is set after it is included, not before, meaning that file 2 doesn't realize that file 1 has already been seen?

Edited by jostikas
Added note on current version for future reference
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...