How would I go about creating this algorithm? ( Intermediate Programmer)

Hey guys , I am creating a sort of simulation game and it’s kind of decision based. Basically , it works by a panel coming up with text on it , you then have options you choose from , depending on which option you choose , you get another panel with your result (it affects other factors in game as well) , and then another panel comes up etc until your turn is done. So , I’ve been struggling with how to implement this. I do think of myself as a somewhat intermediate programmer , but I want to learn and know the “proper” techniques. My idea was to create a couple of arrays , one for the text/panels and another for the options , and then create a sort of loop that displays the panels and options ( just buttons) at the same time , so the player can pick their choice ( and then the next panel and its respective options come up). However , I feel very unsure of if this way is correct and how I should go about it. Basically , what would you experienced programs recommend me to do? Any tutorials I should watch to up my skills on this topic? Or just some feedback on what I should do?

You should get started! Just start trying some things, see how it works out.

2 Likes

Good point , but I kind of just wanted to see if others who were more experienced, knew a better way of going about it.

Everyone will have a different solution to the same problem, there is no “proper” technique. What works for you is best.

Personally i’d create a Serializable class/struct that contains all information to show one panel, and loop through these to display them at the correct time.

1 Like

One window that works differently by assigning different functios.

1 Like

What you’re describing is something that works in the same way as a standard conversation system. So if you want to look at a tutorial for how to organize these kinds of things, that’s the thing to look for.

@TJHeuvel-net 's advice is solid, though.

3 Likes

Thanks for the advice guys!

I’m all for conversation systems (believe me ;)), but you may also want to read up briefly on decision trees and rule-based systems.

In any event, you’ll do yourself a huge favor by separating code and data. Don’t embed your text or decision logic in your scripts. Instead, write your scripts to read the data from a file or asset. This serves two purposes:

  1. You can focus on the data without getting distracted by the code, and vice versa, and

  2. You can change the data without having to rework code and possibly inject bugs into it.

It could be as simple as an Excel spreadsheet, or as fancy as an XML format generated by Chat Mapper or articy:draft (or even an asset created by a dialogue system asset).

1 Like

Another few tips, look at SOLID I get the feeling that patterns and design principles is what you are looking for.

As most people said, everyone does things differently. My take on this would be to make a class for managing the panels, and a class that contains the panel text and options. The manager keeps the data chosen by the player and controls which panels are shown, and when that panel choices are shown.

1 Like