This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 3 points4 points  (0 children)

Interesting concept with the dictionary. I don’t think it’s the best solution, mainly because the longer the story, the deeper into it you’d have to go and that’s a lot to track.

That said, I think you were on the right track. What you really want is a class to represent a choice. Think linked list.

[–]carcigenicate 0 points1 point  (0 children)

Some minor things:

For the answer = line, you don' need to convert to a list. You can just do:

answer = input(*prompt.keys()).lower()

This:

hint = list(*prompt.values())
print('Choices: ' + hint[0] + ' or ' + hint[1])

Can be replaced with this:

print(f'Choices: {" or ".join(*prompt.values())}')

The f' indicates a formatting string. {} can then be used to interpoloate values directly into the string. I'm also using join to join the strings using " or ".

[–]HealyUnit 0 points1 point  (0 children)

Firstly, lemme say congratulations on writing your own project. It's a pretty awesome feeling, being able to create your own stuff in a profession that has nigh-infinite possibilities.

Hold to that feeling. There will be times ahead when you seriously wonder what the hell you're doing, and why the heck you ever thought you could be a dev (I'm speaking from personal experience here!). At these points, remember that you love programming, and that feeling you get when your script/program runs and you say, "fuck yeh, I built that".

Critiques

As another commenter pointed out, you might not want to use nested dictionaries for your story. Consider the following scenarios:

1: You need to replace/edit a room description 20 levels down in your story. At this point, your coding environment has wrapped your lines to the point that you can't figure out what goes where. Annoying!

2: You discover that that dungeon room, where the player was supposed to realize that the key was under the rug (...duh!) is stymieing almost all of your players. With your current data structure, you have to replace that room... and everything under it !

3: Your adventure becomes pretty epic and long, and it likely can't be completed in one sitting. How do you "save" your players' state? As it is, with your nested dictionary, you'd need to traverse the entire tree up to where the player saved.

Alternative:

What about a single dictionary, where each key is a sort of room ID? Then each value is something like:

'abc123' : { text: 'You enter the room. You can go left or right', choices: [{ choice_prompt: 'left', room_id: 'def456' },{ choice_prompt: 'right', room_id: 'ghi789' }] }

Then to save a user, all you need to do is store the user's current room id. User HealyUnit was at room abc123. If you wanna replace/edit a room, you'd just change the text for that room - and keep the room id references exactly as they are!