send variable values using parent.postMessage

Not favoritedFavorited Favorited 0 favourites
  • 2 posts
From the Asset Store
The soundstage is set for an immersive listening experience sending your audience adrift.
  • Hello.

    I am very new to scripting and coding.

    I am trying to send variables values using parent.postMessage:

    parent.postMessage({
     tipo: "jogo-completo",
     pontuacao: [runtime.globalVars.Pontuacao],
     tempo: ${runtime.globalVars.TempoTotal},
     nivel: 3
    }, "*");
    window.addEventListener("message", function(event) {
     console.log("Mensagem recebida:", event.data);
    });
    alert("Você completou o jogo!");
    console.log("✅ Enviando dados:", {
     pontuacao: runtime.globalVars.Pontuacao,
     tempo: runtime.globalVars.TempoTotal,
     nivel: runtime.globalVars.NivelAtual
    });
    
    

    I want to send 'pontuacao' (points) and 'tempo' (time)

    The global variables for both are created.

    I have tried, for example:

    [runtime.globalVars.Pontuacao] and ${runtime.globalVars.TempoTotal} but they don't work.

    Anyone can kindly guide me what I am getting wrong and how to send this variable values?

    Thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ${runtime.globalVars.TempoTotal} is not valid syntax outside of a template string. Try just using runtime.globalVars.TempoTotal on its own.

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