[Solved] Issue withvalue in Expression from promise

0 favourites
  • 3 posts
From the Asset Store
Add this awesome sound effects to make your visual novel come to life!
  • I currently have this code that sends everything to the console.log just fine, but when it comes back into Construct it always displays the textbox(messagebox) name or C2function name(bothlogs), depending if I'm calling the temp variable or the expression within the C2Function

    	Exps.prototype.getText = function (ret, stuff_)
    	{
    		var varself = this;
    		function.get(stuff_)
    		.then(function(content) {
    			// .replace to remove control characters from the string
    			varself.msgContent = ((content).toString()).replace(/[\x00-\x09\x0B-\x1F\x7F-\x9F]/g, "");
    			console.log("Retrieved: " + varself.msgContent);
    			return varself.msgContent
    		})
    		.then(function(text) {
    			console.log("Returned: " + text);
    			ret.set_string(text);
    		})
    		.catch(function(err) {
    			if(err){
    			varself.dataError = (err).toString();
    			console.log(varself.dataError);
    			}
    			varself.msgContent = ("error " + varself.dataError).toString();
    			ret.set_string(err);
    		});
    
    	};
    [/code:37md67hx]
    [img="https://i.imgur.com/5dtZhH9.png"]
    [img="https://i.imgur.com/623HJcT.png"]
    
    Theoretically it should return with the same thing the console.log functions produce but I can't seem to get it working. I'm assuming it's something to do with it being a promise rather than a linear function.
    
    My goal is to have the plugin.getText() expression be able to immediately get the text, as currently I have it 'working' with an action/triggered condition combo but that's not ideal for directly applying the text it to object instances on demand. If someone could help me
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • After spending quite a few hours trying to work things every which way I've just decided to mimic how AJAX calls are tagged and triggered to ensure I can direct the data where I need to as the asynchronous stuff works fine with condition triggers

  • Events run synchronously. You cannot use promises in expressions since Construct checks the return value immediately after the function returns. Your expression kicks off a promise which runs asynchronously but the resolve value is never used by anything.

    You've already found the solution - use the same model as AJAX where actions kick off asynchronous work and then fires triggers upon completion.

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