0 votes
by (2.9k points)
Hi, I'm trying to launch a program using javascript in my game. What I mean by that is that I am trying to launch a game I made in javascript through twine, meaning I'm using it as a game launcher. if anyone knows how to do so that would be great.

1 Answer

+1 vote
by (159k points)
Some examples of both your existing TwineScript in the launching Passage as well as of your Javascript game would help us understand you requirements better.

When you say 'launch' do you mean:

1. Open a HTML page (containing the Javascript game) in another tab.
2. Show a HTML page (containing the Javascript game) embedded within the current passage.
3. Something else...
by (2.9k points)
edited by
I don't know if its possible but my goal is to launch a javascript game that is in my twine folder.
by (159k points)
So the Javascript game isn't contained within a HTML page or referenced as an external JS file from a HTML page?

Is just a self contained external Javascript JS file on your hard-drive that has it's own non-HTML GUI?
by (2.9k points)
Self contained js file
by (159k points)

As far a I know you cant.

For security reasons web-browsers generally don't allow the execution of external applications/utilities, and I believe a self contained js file/application would be consider an external application.

** This is different to importing the contents of an external js file into a HTML page via a script element.

by (2.9k points)
Would you mind elaborating on "Importing".
by (159k points)

There are two ways Javascript code used within a HTML application is stored.

1. You can embed the Javascript code within the HTML file itself using one version of a script element, this is basically how the contents of the story's Story Javascript area is handled.
The element would eventually look something like the following:

<script type="text/javascript">
	/* Story's Javascript. */
	var variable = "value";
</script>

2. You can reference an external JS file using a different version of a script element, and the JS file's contents will be pulled into the HTML document (DOM) after the HTML file is opened.
The element would look something like the following:

<!-- HTML4 and (x)HTML -->
<script type="text/javascript" src="external-file-name.js"></script>

<!-- HTML5 -->
<script src="external-file-name.js"></script>

... the above method assumes that the Javascript contained within the JS file will be used by the HTML file loading (and executing) it and that any visual output (either DOM manipulation or canvas element based) will appear within the HTML document generated by the HTML file.

There are restrictions on what the Javascript can do when it comes to access the resources of the current machine and it's operating system, which is why the above methods generally can't run self-contained Javascript applications that have their own non-HTML based GUI.

...