Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question How to save score from my javascript based mini game?

    Hi to every one.
    I'w created a mini javascript game for my site where you click on red button as fastest as you can for 10 seonds to achieve as best as you can click numbers per second. And the end score is a variable which I send to a function which reads the array that contains ten best scores and write your score in same array if it's among 10 best.

    Now I want to make somehow to save that array on server so I could read it on page load to show a high score list, but I'm having trouble to write that array in any kind of data on server that I could read it again from same data.

    I would be very grateful if someone can help me!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,983
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    To record the scores on a server you need to use server-side scripting, not client-side Javascript which cannot communicate with the server or access a database.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Yes I know that but I'm a novice with server side programing and I would appreciate a lot if some could guide me a little in right direction!

    I'w found some PHP solution to send javascript array to PHP, and I tried as instruction said but have no success!

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,166
    Thanks
    23
    Thanked 601 Times in 600 Posts
    What you need to use is ajax. It's javascript code that communicates with the server. Just google ajax and read up on it and copy the code. BTW you should use POST method.

    Ajax will pass variable to a server side php program and run it. You can use the php to store the high score in a database or to make it simple, in a text file.

    But when you start just make a php script that says echo 'Made it!'; So you can concentrate on making the link.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •