Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Storing items in a file (RPG help)
#1
Hey guys, once again I am bothering the forum.

I saw the game "Konrad the Warrior" from acidworks used a file that had the items stroed as characters... such as the delta greek symbol or whatever. Would that help slim a program down if you had a seperate file labeled 'items' that had things such as

Ö = "Short Sword"

and stuff like that.. then you would just read that file and it would equip the guy as necessary? Thanks for any help.. this may be vauge and that is because, well, I AM vauge.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#2
Yes, your question kinda makes sense.

Basically, it sounds like you want to have all items designated by an ASCII character, then have a lookup table, in the form of a file, that holds the string values for each ASCII character. It's not a bad idea, but it won't be all that fast.

If you have the memory space (i'm not sure if that's the reason you are trying to slim down your proggy or not) then you should store the value in a file and then load them into a string array at runtime, that way your code is shorter because you don't have to have data or string statements. Then you can just pull the strings out of your array when you need them.

edit:
Didn't finish before I hit post.
If you don't have enough memory space, then you can do a rather slow routine that would allow you to read each line of the file, just have the first line coorespond to a number, then n +1 = second line, etc. With a file like this, you can get your input from the file, and discard it if it isn't the number of the item you want.

That method, however, will be quite slow. I'm sure there is a faster method w/ bsave and stuff, but I'm not quite sure of exactly how you should implement it, so it would probably be better if you got advice on how to do that from someone else (unless I think of something, in which case I will get back to you)

Aaron
Reply
#3
I had a problem with item names in a program I wrote recently where I had about a thousand items and putting them all into a subroutine was causing a string space overflow or something. So what I did was the following:

1. Made 10 different item types (food, gemstones, potions, keys, weapons, armor, scrolls, miscellany, quest items, artifacts, non-monster items [items that can't be found randomly from victory in battle]) and assigned each type a multiple of 100. So food = 0, gemstones = 100, potions = 200, keys = 300, and so forth.

2. Within each item type, I listed the items in order from 1 to a max of 99 in terms of rarity. So the most common food you'd encounter would be item 0 (food category) + 1 (most common) = 1 = "Leg of Lamb", the next most common food = 0 (food category) + 2 (next most common) = 2 = "Green Apple". The most common artifact would be 900 (artifact category) + 1 (most common) = 901 = "Bowl of Gruel". And so on...

3. I made a file called "ITEMS.DAT" in the game directory that looks like the following:

[ITEMS.DAT]
Code:
0
Nothing
Nothing
1
Leg of Lamb
Meat?
2
Green Apple
Fruit?
3
Brown Apple
Fruit?
4
Red Apple
Fruit?
5
Bunch of Grapes
Fruit?

well, you get the idea. I list the item number, the name of the item, and then the unidentified name of the item.

4. In the program, I made a function called "itm$" which you pass a number and an identified/not-identified flag and it returns the name of the item:

Code:
FUNCTION itm$ (n, id)

OPEN "ITEMS.DAT" FOR INPUT AS #2 'items
     DO
          INPUT #2, t 'get item number
          IF t = n THEN 'you found the item in the file
               IF id = 1 THEN
                    INPUT #2, t$ 'get identified name
                    INPUT #2, c$ 'skip
               ELSE
                    INPUT #2, c$ 'skip
                    INPUT #2, t$ 'get unidentified name
               END IF
          ELSE
               INPUT #2, c$ 'skip this item
               INPUT #2, c$ 'skip this item
          END IF
     LOOP UNTIL t = n OR EOF(2) 'found item or no items left
CLOSE #2 'items

itm$ = t$
END FUNCTION

5. Now, all items in the game can be referred to quickly by numbers. I printed out a big list of all my items with numbers so that I can reference them quickly. In the code, whenever I want an item name to display on the screen, I just do this:

Code:
PRINT itm$(ItemNumber, IsItemIdentified)

(I actually use I and ID as my argument variable names)

Although the retrieval of items may not be that fast (I can hardly notice any time delay at all even with over a thousand items on a slow computer, tho), the benefits of having your items coded by GROUPS and NUMBERS are many:

1. You can easily code a "find random item" routine, or do a "find random gem" routine, or a "find random potion" routine. You can make a limit on what items a monster can drop (for example, this goblin will drop a random item, but ONLY the most common of any random category. meanwhile, the DRAGON will ONLY drop artifacts. The Vampire will drop a random category, but only a 5th most common item or rarer..) Get it?

2. You can make the following routines very quickly:

AddItemToInventory(ItemNumber)
AreYouCarryingThisItem(ItemNumber)
AreYouCarryingThisItemIdentified(ItemNumber)
IsItemAnArtifact(ItemNumber)

and many others.

Hope this helps!

*peace*

Meg.
Reply
#4
Meg that makes some sense. I still just can't believe all this stuff... I mean, when I joined in November '02, I thought myself to be a good progger with decent skills, but now I see that I am in fact borderline newbie...........oh well, practice makes perfect! Big Grin Thanks again.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)