How to create a label statement in a python custom class ?

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
Jairus
Newbie
Posts: 2
Joined: Wed Nov 06, 2019 2:20 pm
Contact:

How to create a label statement in a python custom class ?

#1 Post by Jairus »

What is the python equivalent of the Ren'Py label statement ?

I found myself in need of creating a series of dynamic label statements inside a python custom class. Is it even possible to do so ?

So what happens is that I created a custom-defined menu function that have a list of dynamic options for the player to choose. Once the player clicked a option, it will automatically jump to a label corresponding to that option. The options are all dynamic, based on variables. So the corresponding labels should also be dynamic.

I could get around this by writing all the label statements with argument inputs in Ren'Py script. But it's gonna take too much codes, and many label statements would have a bunch of repeated codes in it. I think the more elegant way to do it is to write the label statements in the python custom class. But I couldn't find out if there's a python equivalent for the label statement.

Any suggestions would be much appreciated.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to create a label statement in a python custom class ?

#2 Post by Alex »

Jairus wrote: Thu Nov 14, 2019 5:07 pm ... Once the player clicked a option, it will automatically jump to a label corresponding to that option. The options are all dynamic, based on variables. So the corresponding labels should also be dynamic. ...
What those labels should do - some calculations, oparations with screens or..? In this case you might need to create a function, that will do all that stuff using arguments passed in.
Or they should show some npc's, their talkings, some animation? Then you either need several kinds of labels to pass in some variables (what bg and what character should be shown, what (s)he will say, etc), or need one label to pass in a bunch of statements. Either way you can achieve this with ordinary labels (like, if you pass a list of statements to the label, then you can make a loop in it to iterate through this list).

philat
Eileen-Class Veteran
Posts: 1911
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: How to create a label statement in a python custom class ?

#3 Post by philat »

Agreed that, based on OP's post, I don't see the point of dynamic label declarations. It's hard to see why that's necessary in the abstract. It would be easier to give helpful advice if this were more specific -- like, are you building a battle system? Going on dates? etc. By specific, I mean, like. Code.

Jairus
Newbie
Posts: 2
Joined: Wed Nov 06, 2019 2:20 pm
Contact:

Re: How to create a label statement in a python custom class ?

#4 Post by Jairus »

Alex wrote: Thu Nov 14, 2019 6:13 pm
Jairus wrote: Thu Nov 14, 2019 5:07 pm ... Once the player clicked a option, it will automatically jump to a label corresponding to that option. The options are all dynamic, based on variables. So the corresponding labels should also be dynamic. ...
What those labels should do - some calculations, oparations with screens or..? In this case you might need to create a function, that will do all that stuff using arguments passed in.
Or they should show some npc's, their talkings, some animation? Then you either need several kinds of labels to pass in some variables (what bg and what character should be shown, what (s)he will say, etc), or need one label to pass in a bunch of statements. Either way you can achieve this with ordinary labels (like, if you pass a list of statements to the label, then you can make a loop in it to iterate through this list).
Per your suggestion, I've tried defining another custom class to essentially replace most of the functionality of those label statements. And the codes are indeed much cleaner, even though I still have to create a long list of label names. But it worked !
Thank you for your help.

A follow up question. there's not a python equivalent of the label statement, after all ?

Post Reply

Who is online

Users browsing this forum: No registered users