Search Unity

[Solved]I Need Help Retrieving Data from Mysql using PHP

Discussion in 'Multiplayer' started by Maroy, Jul 26, 2010.

  1. Maroy

    Maroy

    Joined:
    Dec 20, 2009
    Posts:
    35
    Hello,
    I'm making a small MMORPG (I know you're not supposed to try making an MMO by yourself. Considering only 5 people will ever play it, I think I can pull it off) and I had a question about retrieving data from a mysql database. I'm using a slightly modified and simplified version of the scripts from here. I understand how the Server Side Highscores tut retrieves scores, but it only retrieves it as a formatted string. I'm trying to use a similar script to retrieve ints such as the player's x, y, and z coordinates and level number. My questions are: what would I need to do to convert the echo to an int, and can I retrieve multiple usable ints using a single WWW call?

    Any help would be greatly appreciated, but if you can't help, thanks for stopping by to read the thread anyway.
     
  2. Maroy

    Maroy

    Joined:
    Dec 20, 2009
    Posts:
    35
    Nevermind, I figured out the first question. Still, there's gotta be a better way then calling WWW 15 times a second.
     
  3. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    I have no knowledge in MySQL (apologizes), so I can't really answer. About "calling WWW 15 times a second", what is disturbing ? You could do some if statements, and little trick to reduce the rate, don't you ?
     
  4. Maroy

    Maroy

    Joined:
    Dec 20, 2009
    Posts:
    35
    Calling WWW so many times would cause quite a bit of strain on my server, since I'm running it on my development machine. It occurred to me to only sync exp and level when the player gets exp, but I'm still setting all the transform properties every second (to ensure players can't just quit if they misstep, because I'm using a webplayer and last time I checked OnApplicationClose or whatever only applies to Standalones.)
     
  5. sztacheta28

    sztacheta28

    Joined:
    Jan 11, 2010
    Posts:
    12
    I think that you can use WWW to get data from MySQL in the form: "score1,score2,score3" and result assign to variable.

    After it you can use split function:
    Code (csharp):
    1. var combined = "score1,score2,score3";
    2. var words = combined.Split(","[0]);
    If you need get more types of data(e.g. score and nick) you can use data in form:
    "score1,score2,score3;nick1,nick2,nick3"


    Sry for my english :D
     
  6. Maroy

    Maroy

    Joined:
    Dec 20, 2009
    Posts:
    35
    Your English is fine :wink: I never noticed the Split function! That's perfect. If only I hadn't just spent 4 hours coding it the other way... :eek: but anyway, thank you very much!
     
unityunity