Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Nymall

Member Since 22 Feb 2013
Offline Last Active Today, 12:11 AM
-----

Topics I've Started

A few painful questions about Databases

Today, 12:08 AM

Using: MySQL, PHP, JQuerry

 

Well, I have a few questions about database organization and I'm hoping you guys can help me out. I'm not new to programming - I'm mostly self-taught, and I've been doing it on and off since I was in my early teens. However, I've been finding information about organizing things very hard to track down...

 

I guess I should give an example. Right now I'm working on the framework for a web game for my wife. It's real simple, image mapping, point and click stuff, but I'm having some difficulty figuring out how to plan ahead just in case this game is live in 5~10 years(as unlikely as it is). At the moment the inventory is split into seven different tables, with a total of 600 columns combined for all of them.The farther I'm getting into this project, the more I'm wondering if each character should have their own table, and rows for each of the items they have, or if I should proceed as I have done.

 

So, in summary - ​Is it more efficient to have a table with 600+ columns and 100,000+ rows, or 100,000+ tables with a average of 100 rows each? How much weight does a empty entry add to the database? Is there a easy way to future proof the minimalist number of table concept without it eventually getting completely unmanageable?

 

Now for problem number 2: I've got a bit of explaining first... Right now, when a user clicks a link, the game pulls the location the player is currently in and the number associated with the hotspot they clicked, and checks it against a table of valid destinations for that room. If there is a valid destination, it's returned to the script and the game makes another check to the database for the information for that room, which is then brought back to the script. From there, it enters a "flag section" which filters if the player can continue.

 

1)If it returns true, the scene draws as normal.

 

2)If it returns false, it checks the database for the new possible destination, and then renders that location as if it was the location initially returned.

 

The problem - This can at times mean that the database can be queried a total of five times for a simple move action.

 

Notes: There are some locations that are designed to have multiple tests running at the same time, by order, so it would add a lot of bulk to add the test information right into the scene table.

 

Is there any general advice you can give to shorten up this insanse number of database calls? Is there a faster way to script this in MySQL? Would the performance loss be fine for a small/medium sized game?

 

Thank you for your help!


Javascript/Jquery strange errors, trying to get %22 and %7B?

22 February 2013 - 11:25 AM

UPDATE: I've discovered the problem, and now I feel foolish. I accidentally removed the JSON parsing, and for one reason or another tried to re-implement it by accessing it as a array. It's one of those mistakes that is done at 1am on a saturday, and never rediscovered. Thank you for responding, though!
 
Hey guys,
 
I've been working on a project for my wife in my free time, a type of adventure game in PHP. She's been doing the writing, and as I've been a dabbling programmer for many years I've taken up the mantle of developer.
 
The game is written in PHP, and it's using Javascript and Jquery to dynamically get data from the PHP script through JSON and enact changes on the page dynamically. For quite a while, development has been going good and it was almost playable for a short period of time... then, this happened:

 

GET http://127.0.0.1/New%20Pointless/%7B 404 (Not Found) jquery-1.9.1.js:2358
GET http://127.0.0.1/New%20Pointless/%22 403 (Forbidden) jquery-1.9.1.js:2358


 

The data from the php script is JSON, and I've confirmed that it's being sent properly, and I have error suppresion on that side so it's not throwing a monkey wrench in the works... I'm really not sure why this is happening. I've done SEVERAL hours of investigation on these errors, and I haven't the foggiest clue why they exist.
 
I've gone to the area quoted by the chrome console, and it appears to be in the .attr function of jquery. The thing is, there are no get commands called by the javascript for either %7B or %22. I took a guess that they might be rogue characters, but I can't find anywhere in the javascript where " and { are sent via get.
 
Here's the javascript code as it stands:
 
<script language="javascript">
function onstart(){
    loadbyref('S00010000');
    $('#text').hide();
    $('#textfill').hide();
}
function loadbyref(LocByRef) {
    $.post('game.php',                  //the script to call to get data          
      {
        atr:LocByRef
      },
      function(data)          //on recieve of reply
      {
        var background = data[0];
        var convo = data[1];
        var convotext = data[2];
        var people = data[3];
        var buttonone = data[4];
        var buttontwo = data[5];
        var buttonthree = data[6];
        var islocation = data[7];
        var personlink = data[8];
        var buttonoutput = "";
        $('#gamescreen').attr("src", background);
        if(convo!=true){
            $('#text').hide();
            $('#textfill').hide();
            if(people!="nil"){
                $('#people').show();
                $('#people').attr("src", people);
                $('#people').attr("onClick", personlink);
            }else{
                $('#people').hide();
            }
        }else{
            $('#people').show();
            $('#people').attr("src", people);
            $('#text').show();
            $('#textfill').show();
            $('#textplace').html(convotext);
            if(buttonone!='nil'){
                buttonoutput = buttonone;
            }
            if(buttontwo!='nil'){
                buttonoutput += buttontwo;
            }
            if(buttonthree!='nil'){
                buttonoutput += buttonthree;
            }
            $('#buttonfill').html(buttonoutput);
        }
      } 
    );
}
 

 

 
 
And here is the example of the response from the php script:
 
 

 

{"0":"mydorm.png","1":false,"2":"nil","3":"nil","8":"nil","4":"nil","5":"nil","6":"nil","7":true}

 

 

 
Is there something obvious I'm missing? Any help would be appreciated!

PARTNERS