by stevekemp · 5y ago · 0 comments
For example imagine you wrote an "EXAMINE" command, and you wanted to allow all objects to be examined. The horrid way to do it would be something like this:
if target == "desk"
print( "The desk is ..\n" );
if target == "book"
print( "The book is ..\n" );
With a table-based approach you just define your struct (in C) or item-table (in assembly) and your code now looks like this: item = find_item_by_name( object );
print( item.description );
Sure you have to write the lookup function to find the object, but it means you don't have to duplicate the logic for every action (get, drop, examine, use, etc).Using tables for items, and locations, basically saved me a lot of custom code, cut down on repetition.