3
\$\begingroup\$

I'm coding a relatively simple VN with RPG elements in Ren'py, with little prior programming knowledge. There's one aspect that I can't simplify further because it's important to the game's branches, but that I'm not sure how to enact.

There are four traits/stats the main character can have in this game:

  • Viciousness
  • Intelligence
  • Creativity
  • Charisma

You have two of the four. They don't have levels or anything -- it's simply 'do you have this trait or not'. You can't change traits after picking the two of them, you just have e.g. a Creativity/Viciousness build for the rest of that playthrough.

With my limited prior knowledge, the only way I can figure out how to enact this is with a giant mess of if-else statements. You would, for instance, start with:

default Intelligence = False

Then if you pick Intelligence as one of your stats:

$ Intelligence = True

Then, for anything further that requires Intelligence (or precludes it, as the case may be):

if Intelligence = True

But this sounds like a giant overcomplicated mess if I'm doing it for each and every time the game checks if you have/don't have a trait. There's a better way. What is it?

\$\endgroup\$
1
\$\begingroup\$

You should build up a system in which you can define what is required for actions (as of anything that requires these traits). Now, logically speaking you have A,B,C,D.

Sometimes you want A and B, sometimes you want A or B, sometimes you want A and (B or C). One way which comes to my mind is to create a class or struct (let's call it 'R') to tie together OR conditions, then whenever you have a requirement, you use a list or array of these conditions, which is an AND.

So the system would be used like this ([ ] symbolizes one of 'R':

[A] [B]

This means you must have A and B.

[A] [B or C]

This means you must have A and either B or C.

For all of this you should use enums and some method or function like "CheckRequirements (List requirements)" which compares the traits of the player and compares them with the required ones and returns a bool.

I am not sure whether it's good to hard code such conditions rather than finding ways to solve it in more abstract ways. But it all depends I guess. Also I don't know which engine or scripting/programing language you are using.

\$\endgroup\$
2
  • \$\begingroup\$ I'm using Ren'py, which is explicitly stated in the title. \$\endgroup\$ – Max Astrophel Jul 24 '18 at 7:36
  • \$\begingroup\$ Ah sorry, I missed it (I looked mostly in the tags). I can't help with that, so this abstract answer is all I have to offer. \$\endgroup\$ – Battle Jul 24 '18 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.