Tips for efficient Variable checks across different characters.

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Chendzeea
Newbie
Posts: 10
Joined: Fri May 18, 2018 8:05 pm
Contact:

Tips for efficient Variable checks across different characters.

#1 Post by Chendzeea » Sat Jul 04, 2020 4:57 am

I'm seeking advice on how best to handle variable checks against a well "Variable Variable".
I've Multiple Characters with their own stats, skills and inventory.
Going into an Encounter you choose which character you want to use. I handle this with a POV = Name variable.
Each Encounters, checks either skill, inventory item or stats to dictate the outcome. Pretty standard.
The issue is how best to handle the checks to apply across all the characters.

For Example at the moment I'm using a set up kinda like this. Lets say "Ashley" is using a "Key"
If POV == Ashley and Ashley_ItemKey == True
Win
elif POV == Ashley and Ashely_ItemKey == False
Fail
elif POV == Mark and Mark_ItemKey == True
Win
elif POV == Mark and Mark_ItemKey == False
Fail

At the moment I have duplicate Item tags with every characters name. Since each inventory is separate.
ItemKey_character1
ItemKey_character2 ect ect.

That seems cumbersome. Surely there is an easier way to track that.
also the above If statement seems cumbersome as well.
Lets say an Encounter against a Monster allows for 3 options
Use a Gun (Available if you have Gun), Run (Check Against Agility), Hide (Check Against Stealth)

Using the IF statements set up like I have it gets pretty complicated but works. I just feel it can be streamlined. Any advice would be greatly appreciated.

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: Tips for efficient Variable checks across different characters.

#2 Post by nananame » Sat Jul 04, 2020 5:59 am

You should look into classes. Creating a class for your characters will help you a lot.
Sorry I don't have time to point out manuals or explain in detail here but you'll cretae class such as:

init python:
class CharacterClass(object):

def __init__(self, name, itemkey, *args, **kwargs):
self.name = name
self.itemkey = itemkey

Then you'd declare your default characters:

default Ashley = CharacterClass("Ashley",True)
default Mark = CharacterClass("Mark",False)

And later in the game when you have POV = Ashley (or whatever) you can simply use:
if POV.itemkey:
win
else:
fail

This is a very short explanation and you really should learn about classes as there's a whole bunch more you can do with it.

Chendzeea
Newbie
Posts: 10
Joined: Fri May 18, 2018 8:05 pm
Contact:

Re: Tips for efficient Variable checks across different characters.

#3 Post by Chendzeea » Sat Jul 04, 2020 4:06 pm

Awesome :) That will definitely be the next thing I research. Thank you :D

Post Reply

Who is online

Users browsing this forum: Google [Bot], TioNick