Ok... so I have a game I'm developing and I'm running into a scope problem I think...
It starts in my js file fired by a click on the card the player wants to play:
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();
}
So my problem is that the $player variable is null so nothing is displayed. Basically, as you can see in the callback on the js function, I'm just parsing out the string and updating the player's stats on the main php page. So is this a scope thing? Is there some way to make PHP persist that $theGame variable, which is an object itself, so that I can access/modify it in my functions file?
Any ideas would be most helpful... I've tried using the global keyword, as I said... tried making the variables in the $theGame object public, tried making them private and using getters and setters... I've had a separate problem with that actually, can't seem to get my functions to work on my objects in general, have just been making my variables public and accessing them directly instead of using the getters and setters. Anyway. Please help! I'm so frustrated!!! lol
Thanks, Jon