having an object selector?
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.
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.
having an object selector?
I have several characters that are set up as objects (with their own stat values) and would like to set up a system where if I select them I can have them do something without having to reference that specific character/object for each and every character. any suggestions on how to approach this?
Re: having an object selector?
Could you be more specific? It might help if you give an example of what you *don't* want to do, and we can tell you how to avoid it.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
Re: having an object selector?
what I'd like to make is basically a "roster" menu of sorts where I can select a character and interact with them such as train them up a specific stat or hang out with them to increase affection. What I don't want is to code the exact same common "activities" for each and every character.
hopefully that clears up any confusion
hopefully that clears up any confusion
Re: having an object selector?
Hi, elhlyn,
I think you previously had the related question. I guess, the example didn't work for you, or it was a poor explanation from my side (or I just did not get your question.)
(If you look at the example, screen select_character is simple version of "roster" menu. The selected character passed to the variable npc. Then you can do with this selected npc all sorts of "activities" without specifying who exactly this character is.)
I think you previously had the related question. I guess, the example didn't work for you, or it was a poor explanation from my side (or I just did not get your question.)
(If you look at the example, screen select_character is simple version of "roster" menu. The selected character passed to the variable npc. Then you can do with this selected npc all sorts of "activities" without specifying who exactly this character is.)
Re: having an object selector?
Unfortunately the main issue I had when I was utilizing this code was on the issue of repeating characters when I wished to have them unique rather than potential duplicates. I am wrong on 2 fold for not reaching out again and more importantly not being very clear in explaining what I'd like to do.
Re: having an object selector?
Please write out a sample of what you want your code to do for one character, and then we can maybe show you how to generalize it. I still really don't have a handle on what you're looking for.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
Re: having an object selector?
just a quick example
Code: Select all
label training
$ selected = char_tom
"what would you like to do?"
menu:
"traing":
"you trained their strength"
$selected.strength +=1
jump ("train")
"hang out":
"you hung out."
$selected.affection += 1
jump("training")
#and if I want to choose another character, let's say Jill,
label training
$ selected = char_jill
"what would you like to do?"
menu:
"train":
"you trained their strength"
$selected.strength +=1
jump ("training")
"hang out":
"you hung out."
$selected.affection += 1
jump("training")
Re: having an object selector?
You want your code to look like this:
Code: Select all
init python:
class NPC():
def __init__(self, name, strength=0, affection=0):
self.name = name
self.strength = strength
self.affection = affection
default char_tom = NPC("Tom")
default char_jill = NPC("Jill")
label char_selector:
"Who do you want to work with?"
menu:
"Tom":
"Tom is by the bar."
$ current_npc = char_tom
"Jill":
"Jill is climbing a tree."
$ current_npc = char_jill
call training(current_npc)
"Training is done."
"[current_npc.name]'s stats are now: strength=[current_npc.strength], affection=[current_npc.affection]."
$ current_npc = None
jump char_selector
label training(selected):
"what would you like to do with [selected.name]?"
menu:
"train":
"you trained their strength"
$selected.strength +=1
"hang out":
"you hung out."
$selected.affection += 1
"[selected.name] has to go now."
return
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
Re: having an object selector?
Thanks!