PDA

View Full Version : loading "$var_name" rather than its value.


JonEllis
11-04-2006, 06:36 PM
Hello,

I'm currently writing a 2 player game of battleships, the back-end in PHP, and the gui in flash.

I am using the LoadVars method (.sendAndLoad, using one object to send, and another to load)

this method works with no problem in one case, but in another, i seem to be returning variable names from the PHP code rather than the value of the actual variable.



btnOK.onRelease = function(){
// variables (csv string)
sendVars.shipAircraftCarrier = aircraftCarrierList;
sendVars.shipBattleship = battleshipList;
sendVars.shipFrigate = frigateList;
sendVars.shipSub = subList;
sendVars.shipSpy = spyList;

sendVars.sendAndLoad("php-flash_comms.php", getVars, "POST");
} // end btnOK.onRelease function

getVars.onLoad = function(success:Boolean){
trace(this.numbers);
if (this.accepted == "false"){
trace("false");
gotoAndPlay(4);
}else{
trace("true");
}
} // end getVars.onLoad function


ok, now to the PHP:


function check_positions(){
$aircraft = explode(",", $_POST["aircraftCarrier"]);
$battleship = explode(",", $_POST["battleship"]);
$frigate = explode(",", $_POST["frigate"]);
$sub = explode(",", $_POST["sub"]);
$spy = explode(",", $_POST["spy"]);

$accepted = true;
if(count($aircraft) != 6) $accepted = false;
if(count($battleship) != 5) $accepted = false;
if(count($frigate) != 4) $accepted = false;
if(count($sub) != 4) $accepted = false;
if(count($spy) != 3) $accepted = false;

if ($accepted) echo "&accepted=true&<br>";
else print "&accepted=false&<br>";

$numbers = count($aircraft).":".count($battleship).":".count($frigate).":".count($sub).":".count($spy);
print "&numbers=$".numbers."&<br>";
} // end check_positions function


the PHP returns:

&accepted=true&
&numbers=6:5:4:4:3&

however, flash reads:
accepted = true => great
numbers = ".$numbers." (including the quotation marks) => not so good.

Does anyone have any suggestions as to what i can do to fix this?

Ps sorry for the huuuge post.

peptobismol
11-05-2006, 11:22 PM
try changing your delimiter from ':' to another character .. maybe '|'

JonEllis
11-07-2006, 08:13 PM
Have tried your suggestion without success. :(

i have never heard of an error like this before.

does anyone else have any sugestions, or had this error before?

peptobismol
11-08-2006, 02:23 AM
you have
print "&numbers=$".numbers."&<br>";

try
print "&numbers=".$numbers."&<br>";

get rid of <br> from your code too.
you don't need it

JonEllis
11-08-2006, 04:36 PM
that didnt fix it (i must have changed it shortly after posting)

i fixed the problem my changing my Flash code to an absolute path to the php file rather than a relative one.

works fine now.

Thanks for the suggestions