These keys are all stored in their own DatabaseObjects in a table ("WorldWords").
I want to be able to take the keys, process their values and store the final result in a separate table ("Worlds") under the composite heading ("Aries Learners Factory Human") This way worlds can be dynamically created with new keys as players explore them, and destroyed if they haven't been accessed for a while (Anyone who has played .Hack may be somewhat familiar with the concept here.)
I'm having a couple of problems implementing this.
First of all, trying to call BigDB.Load() from the serverside gives me a message about needing an object reference for non-static property. I try to create an object reference using "new BigDB()" but it is an abstract class, so that doesn't work.
Secondly, since I cannot create static fields on the serverside, and the BigDB.Load uses a delegate system (rather than just letting me do something like DatabaseObject word=BigDB.Load()) I'm having trouble 'anchoring' the system to do what it needs to do once all the word are loaded.
I currently am trying to use a class with four variables (one for each key) and then call a method that loads each word four times and use a separate delegate for each one to a different method for each variable (I might condense this to one method and just use a string and a switch case) This feels very wonky and I'm not sure that it's the best way to do it, and I can't even test it because I can't get BigDB.Load() to work since it is non-static.
Any suggestions are appreciated.
EDIT - just in case it's not clear I want to do this server-side because I don't want players hacking the client and creating whatever values suit their fancy - which they could do if I were to load the objects in the client, process the values, then save them.
EDIT 2 - Aha! I'm so clever! I just realised that I can get my WorldSeed class to extend BigDB (probably not the most 'clean' solution, but it works for now) (Edit 3 - actually apparently that doesn't work because now I have to implement stuff because its an abstract class it implements it rather than extends it D: )
Still looking for tips on how I can do this and similar tasks in a better way - this feels very round-about.
BTW the "Multiplayer Reference" examples for BigDB should probably be changed to reflect the fact that it's not a static class. None of the examples work as written for server-side;
https://gamesnet.yahoo.com/documentatio ... rary.bigdb
Final Edit;
Here's what I'm looking at so far. I have no way of testing it still because I can't call BigDB.Load in any way that I've tried. Please let me know if I'm on the right track or completely out to lunch.
- Code: Select all
class WorldSeedGenerator : BigDB
{
DatabaseObject signDO = null;
DatabaseObject adjDO = null;
DatabaseObject flexDO = null;
DatabaseObject nounDO = null;
void wordLoaded(string group, DatabaseObject val) {
if (val == null) {
//the BigDB.Load returned null. Catch here because we can't check for null later as null is the initialization for our categories.
//basically this means this word doesn't exist and we need to throw an error and abort this world generation.
}
switch (group)
{
case "Sign": signDO = val; break;
case "Adj": adjDO = val; break;
case "Flex": flexDO = val; break;
case "Noun": nounDO = val; break;
default: return; //invalid group.
}
if ((signDO !=null) && (adjDO !=null) && (flexDO != null) && (nounDO != null)){
//combine everything
Console.WriteLine("Seeds: "+
signDO.GetLong("seed",0)+", "+
adjDO.GetLong("seed",0)+", "+
flexDO.GetLong("seed",0)+", "+
nounDO.GetLong("seed",0));
}
}
public DatabaseObject constructWorldPhrase(string sign, string adj, string flex, string noun) {
Console.Write("constructWorldPhrase: "+sign+" "+adj+" "+flex+" "+noun);
Load("WorldWords", sign, delegate(DatabaseObject val) { this.wordLoaded("Sign", val); });
Load("WorldWords", adj, delegate(DatabaseObject val) { this.wordLoaded("Adj", val); });
Load("WorldWords", flex, delegate(DatabaseObject val) { this.wordLoaded("Flex", val); });
Load("WorldWords", noun, delegate(DatabaseObject val) { this.wordLoaded("Noun", val); });
return null;
}
}