[Solved] Issue withvalue in Expression from promise

0 favourites
  • 3 posts
  • 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;
    		.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);
    		.catch(function(err) {
    			varself.dataError = (err).toString();
    			varself.msgContent = ("error " + varself.dataError).toString();
    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
  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)