;

PDA

Click to See Complete Forum and Search --> : new music game


JDE
06-29-2002, 12:05 PM
Hi, everyone. I've recently put up a new game I've been working on for quite a while off and on. It is a 2-note interval matching game using a keyboard. The only thing I would still like to add to it is a way of keeping track of players'scores, with a top ten high score list. Anyone have experience coding something like that?

Here's the link: www.pedaplus.com/2_intervals.html (http://www.pedaplus.com/2_intervals.html). I'd be glad to hear any feedback. (made entirely with 3dfa)

Jon

kusco
06-29-2002, 12:22 PM
Hello Jon,

I've been playing the game for about 10 minutes and love it.

However, I think that I've found a little bug in it. When the two notes are played for you to hear, you can press the key of the second note without an error. eg. if notes c and d are played then I can press d first without it being a problem but the second note will always catch me out.

It may not be a biggy and it's possible that it's intended this way.

Aside from that, it's great for learning the notes by ear and put a key to the note.

Welldone!!

JDE
06-29-2002, 01:29 PM
I think you mean that the error is not indicated until the second note is played back by the user? I thought about adding the "first-note" error, and just didn't bother adding the code. The way I coded it, the first two note values heard are stored in an array, and the two note values played back by the user are stored in another array, and the two are compared after the second note is played by the user. I guess it would be pretty simple to compare the first notes in each array after the first note is played back by the user. I'll work at adding that. Thanks for the suggestion!

Jon

JDE
06-29-2002, 02:31 PM
OK. Now the first wrong note played will register as wrong, and send you to the next test interval.

http://www.pedaplus.com/flash/2_intervals.swf

blanius
06-29-2002, 06:00 PM
Originally posted by JDE
OK. Now the first wrong note played will register as wrong, and send you to the next test interval.

http://www.pedaplus.com/flash/2_intervals.swf

JDE If your server has MySql and PHP I will consider doing the server side for you.

JDE
06-29-2002, 11:56 PM
Yes, the webhost provides perl, MySqL, PHP, and several other things that I know very little about. I am interested in learning more about PHP and MySQL as I get time. As mentioned before, I've got a book on Perl/CGI, and I'm working through the basics on that - though I haven't had the time or nerve to write any perl scripts (even very simple ones) yet. Maybe this would be a good project to learn some things - and if you're willing to help, thanks!

blanius
06-30-2002, 04:47 PM
Originally posted by JDE
Yes, the webhost provides perl, MySqL, PHP, and several other things that I know very little about. I am interested in learning more about PHP and MySQL as I get time. As mentioned before, I've got a book on Perl/CGI, and I'm working through the basics on that - though I haven't had the time or nerve to write any perl scripts (even very simple ones) yet. Maybe this would be a good project to learn some things - and if you're willing to help, thanks!

Ok lets see first you need a database. If you don't already have one get it set up by you host.

They will give you some way to interact with this database commonly it's through MySqlAdmin wich makes building the table we'll need very easy

You can just paste the following into the database as a query to creat a table called MusicGame

SQL-query :
CREATE TABLE MusicGame (Mid INT not null AUTO_INCREMENT, date VARCHAR (10) not null , name TINYTEXT not null , score BIGINT not null , PRIMARY KEY (Mid)) comment = 'Keep score for music game'


This will make a table like this
Field Type Attributes Null Default Extra Action

Mid date name score

^ Mid is the Record Id
^ date is obvious
^name of the person
^the score.

I think that's all we'll need.

I think we should populate it with default data to start. Like
1 00.00.2002 Nobody 0000
2 00.00.2002 Nobody 0000
till we have 10 (assume we want only top 10)

etc.


Now we have a database table of high scores by nobody with scores of 0

Next we tackle the PHP code to get this data out and to add new high scores. We'll leave the code for deciding if there is a high score to the game code. So we need a php script that simply gets the data and formats it so that we can use it in 3dfa and also will update a slot with new data.

dkerr
06-30-2002, 09:06 PM
Hi there - thanks for the post. Love the game. Are you using it exclusively for teaching ? We'd love to display this as a demonstration of 3DFA's capabilities in different areas - do you have any objection to us linking to your site, or even better - would you consider allowing us to use the .movie file ? We understand if you cannot do the latter.

Great work - best of luck with the program. In regard your question on high scores, etc. - the previous post are the best suggestions we could offer as well. The 'insanelander' demo contains code that uses a shared 'highscores' server. You may want to examine how that works, but the real 'guts' of the technique is in the database and ASP/PHP on the server-side. Let us know if we can be of any more assistance.

Regards

blanius
06-30-2002, 11:55 PM
Been working on this and so far I have the PHP nearly ready:
You can test this right now by the following:
http://deadyeti.com/blanius/musicgame.php?action=get will dispay the data the way it will appear to 3dfa. (I'll explain later)

You can also get an HTML response with
http://deadyeti.com/blanius/musicgame.php?action=html

I added this in case you want to be able to display the high scores in a web page.

The update seems to be ready as well, but I'm still testing iit. (I do this by hand entering the variables that 3dfa will need to send)

Here is the partial code:

<?php
// This is not a secure way to do this we should really take all the connection code and put it in
// another file and use Include filename to add it
$host="myhost.com";//This is your server name
$dbname="mydatabase";//The name of the database on your server
$username="myusername"; // The username for accessing the database
$password="mypassword"; // The password for accessing the database
$dbtable="MusicGame"; // The name of the table we are using
$notify="youremail"; // The email address you want notices sent to. (optional)



mysql_connect($host,$username,$password) OR die("Can't connect to database");
mysql_select_db("$dbname") or die("Unable to select database");
if ($action=="html")
{
echo ("<table border=\"1\">");
$result = mysql_db_query ("$dbname", "SELECT * FROM $dbtable ORDER by Mid");

while ($row = mysql_fetch_array ($result))
{
$name =$row["name"];
$date =$row[date];
$score =$row[score];


echo"<tr><td>$date</td> <td>$name</td><td>$score</td></tr>";
}
echo "</table>";

}

if ($action=="get")
{

$result = mysql_db_query ("$dbname", "SELECT * FROM $dbtable");

while ($row = mysql_fetch_array ($result))
{
$name =$name.$row["name"]."|";
$date =$date.$row["date"]."|";
$Mid =$Mid.$row["Mid"]."|";
$score =$score.$row["score"]."|";

}

echo ("&Mid=".$Mid."&dates=".$date."&names=".$name."&score=".$score);

}


if ($action=="add")
{
$day = date("d");
$month = date("m");
$year = date("Y");

$date = "$day"."."."$month"."."."$year";

$sql = "UPDATE $dbtable SET name='".$name."',date='".$date."',score='".$score."' WHERE Mid='".$Mid."'";
echo $sql;
$result = mysql_query($sql);

/*if ($notify){
mail($notify,"new high score added ",$name."\n".$score,"");
}*/ //commented out while testing.

}

?>



Next the hard part. The javascript side within your game.
You will have to call the php script at the start of the game and the variables loaded into an array. Then if the user playing gets higher than the lowest score, add them and shift all the scores.

Perhaps Kusco would like to dive in at this point.

blanius
07-01-2002, 12:05 AM
Oh by the way I will try to comment this code a bit more. Bear with me I'm just learning this myself.

JDE
07-01-2002, 01:53 AM
Whew! I'll try to catch up with what you're doing. I think I'll study your code along with some of those PHP tutorials you suggested earlier. Thanks for doing all that work.
BTW, I've added a 3-note version of the game: http://www.pedaplus.com/games.html
DKerr, as for the link, movie, etc. I'm flattered. No problem.
http://www.pedaplus.com/flash/interval_2notes.movie and http://www.pedaplus.com/flash/interval_3notes_bk.movie
[Edited by JDE on 07-01-2002 at 02:03 AM]

JDE
07-01-2002, 02:32 AM
If anyone's interested, here are the sounds (piano notes) used in this game:
http://www.pedaplus.com/flash/sounds.zip

Also, I'd be interested in advice about how to tighten the code (Ed?). Part of my problem with this game was trying to get the code for controlling the test/response sequence into one script. As it is now, the game depends heavily on each individual keyboard button for control, which makes maintaining or changing the javascript a little bit of a pain. I tried getting the note-test/response comparisons into one list of actions without much success. I also suspect I'm using more variables, etc. than necessary.

thanks

Jon E

JDE
07-04-2002, 01:01 AM
OK, Bret. Thanks for the help with the PHP/MySQL so far. I was able to figure out how to get the database set up on my server, and also used your script, putting the connect info into a separate file and using the include() function. It works!! http://www.pedaplus.com/musicgame.php?action=html

Also, I've been tweaking things a little. The 2-note interval game has a "choose level" feature now, and I've added a 3-note version.

http://www.pedaplus.com/flash/2_intervals.html
http://www.pedaplus.com/flash/3_intervals.html

[Edited by JDE on 07-04-2002 at 01:06 AM]

phillong
01-14-2003, 01:42 PM
Originally posted by blanius
Been working on this and so far I have the PHP nearly ready:
You can test this right now by the following:
http://deadyeti.com/blanius/musicgame.php?action=get will dispay the data the way it will appear to 3dfa. (I'll explain later)

You can also get an HTML response with
http://deadyeti.com/blanius/musicgame.php?action=html

I added this in case you want to be able to display the high scores in a web page.

The update seems to be ready as well, but I'm still testing iit. (I do this by hand entering the variables that 3dfa will need to send)

Here is the partial code:
[code]
<?php
// This is not a secure way to do this we should really take all the connection code and put it in
// another file and use Include filename to add it
$host="myhost.com";//This is your server name
$dbname="mydatabase";//The name of the database on your server
$username="myusername"; // The username for accessing the database
$password="mypassword"; // The password for accessing the database
$dbtable="MusicGame"; // The name of the table we are using
$notify="youremail"; // The email address you want notices sent to. (optional)



mysql_connect($host,$username,$password) OR die("Can't connect to database");
mysql_select_db("$dbname") or die("Unable to select database");
if ($action=="html")

Hi Bret,

I copied all your code here and tried to run it and get the message below:

Parse error: parse error in /home/carbonst/public_html/yahtzee.php on line 5

Line 5 on my script is

if ($action=="html")

Any ideas why I get this message? It is driving me nuts, all looks fine with the code.

If I can get it to run, I have an idea how to adapt it to what I want the code to do for me and will post the change if I can get it to work. I only started with PHP but have gotten some ideas from doing some reading and asking questions.

Thanks
Phil

blanius
01-14-2003, 02:45 PM
Originally posted by phillong
Hi Bret,

I copied all your code here and tried to run it and get the message below:

Parse error: parse error in /home/carbonst/public_html/yahtzee.php on line 5

Line 5 on my script is

if ($action=="html")

Any ideas why I get this message? It is driving me nuts, all looks fine with the code.

If I can get it to run, I have an idea how to adapt it to what I want the code to do for me and will post the change if I can get it to work. I only started with PHP but have gotten some ideas from doing some reading and asking questions.

Thanks
Phil

Hard to tell from that one line, I've found it's usually a ; or " or a { that is missing. Check for those. You can send me the file And I'll look at it

phillong
01-14-2003, 07:31 PM
Originally posted by blanius
Hard to tell from that one line, I've found it's usually a ; or " or a { that is missing. Check for those. You can send me the file And I'll look at it

Hi Bret,

I copied and pasted again and this time it worked.

I have been racking my brain for over a week and playing with code and asking questions on other forums and I finally got the code to what I was looking for.

I was looking for setting the variables for the data right in the php file. This meant all I had to do in 3dfa was to link the edit boxes to the right variable. I then did not need any code in 3dfa to handle the data. I also read somewhere that some browsers/plugins have trouble with reading in the first element of a url-encoded string. So I wanted dummy data first, so I placed "script_done=no" first, and then my data. Then I wanted a way to check in 3dfa if data was sent and finished. So I put "script_done=yes" at the end of the string. Now I can check if script_done=yes then do something.

The data that is output can be checked here if interested:
http://www.carbonst.com/yahtzee.php?action=get

The code that does this, if anybody can use it, is:

if ($action=="get")
{

print 'script_done=no&';

$scores_to_return = 10;
$result = mysql_select_db("$dbname");
$result = mysql_query ("SELECT * FROM $dbTable");

$output = "";
$i = 0;
while(($row = mysql_fetch_array ($result)) && $i < $scores_to_return) {
$name =$row["names"];
$Mid =$row["Mid"];
$score =$row["scores"];
if($output != "") {
$output .= "&";
}
$output .= "name_" .++$i. "=" .rawurlencode($name);
$output .= "&score_" .$i. "=" .rawurlencode($score);
}

print $output;
print '&script_done=yes';

}


I did have help with the code and the ideas so it is not all mine so a Thanks to all that did help.

Phil