我正在使用kongregate获取用户用户名
var username = kongregate.services.getUsername()
现在使用这个用户名,我想让玩家将他们的钱发送给其他用户的方式,但我不太确定我的整个游戏是如何用javascript编写的,在这一点上,我绝对没有办法切换到PHP和使用ajax,所以这可以用javascript完成吗,例如,这里有一些相关的代码
var playerName = document.getElementById("username").value;
var moneyAmt = document.getElementById("money").value;
var submitBtn = document.getElementById("sendMoney");
submitBtn.onclick = function(){
if(Game.Player.money >= moneyAmt){
Game.Player.money -= moneyAmt;
//Send Money along with playerName
}
}
//User recieving
if(kongregate.services.getUsername() == playerName){
Game.Player.money += moneyAmt;
}//Form for sending
<form>
<input type="text" id="username" placeholder="Enter players username"><br>
<input type="number" id="money" placeholder="Enter amount to send">
<input type="submit" id="sendMoney" value="Send">
</form>我知道这有点困难,尤其是使用javascript,但我别无选择。
发布于 2017-05-04 22:53:42
我不认为你可以通过Kongregate做到这一点。我看到这种情况发生的唯一方式是,如果你有自己的服务器/数据库来保存请求,直到它们被收集。
https://stackoverflow.com/questions/38492944
复制相似问题