Calling scripts

picklish

Member
I'm admittedly still new here, but I've read all the docs and this is still unclear to me. If this is a case of RTFM, then please point me to the appropriate FM. :)

Use case: I have a script with a function in it. Let's call this function "void doStuff(int times)".

Is there anyway to call this function from the CLI or does it have to be in an ASH script?

If it is in an ASH script, is there any way to just #include/import that script in another script to use that function?

If neither of those are possible, then it seems like I have to put this function in some dostuff.ash file by itself and then add a "void main(int times)" function that calls the doStuff function. However, how do I then call this function (either from the command line or from another ASH script) and pass along the parameters on the command line? "call dostuff.ash 3" doesn't work. Finally, "call dostuff.ash" just prompts me with the GUI (yuck).
 

Nightmist

Member
Is there anyway to call this function from the CLI or does it have to be in an ASH script?
Technically it has to be from a ASH script. Although it is possible to call a ASH script which just happens to call that function. But if your looking to also pass a value to this function then:
To do this your going to have to use the CLI command "set" and then get that value in the ash script though a get_property.

You can use the ash command:
Code:
import <PATH.ash>;
at the start of the script and it should import all the commands in the imported script... (But if your trying to import a single specific function then just put it into a separate file assuming you really dont want to copy it straight into your script)
 

picklish

Member
[quote author=Nightmist link=topic=338.msg1830#msg1830 date=1155303277]
Technically it has to be from a ASH script. Although it is possible to call a ASH script which just happens to call that function. But if you're looking to also pass a value to this function then to do this you're going to have to use the CLI command "set" and then get that value in the ash script though a get_property.[/quote]
Thanks for letting me know how that can be done. At the same time, that's a pretty obtuse way of doing things. I wonder how easy it would be to do something naive like making lines that start with "!" run ASH commands off the command line. That would solve both of my problems...

[quote author=Nightmist link=topic=338.msg1830#msg1830 date=1155303277]
You can use the ash command:
Code:
import <PATH.ash>;
at the start of the script and it should import all the commands in the imported script... (But if you're trying to import a single specific function then just put it into a separate file assuming you really don't want to copy it straight into your script)[/quote]
Thanks! That's exactly what I was looking for. Did I miss that in the reference doc or is it just undocumented?
 

Tirian

Member
I guess import is undocumented. I wonder if there's anything else that isn't a flow control keyword or a data type or a function....

If I may ask, what is it that you're doing that you want to run ASH commands off the command line? There are probably ways around doing anything that you'd want to do, but I'm not sure that I understand the problem that you're trying to solve.
 

picklish

Member
[quote author=Tirian link=topic=338.msg1839#msg1839 date=1155307769]
If I may ask, what is it that you're doing that you want to run ASH commands off the command line? There are probably ways around doing anything that you'd want to do, but I'm not sure that I understand the problem that you're trying to solve.[/quote]
That's a fair question. Mostly it's due to just wanting to be able to debug new functions off the command-line. It's a workflow optimization, because I'm a lazy programmer who dislikes having to go edit a file whenever I want to test a different parameter value.

Also, the immediate issue was that I wrote a "drink(int drunkenness, int estimatedMeatPerTurn)" function that needed to be called twice (once for all but one drunkenness, once for cap) and I wanted to stick it in an existing dinky command-line script I had been using previously without much hassle.
 
Top