How do I get a FETCH result in a global variable?

0 favourites
  • 2 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • HI... Can you tell me how to do so that the data that Fetch throws in console.log can be saved in a global variable of the project?

    I thought it was so...

    const url = runtime.globalVars.urlg;
    
    const responseg = await fetch( url , requestOptions)
     .then(response => response.text())
     .then(result => console.log(result))
     .catch(error => console.log('error', error));
    
    runtime.globalVars.json1 = responseg;
    

    But it gives me an error in the variable...The response is a JSON, and i need to do 5 o 6 queries in parallel...(this is only one)

    Thank you!

    (in console.log it works perfectly, but the variable does not capture the result)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, I was able to solve the above problem very simply.

    const url = runtime.globalVars.urlg;
    
    const responseg = await fetch( url , requestOptions)
     .then(response => response.text())
    
     .then(function (result) { console.log(result); //here goes the capture//
     runtime.globalVars.json1 = (result);})
    
     .catch(error => console.log('error', error));
    
    

    Now i have another problem... i need to be able to encode some of the information in hmac Sha256.

    I can't find any addons or plugins that provide me with this theme, nor information about the theme that I can use in construct 3. Any ideas?

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