Im trying to make a shop where a player can touch a item and press g to purchase it. When the player collides with a item the cost correctly shows in the action text but when they press g all of the wrong info is sent to the server and the player is charged and given what they have not payed for.
var Purchasecrate = pc.createScript('purchasecrate');
Purchasecrate.attributes.add('cost',{type:"number"});
Purchasecrate.attributes.add('crateid',{type:"string"});
Purchasecrate.attributes.add('actiontext',{type:"entity"});
Purchasecrate.purchaseable=false;
// initialize code called once per entity
Purchasecrate.prototype.initialize = function() {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
Purchasecrate.prototype.onCollisionStart=function(result){
if(result.other.tags.has('player')){
this.actiontext.element.text=`Press [G] To Confirm Purchase Of ${this.cost} RT`;
Purchasecrate.purchaseable=true;
setTimeout(function(){
this.actiontext.element.text=``;
Purchasecrate.purchaseable=false;
}.bind(this),5000);
}
};
// update code called every frame
Purchasecrate.prototype.update = function(dt) {
if(Purchasecrate.purchaseable){
if(this.app.keyboard.wasPressed(pc.KEY_G)){
Network.prototype.buycrate({"playfabid":localStorage.playerid,"skincrate":this.crateid,"cratecost":this.cost});
console.log({"playfabid":localStorage.playerid,"skincrate":this.crateid,"cratecost":this.cost});
this.actiontext.element.text=``;
Purchasecrate.purchaseable=false;
}
}
};
The server code is correct and the network code is correct. Tested them. The client code is having the problem