Use this perhaps?
Moved to jQuery forum. This is really not a PHP question.
22 Replies - 17588 Views - Last Post: 06 October 2010 - 10:34 AM
#17
Re: PHP text based game input method help
Posted 03 October 2010 - 04:57 PM
Thanks for moving the thread.
So I have made the form print the input into the div but I can't seem to figure out how to use the append() feature to make the input appear after any other text already in the div box?
Here is my message.php file that the input is sent to I think this is where I need to put append(), is that right and if so how do I use append()?
Thanks,
Bugsy
So I have made the form print the input into the div but I can't seem to figure out how to use the append() feature to make the input appear after any other text already in the div box?
Here is my message.php file that the input is sent to I think this is where I need to put append(), is that right and if so how do I use append()?
<?php
if(isset($_GET['message']))
{
$received = $_GET['message'];
echo "$received";
}
?>
Thanks,
Bugsy
#18
Re: PHP text based game input method help
Posted 04 October 2010 - 12:49 PM
So I've tried a few things but still can't get my user input to not replace what was previously inputed!
Any help would be great!
Thanks.
Bugsy
Any help would be great!
Thanks.
Bugsy
#19
Re: PHP text based game input method help
Posted 04 October 2010 - 06:24 PM
Hi,
That is not where you would choose to append rather than replace, what you are showing there is what is being returned from the server.
How are you placing what is returned from the server into your div? Are you using jQuery or straight Javascript? Could we see the code you are using?
That is not where you would choose to append rather than replace, what you are showing there is what is being returned from the server.
How are you placing what is returned from the server into your div? Are you using jQuery or straight Javascript? Could we see the code you are using?
#20
Re: PHP text based game input method help
Posted 05 October 2010 - 06:24 AM
Ok so here is my code for the user input:
I got it from another site, but on't fully understand it after the document.myform.message.value='' bit, I can't figure out what the code does here.
Here is my message.php form also:
So at the moment this code will accept, process and display the users input, but like most text games I want the input to be a response to text already on the screen. and the problem with this code is it removes anything else in the div box.
Any suggestions on fixing this code or ideas on a better way to do it would be great.
Thanks,
Bugsu
<html>
<head>
<link rel="stylesheet" type="text/css" href="Game_window.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function getMessageResponse(str)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObj0ect("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('response').innerHTML=xmlHttp.responseText;
document.myform.message.value = '';
}
}
var url="message.php";
url=url+"?message="+str;
url=url+"&sid="+Math.random();
xmlHttp.append("GET",url,true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form method="POST" name="myform" id="myform">
<input type="text" name="message" size="97" class="Player_Input" />
<input type="button" value="Submit" class="Submit_Input" onclick="getMessageResponse(document.myform.message.value);">
</form>
<div rows="20" cols="40" id="response" name="response" class="Game_Area">
</div>
</body>
</html>
I got it from another site, but on't fully understand it after the document.myform.message.value='' bit, I can't figure out what the code does here.
Here is my message.php form also:
<?php
if(isset($_GET['message']))
{
$received = $_GET['message'];
echo "$received";
}
?>
So at the moment this code will accept, process and display the users input, but like most text games I want the input to be a response to text already on the screen. and the problem with this code is it removes anything else in the div box.
Any suggestions on fixing this code or ideas on a better way to do it would be great.
Thanks,
Bugsu
#21
Re: PHP text based game input method help
Posted 05 October 2010 - 05:14 PM
You could put each response in a paragraph and then append that to your response div. Something like :
You most likely want to start working out database requirements next so that your post to the server actually does something. Also this really isn't the right forum for this since your not using jQuery for this.
if(xmlHttp.readyState==4)
{
var para = document.createElement("p");
para.innerHTML = xmlHttp.responseText;
document.myform.message.value = '';
document.getElementById('response').appendChild(para);
}
You most likely want to start working out database requirements next so that your post to the server actually does something. Also this really isn't the right forum for this since your not using jQuery for this.
#22
Re: PHP text based game input method help
Posted 06 October 2010 - 08:26 AM
Thanks for that Its working great with that addition.
Now I'm just starting to construct the login part. I'm not sure on how to load in each part of the game, should i have a different file for each room/area or just one long page with all rooms on it?
Thanks,
Bugsy
Now I'm just starting to construct the login part. I'm not sure on how to load in each part of the game, should i have a different file for each room/area or just one long page with all rooms on it?
Thanks,
Bugsy
#23
Re: PHP text based game input method help
Posted 06 October 2010 - 10:34 AM
Ok so I've got my code to append to what is in the box already thanks to Jstall.
Now I'm trying to load something if the users input is a specific string, eventually for the login screen.
For example:
Are you new?
Then the user inputs yes or no and it loads the next bit of text depending on the answer.
I have tried this so far can anyone suggest why it just prints the last else "Not a valid input"response part?
Now I'm trying to load something if the users input is a specific string, eventually for the login screen.
For example:
Are you new?
Then the user inputs yes or no and it loads the next bit of text depending on the answer.
I have tried this so far can anyone suggest why it just prints the last else "Not a valid input"response part?
<html>
<head>
<link rel="stylesheet" type="text/css" href="Game_window.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function getMessageResponse(str)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObj0ect("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var para = document.createElement("p");
para.innerHTML = xmlHttp.responseText;
document.myform.message.value = '';
document.getElementById('response').appendChild(para);
}
}
var url="message.php";
url=url+"?message="+str;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form method="POST" name="myform" id="myform">
<input type="text" name="message" size="97" class="Player_Input" />
<input type="button" value="Submit" class="Submit_Input" onclick="getMessageResponse(document.myform.message.value);">
</form>
<div rows="20" cols="40" id="response" name="response" class="Game_Area">
Welcome to the World of Myth are!!<br /><br />
Are you an existing citizen of Myth??<br />
<?php
if ($para=="yes") {
echo "Welcome back friend!";
}
else if ($para=="no"){
echo "Well welcome to Myth friend!";
}
else (£para==""){
echo "Not a valid input!";
}
?>
</div>
</body>
</html>
Thanks,
Bugsy

New Topic/Question
Reply



MultiQuote



|