nadiavi's Forum Posts

  • 1 posts
  • Hi, I have an external js script with some async funcstions and I want to call them in event sheets one after another and make sure each one finishes working before the next one starts. What is the best way to do so? Using await or wait for previous actions to complete? Here is my code in the external script:

    class YandexSDK {
     constructor () {
     this.ready = new Promise(resolve => this.init = resolve);
     }
     setSDK (ysdk) {
     this.ysdk = ysdk;
     } 
     showFullscreen () {
     this.ready.then(() => this.ysdk.adv.showFullscreenAdv({
    	callbacks:{ 
    	 onClose: () => {
     console.log('Ad was closed');
     }}}))
     }
     load_player () {
     this.ready.then(() => this.ysdk.getPlayer().then(_player => {
     player = _player;
    		console.log('Player Loaded '+ String(player));
    		return player;
     }).catch(err => {
     console.log('Error loading player');
     }))
     }
     
    };
    
    async function load_player_score(runtime) {
     if (player != null) {
    	loaded_stats = await player.getStats();
    	console.log("loaded stats: "+loaded_stats.score_save);
    	runtime.globalVars.score = loaded_stats.score_save
    	console.log("updated score ")
    	}}
    
    

    And here is the event sheet, now I am using await but I also tried waiting for previous action - but it doesn't work as I am expecting. Could you please advice?

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1 posts