Access script variables from events like Set Text

1 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • So in a Set Text event, I can do something like:

    "Score: " & score

    In this scenario, score is a global variable and the output is something like... Score: 123

    Instead of using the score variable here, is it possible to use a different variable I previously added to globalThis in a script?

    Something like...

    globalThis.myScore = 123;

    and in Set Text:

    "Score: " & globalThis.myScore

    Is this possible? In my attempt, it doesn't like me trying to use globalThis.myScore in the event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think so, but you can go the 'other' way and set C3 event global variables in JS script.

    ... global variables, which are available via runtime.globalVars...

    So in scripting use:

    runtime.globalVars.myGlobalScore = scriptScore;
    

    Then in C3 events: create the global myGlobalScore and then Set Text "Score: " & myGlobalScore

  • See the Integrating events with script example.

  • There's 3 easy ways that come to mind, which one works best will depend on your situation.

    1. Create an event sheet function that gets the value. This works because you can set the return value of the current event sheet function from JavaScript using runtime.setReturnValue.

    2. Create an event sheet function that sets the score label. You can call event sheet functions by name from JS using runtime.callFunction passing in your variable.

    3. Assign the value to a event sheet variable. It's possible to read/write the local variables of an event sheet from and event sheet script block, and the projects global variables from any script type.

  • There's 3 easy ways that come to mind, which one works best will depend on your situation.

    1. Create an event sheet function that gets the value. This works because you can set the return value of the current event sheet function from JavaScript using runtime.setReturnValue.

    2. Create an event sheet function that sets the score label. You can call event sheet functions by name from JS using runtime.callFunction passing in your variable.

    3. Assign the value to a event sheet variable. It's possible to read/write the local variables of an event sheet from and event sheet script block, and the projects global variables from any script type.

    Nice solutions, thanks!

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