Page 1 of 1

Calling Other Scripts From A Main Script

Posted: Tue Jun 04, 2024 9:09 pm
by oceanarts
It seems to me that it should be possible to call a separate "subscript" from a main script, let it run in its entirety and then return control to the main script.
I've tried the @INCLUDE pre-processor, but it seems, according to the docs, I can only reference individual functions using this.

Is this correct, or am I misunderstanding its use?

Re: Calling Other Scripts From A Main Script

Posted: Tue Jun 04, 2024 11:36 pm
by plouf
yes you cant make functions in hws only way

but whats the reason to "Call a script" ?

Re: Calling Other Scripts From A Main Script

Posted: Tue Jun 04, 2024 11:55 pm
by oceanarts
I'm sorry if my wording is causing confusion.

The thing is I've written a mini-game which is supposed to be part of a larger project. It's in its own script and it would just be easier if there was a way to run it from the main program and have it return once it's finished or otherwise exited.

Re: Calling Other Scripts From A Main Script

Posted: Wed Jun 05, 2024 12:02 am
by plouf
if you make this "Script" a big function, and you call this function from main script , will do do just that don;t it ?!

Re: Calling Other Scripts From A Main Script

Posted: Wed Jun 05, 2024 7:42 am
by emeck
@oceanarts

Try with Execute() or Run(). Run/execute Hollywood and pass the script as an argument. Haven't tried it myself but it should work.

Regards

Re: Calling Other Scripts From A Main Script

Posted: Wed Jun 05, 2024 7:31 pm
by oceanarts
Thanks for the tips. It didn't occur to me I could encase the whole thing in one big function.

Re: Calling Other Scripts From A Main Script

Posted: Tue Jun 18, 2024 12:57 am
by zylesea
I suggest to use the Run() command if you want to keep your daughter script also as a stand alone program.
You shoud set up a message port in your daughter script and an EventHandler:

CreatePort("daughter_script_MSGPORT") ;Message port for Interprocess communication
InstallEventHandler({OnUserMessage = p_EventFunc})

In your main script you need to check whether the script exists, if so launch it by Run()

If Exists ("drawer/daughter_script") Then Run ("drawer/daughter_script")

With the message port you can pass on some control items (like defined in your event function to your daughter program from the main program.

For example to iconify or deiconify the dauhter program you can do the following:

in main programm:
SendMessage("daughter_script_MSGPORT", "ICONIFY")
or
SendMessage("daughter_script_MSGPORT", "DE_ICONIFY")

The daughter program needs in its event functions a chapter like this:

Case "OnUserMessage":
Switch msg.command
Case "ICONIFY"
HideDisplay()
Case "DE_ICONIFY"
ShowDisplay()
EndSwitch

Works nice for me.