VB help requested

Started by
12 comments, last by senelebe 17 years, 11 months ago
A friend of mine and I are in the process of making some tools for PnP RPG's, such as a character gen, monster/spell/whatever info viewer, dice roller, etc. Right now, we're running into a problem as to the best way to store information on monsters/spells/whatever. We're currently storing it to a plain text file, but there are several headaches cropping up there. I've tried researching into databases and XML as possible alternatives, but most information I find is too sketchy on details for me to be comfortable with it (database info turns out to be focused on the actual writting of the database, but not on how to access it with code, and XML info focuses on web stuff, which we're not doing, or tends to be a convuluted nightmare) So, to the question, does anyone know of any tutorials that show how to make a simple database and how to access it, or how to work with XML to the extent that I need it, without all the extra crap? Or would we be better off with just a plain text file?
Advertisement
No takers? I thought I might find some useful info here. Ah well. Just in case, I'm using VB.NET 2005. Any opinions would be useful.
This depends on what kind of data you want to store. You can store stuff about monsters and spells in files. Since you are working on .NET, this should be pretty easy. You can create a class that defines a specific type of monster, and then you can load in the data for a new monster from a file. You can use something like

MonsterType = "dog"
ImageFile = "dog.bmp"
AttackPower = "34"
...


You can easily parse this file and then use it in your game.
I am currently working on a project very much like yours. A lot of it depends on how much data you have. For the typical stuff i would suggest XML, it works pretty well and can really store a lot of information and is pretty easy to access.

If you have tons of information, like all of the source books for Rifts then I would suggest going with mySQL.

If you need some help getting started let me know, I should be able to point you in the right direction.

theTroll
Hope this helps...didn't test it, but I think it should help you out a bit...

Reading XML file:
Dim objDocument As ObjectDim objNode As ObjectDim objNodeList As ObjectDim strName As String, strHealth As Long, strStrength As LongDim objMonster As MonsterDim objMonsters As New Collection' Create DOM Document object.Set objDocument = new ActiveXObject("Microsoft.DomDocument");' Open the XML file.objDocument.async = FalseobjDocument.validateOnParse = FalseCall objDocument.Load(strFilename)' Loop through each element of the root.If objNode.parseError.errorCode = 0 Then    ' Find the children of the "monsters" element.    Set objNode = objDocument.documentElement.selectSingleNode("monsters")    Set objNodeList = objNode.childNodes        ' Loop through each single "monster" element and create monsters objects.    For Each objNode In objNodeList        Set objMonster = New Monster                Call objMonster.setName(objNode.selectSingleNode("name").nodeValue)        Call objMonster.setHealth(CLng(objNode.selectSingleNode("health").nodeValue))        Call objMonster.setStrength(CLng(objNode.selectSingleNode("strength").nodeValue))                Call objMonsters.Add(objMonster)    NextElse    ' Handle error here...End If' Dereference memory objects.Set objDocument = NothingSet objNode = NothingSet objNodeList = NothingSet objMonster = Nothing


Writing XML file:
Dim objDocument As ObjectDim objMonsterNode As Object, objCurNode As Object' Create DOM Document object.Set objDocument = new ActiveXObject("Microsoft.DomDocument");' Load filename you provide to function.objDocument.async = FalseSet objMonsterNode = objDocument.createElement("monsters")Set objDocument.documentElement = objMonsterNodeFor Each objMonster in objMonsters    Set objCurNode = objDocument.CreateElement("name")    objCurNode.nodeValue = objMonster.getName()    Call objMonsterNode.appendElement(objCurNode)        Set objCurNode = objDocument.CreateElement("health")    objCurNode.nodeValue = objMonster.getHealth()    Call objMonsterNode.appendElement(objCurNode)        Set objCurNode = objDocument.CreateElement("strength")    objCurNode.nodeValue = objMonster.getStrength()    Call objMonsterNode.appendElement(objCurNode)NextCall objDocument.Save(strFilename)' Dereference memory objects.Set objDocument = NothingSet objCurNode = NothingSet objMonsterNode = Nothing
Here is an article on XML serialization with VB.Net. This lets you easily define how a class is stored in XML.

Although, depending on how complex the data is, a simple text file may be better. If you want to use databases you need to look for information on ADO.NET and SQL.
Thanks for the replies. A couple things, though...

MattMan : Will the code you use to write to the XML file actually create the file and fields, or will I have to do that seperately?

Currently, this is being geared towards DnD 3rd Ed., and we have two monster manuals, a speel book, and several other things, so it'll probably be quite a bit of info. We already have the dice roller and character generator. Right now I'm working on a program to store the monster info into the files, so his wife can start data entry on that.

Ace Pilot : I would like to make a file like that, but have no idea how to parse something like that. Right now we're simply using the MyReader parsing, as referenced by MSDN.
You can either enter the information into the XML by hand (something I seem to be fond of doing) or write a simple app to enter the information for you.

I would suggest you make a class that can enter and retrive information from the XML file. This class can be used to make an app to enter the information and it can also be used in your RGP app. It might also be a good idea to create in your RGP app a way to enter more information to the XML file. This will let you have a single program instead of two to keep up with more information.

theTroll
TheTroll : that's what I'm trying to figure out how to do.
So where are you running into trouble?

theTroll

This topic is closed to new replies.

Advertisement