Forum BigDB Saved scores fine, but calling on them I receive this error

Discussion and help relating to Player.IO's database solution, BigDB.

Saved scores fine, but calling on them I receive this error

Postby vinceas3 » July 7th, 2011, 5:54 pm

Error: The index 'ByDate' value no. 1 (index 0) must be of type: Date

Code:
Code: Select all
//Get today's 10 best scores
_client.bigDB.loadRange("Scores", "ByDate", [new Date().setHours(0,0,0,0)],
   null, null, 10,
   function(scores:Array):void{
      //Display the scores array...
   }
);


I can load scores by username, but unfortunately not with loadRange() and using those values.

Here is a screenshot of how my BigDB looks:
http://i55.tinypic.com/m9vpdk.jpg

Here is a screenshot of my score, saved in the BigDB:
http://i56.tinypic.com/14x1bpf.jpg
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » July 9th, 2011, 7:17 pm

Have to bump this one just once. Thanks!
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby Oliver » July 11th, 2011, 1:39 pm

Quick Question: What happens if you try to do the lookup from serverside code?
User avatar
Oliver
.IO
 
Posts: 1136
Joined: January 12th, 2010, 8:29 am

Re: Saved scores fine, but calling on them I receive this error

Postby Henrik » July 14th, 2011, 5:25 pm

I'm guessing the AS3 client sends that as a DateTime instead of as a Date. Easiest fix would be to change the index type to DateTime instead of Date.
User avatar
Henrik
.IO
 
Posts: 570
Joined: January 4th, 2010, 1:53 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » July 14th, 2011, 5:38 pm

Great thanks I will try that out.
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » July 14th, 2011, 9:40 pm

Same with server. And I even changed index to DateTime:


From the PlayerIO Development Window:

>Error: Webservice returned unhandled error: InvalidIndexValue
The index 'ByDate' value no. 1 (index 0) must be of type: DateTime


Using this code from server:
Code: Select all
  PlayerIO.BigDB.LoadRange("Scores", "ByDate",
                    new object[]{""}, new DateTime(2011, 7, 1),
                    new DateTime(2011, 7, 30), 100,
                            delegate(DatabaseObject[] result) {
                                //...
                                Console.WriteLine(result);
                            }
                        );
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby Henrik » July 21st, 2011, 7:46 pm

Well, that piece of server code looks wrong, if your index only contains a single property, then the indexPath argument has to be an empty array. Try this:

Code: Select all
PlayerIO.BigDB.LoadRange("Scores", "ByDate",
    new object[0], new DateTime(2011, 7, 1),
    new DateTime(2011, 7, 30), 100,
    delegate(DatabaseObject[] result) {
        //...
        Console.WriteLine(result);
    }
);
User avatar
Henrik
.IO
 
Posts: 570
Joined: January 4th, 2010, 1:53 pm

Re: Saved scores fine, but calling on them I receive this error

Postby Henrik » July 21st, 2011, 8:28 pm

Aha! Finally we figured out the problem. :-)

In AS3, the code new Date() returns a Date object. But the setHours() method doesn't return a Date, it modifies the object, but returns a Number. And since Numbers aren't Dates, you get that error from BigDB, as you should. This code should work:
Code: Select all
var date = new Date();
date.setHours(0,0,0,0);
_client.bigDB.loadRange("Scores", "ByDate", [date],
   null, null, 10,
   function(scores:Array):void{
      //Display the scores array...
   }
);

But if you change back the index property to Date instead of DateTime, it will ignore the time component of the date, and in that case you cn do this to get today's scores:

Code: Select all
_client.bigDB.loadRange("Scores", "ByDate", [new Date()],
   null, null, 10,
   function(scores:Array):void{
      //Display the scores array...
   }
);

That should hopefully work just as well. Just let us know if you have any further problems. :-)
User avatar
Henrik
.IO
 
Posts: 570
Joined: January 4th, 2010, 1:53 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » July 21st, 2011, 8:31 pm

Awesome I will look at this momentarily. Thanks for the help :!: :D
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » July 21st, 2011, 9:50 pm

Awesome. Works beautifully! Now I have scores :) Thanks for the help!
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » November 14th, 2011, 1:40 am

Fixed. When calling dates in a load range the stop value (the last dates) should be first, and the start value should be second, rather than what is in the documentation.

Here is how you do a load range from the client:
Code: Select all
client.bigDB.loadRange("Scores", "ByDate", null, new Date(2011, 10, 14), new Date(2011, 10, 11), 10,
function(scores:Array):void{


This will properly load all scores from date November 11, 2011 to November 14, 2011. Notice I have to have the end date first, and the start date second. Documentation shows the opposite. No results were popping up so I was troubleshooting other stuff. Took me hours to get past this :lol:
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm

Re: Saved scores fine, but calling on them I receive this error

Postby Henrik » November 16th, 2011, 3:49 pm

vinceas3 wrote:When calling dates in a load range the stop value (the last dates) should be first, and the start value should be second, rather than what is in the documentation.


That depends on the order of the index. If it's in ascending order (oldest first) then you should put the start value first and the stop value last. But if it's descending order, it should be the other way around.

I'll look into improving the error messages and the documentation so that this is made clearer.
User avatar
Henrik
.IO
 
Posts: 570
Joined: January 4th, 2010, 1:53 pm

Re: Saved scores fine, but calling on them I receive this error

Postby vinceas3 » November 16th, 2011, 4:04 pm

Thanks Henrik ;)
vinceas3
 
Posts: 77
Joined: January 16th, 2011, 11:25 pm


Return to BigDB