Jump to content
  • Advertisement

No Comments == More Problems

A4L

960 views

G'Day....

So I spent most of the day re-acquainting myself with the code of my project, after my near 6 month break from computers. Not a break from the project but literally, I didn't have any computer or access to the internet beyond my phone.  This was a lot harder than I thought as I had completely forgotten the logic I was using for this program.  I mean the app worked, and I could keep going, but I wanted to know the exact specifics to be clear in my mind. I also needed to strip it back to the very skeleton, removing all the "testing" stuff, and then build it up from there for so I could start loading the engine with actual content.

I only made it halfway through tracing the game loop through all the classes so far but I was kinda surprised at how far along I am. I mean I am literally at the point of just adding the command processing and the loop is pretty much closed.  This brought back to mind the big problem I was tackling at the time I sold my old house, moved and the project went into hibernation.

A Functional Impass

So the problem I had was being confused about how to have unique code in my project.

So far everything is made with classes that are filled with data in a very general way. I wanted to be able to populate the gameworld during initialisation with simple instructions like gameworld[1,2].loadArea("bedroom"). For example, the "Layout" is a grid of "areas" and the "areas" contain "items" and "exists", and the areas, items and exits all contain unique text strings for names and descriptions and all that concerning their properties. These are all created by reading "area" data files. So during game initialisation, the code just phrases the area data file and this creates the game world. (See my blog post on data files)

The command interpreter can determine what the player is trying to do and with what, like "get apple" or w/e... but the issue I was having was I didn't understand how to have unique code events on these objects. Everything is created from the same classes but how do I have unique functions in those classes and still have the be generic enough be filled in this nice neat way. I didn't want to have to write all these unique classes and then make all these complex checks and balances in the data importer.

How do I say have "take apple" put the apple in the inventory, and have "take supporting block" cause a cave in and spawn new items and change the exits of the entire area?

A Solution?

So I was pretty down while doing my project revision knowing that as soon as I got it back up to scratch I would again be stuck at this problem in the design but while I was having a shower I had an idea for a possible solution that seems simple and within my knowledge and abilities.

To put simply I will make a new class called "Action" that will process the commands separately from the items and exits. In the same way, I do not just print the text outputs directly to the console, I send them to a textBuffer for processing first, I will not send the commands from the command interpreter directly to the items or other interactable objects and trigger action function in those classes.

Instead, I will have an action class that has the command sent and using the player location to find the area as well as the item name I will be able to use if or switch or whatever to filter these action between generic actions or unique ones. So "get apple" is sent to the action class, it searches through to see if the apple has a unique get function... it sees no exception, so it falls through to to the generic "remove from area, add to inventory and print "get" text to screen". Meanwhile "take supporting block" searches through the action class and sees that there is a special case for "get" concerning the "supporting block" and it falls into that unique code block that dose w/e.

I think this will work. The only issue I have is how exactly to get it to work. I may need to make action classes for every action type. Though I hope that this will not be the case. Either way, regardless I believe I have found (maybe a clunky way, but a way) to have unique action events for the generic item objects in the game without having tons of hard coded functions attached to every object.

Times up! Let's do this.

I have to say I was feeling pretty down as I was going through the old code and to be honest this "test project" while teaching me a lot is starting to feel like it is now holding me back fomr moving on in my hobby. Having this big "oh yeah, I never worked out how to get past that issue" wall at the end of my "revision" was a real bummer.

Now though I feel energised and regardless of if it works out as I think or not, having something to bang on with has given me a feeling of momentum

 

Anyway.. thanks for reading!

--A4L

 



2 Comments


Recommended Comments

I'm thinking about giving lua a go to cure that.. (on my next sprint) Always wanted to do hot swapping ; and pick up the pace (accumulated compile time==bad)(scribbleCtrlS==good)  

edit: whoops. my apologies. No disrespect, I see the learning exercise now. 

Edited by GoliathForge

Share this comment


Link to comment

One Action object would indeed work. The disadvantage is that it has knowledge about lots of game objects laying around in the adventure. You can also split your Action object into smaller pieces. 1 Action object for each game object in the adventure, and instead of storing that action object near the player or command processor, store it in the game object itself. That leads towards the Behaviour object I proposed in that same thread at the first page. My proposal was different in the sense that I also broke the Action object into even smaller pieces based on the verb, so "take" can be special, but eg "drop" is not.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!