i everyone, I am stuck with this problem for 2 days now.
I have a function :
public func secure_eval_game_2(nb_choosed:Text, amount:Float) : async Text{
var c = Time.now()/1000;
var a = c % 6+1;
var nb_rand = Int.toText(a);
var result:Bool = nb_rand == nb_choosed;
if(amount > wallet or amount < 0.01 or amount > 1){
return 0;
}
else{
if(result == true){
credit_wallet(mise*(6-1));
}
else{
debit_wallet(mise);
}
};
return nb_rand;
};
In this easy function we :
ā generate number between 1 and 6 (nb_rand)
ā We compare the chosen number (by user) with the (pseudo) random number.
ā We modify the wallet balance according to result Win/lose.
ā At the end, we return the random_number, this random number is given in the .js file, and then, we can use it and display it in browser.
My question is :
Does it exist any way to return nb_rand in the JS and execute credit_wallet/debit_wallet (modify balance wallet) after it has been returned ? (To improve experience, because the Js render is blocked, waiting for execution in blockchain).
The only way i found is : to do this in my js :
nb_rand = motokoFile.generateNumber(); // No writing process in blockchain, only read, so we instantly
// get the random_number to display it.
displayInJs(nb_rand);
motokoFile.evaluation_result(nb_rand); //unsecure
However, in this way, i guess that nb_rand could be intercepted in JS and a different number could be give to the motokoFile.evaluation_result(nb_rand) function.
I am completely completely completely stuck with async and none-async function in motoko fileā¦ And this is probably why I canāt do it.
Other example :
public query func generateNumber(): async Text{
var c = Time.now()/1000 % 100 ;
return c;
};
public function test() : async Int{
var a = generateNumber()
var b = a + 1; // problem
};
I get this kind of error and I have no idea about what I am supposed to do to solve it. (This error is not for this particular case). I guess that itās because a is returned y an async func and b must wait for a to be evaluated, but I donāt know which keyword or synthax use.