Why does this return 0.1? - Parse.com plugin

0 favourites
  • 2 posts
From the Asset Store
Game "Little Dino Adventure Returns" with complete Source-Code (Construct3 / .c3p) + HTML5 Exported.
  • Hello

    I'm developing a Parse.com plugin for C2, and I get this annoying error.

    When I set the value to a variable in C2 using an expressesion, it gets turned into 0.1 for any integer or float.

    When I log to the console directly from runtime, it returns the correct result. When I do it using C2, it returns 0.1 in the console log.

    This is my code in runtime:

    Exps.prototype.QueryHighest = function (ret,par0,par1,par2)
    {
    	var Object = Parse.Object.extend(par0);
    	var query = new Parse.Query(Object);
    	
    	// Retrieve the values descending
    	query.descending(par1);
    	 
    	query.first({
    		success: function(result) {
    			var Return = result.get(par2);
    			console.log(Return);
    			if(isNaN(Return)){
    				ret.set_string(Return);
    				console.log("set_string");
    			}else if(!isNaN(Return)){
    				if(isInt(Return)){
    					ret.set_int(Return);
    					console.log("set_int");
    				}else{
    					ret.set_float(Return);
    					console.log("set_float");
    				};
    			}else{
    				ret.set_any(Return);
    				console.log("set_any");
    			};
    		},
    		error: function(error) {
    			alert("Error: " + error.code + " " + error.message);
    		}
    	});
    };[/code:re1csazq]
    
    And for the edittime:
    [code:re1csazq]AddStringParam("class","Which class does the object lie in?");
    AddStringParam("search attribute","The attribute whose value you want to search for.");
    AddStringParam("attribute","The attribute whose value you want to get.");
    AddExpression(0, ef_return_any, "Parse query: highest result", "Search Query", "QueryHighest", "Returns the highest value from a specified attribute.");
    [/code:re1csazq]
    
    And in C2:
    [img="http://i.imgur.com/sbBdWbQ.png?1?5042"]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Values must be returned synchronously from expressions. If query.first() is asynchronous, then you return a value after the expression has already returned, which is not allowed. It is really a bad idea to use anything asynchronous in an expression anyway, it doesn't fit the model of how Construct 2 works. Instead you should have an action to start the asynchronous task, a trigger that fires when it completes, and then synchronous expressions that return the results of the task.

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