Setting a Global String from JS

0 favourites
  • 4 posts
From the Asset Store
Globals 2.0
$3.60 USD
10% off
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi there,

    I have two global variables and a script.

    What I am trying to do is the following:

    1) Pass the first global to the script

    var result = showMessage(runtime.globalVars.speechFinal);

    2) Set the second global with the result

    runtime.globalVars.finalOutput = result;

    The script has the following and delivers the expected output in the console:

    function showMessage(interimresult)

    {

    var string = interimresult;

    var cleanSet = new Set(string.split(' '));

    var clean = Array.from(cleanSet).join(' ')

    console.log(clean);

    clean.toString();

    }

    However the second step is failing.

    When trying to do this I get the following error:

    Cannot read properties of undefined (reading 'toString')

    Any help or pointers would be greatly appriciated!

    Best wishes

    /Thomas

  • Hello,

    You mentioned that the issue is with step 2, setting the global variable. However the error provided suggests an issue with calling the toString method on undefined.

    Can you confirm your clean variable actually is defined? Also I don't see you actually returning a value from your showMessage function.

    Either these are the problems you are facing or you haven't provided the full source.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi there,

    thank you so much for pointing me in the right direction!

    It was, as you said, the function not returning a value which caused the undefined value error.

    I just added "return clean;" to the script and now everything works as expected :-D

    Thank you so much for helping out!

  • Excellent, have a good day coding!

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