Buttons with highly variable behaviors. How would you do it?

Let’s see if someone can give me ideas on how to do this in terms of software design.

The problem is that I am trying to make a narrative game, in that game after a situation is presented, several options (buttons) are given, and depending on which one you press, it will produce some effects. These effects are very different, they can go from advancing the story, showing the following text, to increasing your charisma by one point, or unlocking access to a place.

About how to achieve this I was thinking for a while. I came up wiith when building the button when you generate the view of the specific dialog, in addition to passing the text that the button should display, which is stored in a data table, I can also pass a string that encodes the effects that make the button. And when you press the button it simply passes that string to a handler. The handler decodes the string and is responsible for communicating with the various objects that manage the ui, my character’s attributes, or access to different places.

Is that correct or am I overcomplicating the issue? Can you think of a design pattern that I’m not seeing that provides a better solution?

1 Like

Are we talking about 20 different outcomes or 200 or 2000?

200

In case it helps someone, in the end what I have done has been to implement the Command pattern. And to make it usable data-driven, I’ve created an object that contains a map of strings and concrete command classes. Each specific command defines the action to be performed and how to perform it. It must also parse a parameter string if I want to pass values to it.

1 Like