You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pyrosshade edited this page May 11, 2019
·
5 revisions
write a user transaction
We want to implement a "welcome bonus" when the user reach a place.
server side code
function __welcomebonus(params, customData, mod) {
"use strict;"
// don't edit above this line // must be on line 3
var self = this;
var user_id = params.user_id;
var domain = this.game.getPrivateDomain();
return self.tx.transaction(domain, user_id, {"bonus" : mod.common.square(10) }, "welcome bonus").spread (function (newbalance, triggered) {
mod.debug(JSON.stringify(newbalance));
return { "totalbonus" : newbalance.bonus };
});
}
Here, bonus is calculate to show a sample use of mod.common.
mod.common act as a library : you can define reusable functions within a dedicated batch called 'common'. the content returned by this function will be available in all others batches and hooks.
Let's try to define a square function :
function common(mod) {
"use strict;"
// don't edit above this line // must be on line 3
return {
square: function (x) { return x*x; }
};
}
Therefor you can call mod.common.square in any of your batches.
Obviously, you can define function which access to any cloudbuilder API.