Using a database in AGS

Started by GarageGothic, Wed 18/06/2003 09:21:23

Previous topic - Next topic

GarageGothic

Is it at all possible to create a database accessible from an AGS game? I'm thinking of something similar to the occult topics database on Sidney in GK3 (which, I think, was coded in some sort of html-like language).

I know that you could easily do it with different room files and creating the text as graphics, but is there any way to create an interface that retrieves data from, say, a text file? Or could you display messages (either global or room) in a certain fashion, as if on a computer screen, for just this one room? (I think the message limit could be a problem)?

Any suggestions?

Erica McLane

Yeah, it`s possible with a lot of scripting. You have to know very well the File* commands and the GUI* commands in order to do this. You will need more thing, also. I`m giving this to you just as an example.

GarageGothic

Sounds too complicated for me. I suppose I'll have to rethink it and limit myself to the few database entries that are actually necessary to proceed in the game. Maybe I'll just do it as a disguised dialog, where you choose search topics on a list instead of typing them.

undergroundling

Chrille implemented something similar in Pleurghburg with the computer database, although that only allowed you to search for things you needed to search for, but I'm sure you could implement more.  Perhaps he can tell you how he did it.  Just a suggestion.

Also, I think there was a similar thread on the Tech board the other day, maybe you should look over there.  Not sure if it was what you wanted, but I remember there being some similar problem.

- Bryan

Dorcan

I don't think it's that complicated :P

function FileReadRawLine(int handle, string text){
char c;
int I=0;
     StrCopy(text,"");
   
     while (FileIsEOF(handle) == 0 && I!=-1) {
         c = FileReadRawChar (handle);
          if (c==13) {
               FileReadRawChar(handle);
               I=-1;
          } else {
               StrSetCharAt(text,I,c);
               I++;
          }
     }
}


function test() {
string text;

     int handle = FileOpen ("test.txt", FILE_READ);
     while (FileIsEOF(handle) == 0) {
          FileReadRawLine(handle, text);
          Display("%s",text);
     }
 
}


With the FileReadRawLine function, you can read each line of a .txt file.
Take a look at how I made the test function

Just display each line of text with the RawPrint function in your room file.

GarageGothic

Yes, Vel posted a similar question on the tech board http://www.agsforums.com/yabb/index.php?board=2;action=display;threadid=6778 the day after I posted mine. Unfortunately nobody has replied to his post yet.

Dorcan, thanks for the script. I'll have a closer look at that when I get home. The only problem I see with this (in what I'm trying to do) would be that it doesn't allow for hyperlinks within the text. So maybe I'll end up with a dialog-like interface but use the FileReadRawLine command to avoid the message limits.

Yuri Patrick

I spent this morning rethinking a problem of mine. I found a much simpler method of databasing for a MMO than using some silly MMO server directly. ;)

How would one go about using a character file on the server end of the connection? Like the ancient MUD servers did. They had a list of files organized by character name. Within those files were stored variables such as password, name, level, room and (in my case) coordinates. How would I go about not just opening the person's character file, which I think I already figured out with your previous example, but also accessing a specific line of text for comparison or reading?

In other words, how would I have the AGS server read the file then pull up the "password" line and the value of the password for verification? Or how would I read just the player's coordinates and/or room number? I don't want to read the entire file. I need to read specific lines. Do I need to use line numbers or something?

Yuri Patrick

I've been reading through the scripting help file on working with files. If my understanding is correct, hopefully someone can verify this for me.

If I want to read the password string from a file, I would use the following code:

File *input = File.Open(charname+".data", eFileRead);
String buffer = input.ReadString("password");
input.Close();

And that should read the value for the password string into the buffer and then I can use buffer to verify the password, right?

Something along the vague lines of:

if clientinput=buffer
    then login complete

right?

I hope I'm getting this again. Been a loooong time since I did AGS Script.

GarageGothic

I don't think the File* functions are what you want. It'd require transferring the whole database to a temp file on the harddrive, and even with encryption that's a no-no in terms of security (as is transferring the password to the user's computer for comparison!).
To be honest I don't know much about servers, but what seems most logical would be to have the game call a sever-side script (submitting the login/password), and if the password is correct return a String from the server with the player's data, that you could then parse and apply to in-game variables.

Also, this thread is from 2003, but you knew that, right?

Yuri Patrick

I found this Post which has helped half of my problem. Writing stuff to a text file. Now, my next question is, I wrote all of the parameters for my database into the file (on the server side of course), and now I need to be able to pull them up singularly.

Like, I have the player's name, and need to pull only that string out, then I need to also pull up their title individually again, etc.

It's a little messy, but it's a database system that has been around for 30 years. It goes back to the ancient text games when they used nothing but the telnet protocol. ;) Good fallback, IMO, when nothing else appears to work or be feasible. :)

Dualnames

If I assume that you have a line per each data, and we consider the number of each line as an ID, there's a way.

Assume you write your database this way and the txt files looks like this:

Love
Hate

Love and Hate simply resemble random contents for my example.

With an integer that starts from 0-1 you can have an array where you can store the contents of a txt and load them up at will. If that's what you want to do.

Code: ags

File *input = File.Open("error.log", eFileRead);
int count;
line[20];
if (input != null) {
  while (!input.EOF) {
    line[count] = input.ReadRawLineBack();
    //Display("%s", line[count]);
   count++;
  }
  input.Close();
}

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Yuri Patrick

#11
for line[20], when I go to compile and run the script, it tells me that line is an undefined token. :(

I never understood arrays, so found workarounds to manually making lists, unfortunately, none of my stuff was very dynamic because of that. :(

Nevermind. Fixed it. Wasn't thinking very clearly. Had some coffee and thought to myself, "*DUH!* I'm working with strings... So... String line[20];" and that fixed it right up. :)

Btw, I assume that for writing to a specific line in a file is possible as well? I just reverse the process in part?

Like first I read the file I wanna write to, count the lines, and then instead of just randomly writing WriteRawLines all over the place, I can then turn around and do something like line[count]=output.WriteRawLine(); and then line[1]=A new username;?

SMF spam blocked by CleanTalk