Hi. I am trying to make something similar to a RPG text game, in Visual Basic 6. I know what you want to say "it's not good for text games" but i have my reasons.
The problem i am facing is this: let's suppose i have 3 main skills: meelee, ranged and magic. And let's also suppose that those main skills hava like 20 sub skills : Dagger, Sword, Axe, etc for Meelee;; ShortBow, Sling, LongBow, etc for Ranged;; Fireball, Heal, Thunder, etc for Magic.
This looks quite simple. When i type "fireball" it will do it, when i "stab" it will stab, exactly as the skill sais.
What if i have 15 main skills? I also have Necromancy, Occultism, Elementals, Thievery, so on, each one with at least 20 sub skills. How can i make the main function recognise what i type? I make one CASE for each of them, calling the skill function?
And one more problem: i want my executable as dynamic as possible: if i modify something in my skills, the executable won't be affected. Why recompile the exec after each test? And what if i add more skills in, let's say Necromancy? The new skill is not recognized automatically, and i want it to be recognized.
I have a lot of problems.

Please, if anyone knows how to help, give me at least a few tips. I am not that good in programming and this is not a scholar project, or somehing :p Lol.

Thank you in advance.

Recommended Answers

All 9 Replies

I would suggest putting these skills into a data file, like a text file, or a database. I might strongly suggest that you look into SQL or ADO (you'll find that you will have less trouble with SQL) for this project. I, however, would go with text files (because I don't always listen to reason). Then, you read in the textfiles, say, on form_load, and use a dynamic multi-dimensional array. I Can See Redim Preserve playing a big role in this. You might also consider using a "collection" instead, which is sort of like an array, but with keywords as indices. Let me know what you come up with.

I think that using a *.ini format for my skills will be the best solution for me, cose i have no idea how ADO or SQL work. I could also use access *.mdb files too, they are very easy to read from.

I tested some CASE examples recently... but i have no idea how to use dynamic multi-dimensional arrays... quite confused right now. I'll try to search and documentate. "Collection" is also a strange word for me.

SELECT CASE uses strings, right? I could store the skill names in strings (that i read from *.ini) then i add them to CASE. But what i don't know is how will the CASE thingy recognise new skills? Isn't it fixed to CASE "whatever1", CASE "whatever2"... etc?
Could i use CASE ELSE to add more CASEs in the first test? Confused again :p

And one more thing: i am using Visual Basic 6 Service Pack 6. Maybe it helps...
I am thinking that "Collections" is not a thing available in VB6... But i don't know.

Sure it is.... try this in a test project on form_load:

' /* Declare A New Collection */
Dim Melee As New Collection

' /* Add Item Dagger, with index of: dagger */
Melee.Add "Dagger", "dagger"
' /* Add Item Sword, with index of: sword */
Melee.Add "Sword", "sword"

' /* Show By "key" index */
MsgBox Melee.Item("sword")

' /* Show By Numeric Index */
MsgBox Melee.Item(1)

Now, you can do this with some files that read it in.... hmn, something like:

dim meleeFile as string
meleeFile = app.path & "\melee.txt"

' /* If The melee file does Exist */
if dir(meleeFile, vbnormal) <> "" then
     open meleeFile for input as #1
          do until eof(1)
               input #1, tmpvar
               melee.Add tmpvar, tmpvar
          loop
     close #1
end if

And now, whenever you want to add a melee weapon or something, you can just update the .txt file (hmn, you could let the user make their own weapons and stuff now.... cool). Obviously, these are just two examples, but I'm sure you can figure out how to make them work together...

A little on collections:

Collections can be referenced by either a numeric index, or a keyed index. Naturally, the first index say, melee.item(1), would be the first item in your collection list. melee.item(2) the second and so on. You could also reference it by the key name. In the first snippit, you see "Sword" which is the actual value, you could get that from using melee.item(2), but you also see sword with just lower case.... that's the key reference so that you can refer to it as melee.item("sword"), and it would give you the same value as melee.item(2). Anyway, let me know if you need any further assistance with this.

Ok, thank you very much for the information you gave so far. I started searching for more information related to collections.

Now, about the second code. How should that "melee.txt" file look like?

And what is "vbnormal" in this line "if dir(meleeFile, vbnormal) <> "" then"

I know what each box, label, button (and so on) do, but the coding is harder for me.
I only have one book to learn from and that is for Visual Basic 5, very old book, so i have to search on google...

The Melee.txt text file should have 1 entry per line for the code above to work. So, something like:

knife
dagger
spear
elbow

The dir function is telling me if the melee.txt file exists.... the vbnormal portion of it, says to look for a normal file, with no hidden, or system attributes set. Imagine our pain if you did an open command and the file wasn't there..... uh oh.

I'm sorry... i can't make that second program work :cry: :cry: :cry: :sad:

I added the code between Form_Load() and End Sub.
I added melee.txt.
When i compile it it returns error (LOGIC!) because it doesnt recognize tmpvar.
I added "Dim TMPvar As String" before "Dim meleeFile As String", but it returns error (Runtime error 424. Object required). I changed the string into "Dim TMPvar As New Collection". It returns another error (Type missmatch).
What is the type of TMPvar ? How can i make the code work?

tmpvar is a temporary variable, used only as a buffer to hold the current line of the file in the loop. Basically, it gets changed on every line of the file. It's only used as a temporary storage place to store the item long enough to stick it into the collection. Truth be told, you could probably read the data directly to the collection, but it makes it easier to read the code using the buffer variable. I'm guessing somewhere you have an option explicit set, which is demanding you declare all your variables... try removing the option explicit, and see if that resolves anything.

The "Require variable declaration" is not selected. It never was.

I had to declare the "melee" thing as new collection. Now it works... At last!
Thank you very much.
I think the rest of the problems are minor now... Yeah, i think that now.

You were of great help.
Thanks. *bow*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.