How do I pass config info to C2 web app on startup?

Get help using Construct 2

Post » Fri Jun 16, 2017 11:57 am

I have built a web app called ChemThink in C2 which resides on my website, http://www.simbucket.com.

1. I would like to place different instances of the ChemThink web app in frames in different locations on my website.
2. Each instance needs to be aware of its parent page so that it loads up the appropriate portion of the web app.

URL to the ChemThink web app: http://simbucket.com/chemthinkserver/chemthink/

URL to the simbucket.com parent pages: https://www.simbucket.com/welcome-to-simbucket/

Depending on which simulation a student clicks on the parent page, I want "ChemThink", the C2 app, to automatically bring the student to the right tutorial or question set upon login.

Rationale:
By the time ChemThink is finished, it will be around 8500 events, with hundreds of event sheets. I want to make sure that I don't have to maintain many different versions of the project.


How do I either do either of the following:
A. Pass a variable from the parent page to the ChemThink instance so that ChemThink knows which tutorial to load?

-or-

B. Give the ChemThink instance the ability to inspect its parent page so that ChemThink knows which tutorial to load?
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 402
Reputation: 16,652

Post » Sun Jun 18, 2017 8:55 pm

cjbruce wrote:How do I either do either of the following:
A. Pass a variable from the parent page to the ChemThink instance so that ChemThink knows which tutorial to load?

-or-

B. Give the ChemThink instance the ability to inspect its parent page so that ChemThink knows which tutorial to load?


Solved!

In order to do "B" above, I can get the desired result with the execJS function, as follows:

1. Create a global variable in the parent page called "tutorialname"

Code: Select all
<script>
      var tutorialname = "";


2. In Construct, On Start of Layout -> Browser -> Alert Browser.ExecJS("parent.tutorialname")


The bottom line is that I can set a Construct variable = Browser.ExecJS("parent.variablename"). I just need to have the ability to add a variable the parent page's source code.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 402
Reputation: 16,652

Post » Mon Jun 19, 2017 7:57 pm

Another approach is to place the variable in a URL query string:

https://www.mywebsite.com/index.html?ms

In the event sheet, one can recover the value "ms" as follows:

On start of layout -> Browser -> Alert tokenat(Browser.ExecJS("window.location.href"),1,"?")
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 402
Reputation: 16,652


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests