How do I initiate YouTube API script from another layout (Not the first one)

0 favourites
  • 5 posts
From the Asset Store
Plugin Transition Layout C3. Layout opening and closing animation for C3. Quickly set up transitions between lay
  • Basically what I ask on the subject. Is it even possible? I had try many conmbinations but nothing works.

    Also, is it posible to change the on click a button from the example API to a OnTouchedObject from a Touch?

    I´m kinda new on JS so I feel totaly lost on this.

    Thanks in adavance.

  • export async function createVideo(iframeId) {

    Globals.ytPlayer[iframeId]["player"] = await YouTube.CreatePlayer(iframeId, {

    "onStateChange": e => { Globals.ytPlayer[iframeId]["state"] =; },

    "onReady": e => {}


    return true;


    How do I use the state to change a global variable at an event sheet?

    I want something like this, but I cant find the way to mix both examples:

    const stateTextInst = runtime.objects.StateText.getFirstInstance();

    const ytPlayer = await YouTube.CreatePlayer("youtubeIframe", {

    "onStateChange": e =>


    // When the player state changes, show it in the StateText object.

    stateTextInst.text = "" +;



    Thanks for the links.

  • You can use

    	runtime.globalVars["Variable name"] = newValue


    	runtime.globalVars.myVariable = newValue;



    An object with a property for each global variable on an event sheet in the project. For example if the project has a global variable on an event sheet named Score, then runtime.globalVars.Score provides access to the global variable from script.

    I'm not on pc now but I think something like this could go:

    	const ytPlayer = await YouTube.CreatePlayer("youtubeIframe", {
    		"onStateChange": e => {
    		runtime.globalVars.myVariable = "" +;

    To simplify the use of "runtime" I prefer to insert a code of this type in 'main.js':

    	runOnStartup(async runtime => {	globalThis.g_runtime = runtime; });

    I use g_runtime instead of runtime

    	const ytPlayer = await YouTube.CreatePlayer("youtubeIframe", {
    		"onStateChange": e => {
    		g_runtime.globalVars.myVariable = "" +;

    If you want "ytPlayer" to be global you have to use the one imported from Globals.js

    	Globals.ytPlayer = await YouTube.CreatePlayer("youtubeIframe", {
    		"onStateChange": e => {
    		g_runtime.globalVars.myVariable = "" +;

    However, remember that the variables in the event sheet can only be strings, numbers or booleans

    I can't test this code right now

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks a lot, I finally made it works!

    I really apreciate you help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)