わかりました...開発中のゲームがあり、スコープの問題が発生していると思います...
それは、プレーヤーがプレイしたいカードをクリックすることによって起動される私の js ファイルで始まります。
It starts in my js file:
function playCard(playerId, card){
$.post("support_files/Blades_functions.php", {
method:'playCardFromHand',
playerID:playerId,
cardName:card
},function(data){
var attr = new Array();
attr = data.split("/");
alert(data);
$("#playerAttackPower").html(attr[0]);
$("#playerDefensePower").html(attr[1]);
$("#playerHealth").html(attr[2]);
$("#playerAttackMod").html(attr[3]);
$("#playerChargeCounters").html(attr[4]);
$("#playerSpecialAttackCounters").html(attr[5]);
});
}
Then into my php file
function playCardFromHand(){
$weapons = new WeaponCards(); // this is basically a class with variables(card objects) (my answer to php not having enums really)
$player = $theGame->gamePlayers[$_POST['playerID']]; // this is the variable ($theGame) that I declare in my main php file with all the markup on it. I'm including my functions file in my main file so the variable should be visible... I've tried using "global" keyword as well and that didn't do anything different...
$cardName = $_POST['cardName'];
$card = $weapons->$cardName;
$card->applyCard($player);
echo $player->getAttack()."/".$player->getDefense()."/".$player->getLife()."/".$player->getAttackMultiplier()."/".$player->getChargeCounters()."/".$player->getSpecAttackCounters();
}
私の問題は、 $player 変数が null であるため、何も表示されないことです。基本的に、js 関数のコールバックでわかるように、文字列を解析して、メインの php ページでプレーヤーの統計を更新しているだけです。これはスコープの問題ですか?関数ファイルでアクセス/変更できるように、オブジェクト自体である $theGame 変数を PHP に保持させる方法はありますか?
どんなアイデアでも最も役に立ちます... 私が言ったように、global キーワードを使用してみました... $theGame オブジェクトの変数をパブリックにして、それらをプライベートにして、ゲッターとセッターを使用してみました... 私は実際には別の問題があり、関数を一般的にオブジェクトで動作させることができないようです。変数をパブリックにして、ゲッターとセッターを使用する代わりに変数に直接アクセスしているだけです。ともかく。助けてください!私はとてもイライラしています!!! 笑
ありがとう、ジョン