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.
Hello wonderful friends of the LemmaSoft Forum!!
I come bearing a request for assistance regarding my code.
The name gen I have works great! Managed to get it to fill the input field, but after jumping to the next scene, it generates a whole new name >:(
Here's a preview of the code in action:
define mc = DynamicCharacter("mc_name")
default names = ["Eisley","Romi","Arianwen","Elvira","Belphoebe","Etol","Aralueni","Morag","Ottoline","Velnor","Euphoria","Envy","Naiad","Hauntice","Malice","Aquina","Sprite","Revelation","Ethereal","Priam"]
default mc_name = ""
init python:
def generate_random_mc():
store.mc_name = renpy.random.choice(names)
screen mc_naming:
vbox:
hbox:
text "Character name:"
input value VariableInputValue("mc_name") minwidth 150 length 24
textbutton "Start" action Return() # due to label flow, this falls through to label greeting anyway
textbutton "Generate" action [SetVariable("mc_name", renpy.random.choice(names))] # given that your function only does one thing, simply using SetVariable directly seems far more efficient
textbutton "Generate (Function)" action Function(generate_random_mc) # example of using a function if you intend to extend the function further (I really don't see the point of the generator class)
label start:
call screen mc_naming
label greeting:
mc "hello!"
mc "my name is [mc_name]"
return
Last edited by peach_light on Thu Apr 11, 2024 1:42 pm, edited 2 times in total.
Screens should not have any side effects in their code. Screen code is run multiple times during prediction and every time screen refreshes (basically, when anything happens) and can be executed with any parameters, including those you never tried to pass.
In short, move random name generation and empty name replacement outside of the screen, after you call it.
Even better, instead of SetVariable("random_mc",True), use Function(gen.randommc)
Ocelot wrote: ↑Wed Apr 10, 2024 4:42 pm
Screens should not have any side effects in their code. Screen code is run multiple times during prediction and every time screen refreshes (basically, when anything happens) and can be executed with any parameters, including those you never tried to pass.
In short, move random name generation and empty name replacement outside of the screen, after you call it.
Even better, instead of SetVariable("random_mc",True), use Function(gen.randommc)
Unfortunately, doing this has caused the generator to not really do anything at all? Hitting the randomize(dice) button results in nothing happening either on the screen or once the game jumps to greeting.
Only if I put the gen.randommc in the greeting label does it generate anything, but only after the start button is pressed.
What I was intending was to hopefully have the generator provide a name from the screen like in the video I linked and perpetuate that into the game.
also for some reason Function(gen.randommc) doesn't really function as it should. I initially had the code using the function string and it didn't really do anything :\
Thus far, I have a super chaotic workaround that looks like
Looking at your original code, you have if randommc, a variable which starts as false in your code. This is what seems to be used to check whether to generate a name or not in your class.
Then in your script, you check if this variable is populated, and run the same code again
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
define mc = DynamicCharacter("mc_name")
default names = ["Eisley","Romi","Arianwen","Elvira","Belphoebe","Etol","Aralueni","Morag","Ottoline","Velnor","Euphoria","Envy","Naiad","Hauntice","Malice","Aquina","Sprite","Revelation","Ethereal","Priam"]
default mc_name = ""
init python:
def generate_random_mc():
store.mc_name = renpy.random.choice(names)
screen mc_naming:
vbox:
hbox:
text "Character name:"
input value VariableInputValue("mc_name") minwidth 150 length 24
textbutton "Start" action Return() # due to label flow, this falls through to label greeting anyway
textbutton "Generate" action [SetVariable("mc_name", renpy.random.choice(names))] # given that your function only does one thing, simply using SetVariable directly seems far more efficient
textbutton "Generate (Function)" action Function(generate_random_mc) # example of using a function if you intend to extend the function further (I really don't see the point of the generator class)
label start:
call screen mc_naming
label greeting:
mc "hello!"
mc "my name is [mc_name]"
return
define mc = DynamicCharacter("mc_name")
default names = ["Eisley","Romi","Arianwen","Elvira","Belphoebe","Etol","Aralueni","Morag","Ottoline","Velnor","Euphoria","Envy","Naiad","Hauntice","Malice","Aquina","Sprite","Revelation","Ethereal","Priam"]
default mc_name = ""
init python:
def generate_random_mc():
store.mc_name = renpy.random.choice(names)
screen mc_naming:
vbox:
hbox:
text "Character name:"
input value VariableInputValue("mc_name") minwidth 150 length 24
textbutton "Start" action Return() # due to label flow, this falls through to label greeting anyway
textbutton "Generate" action [SetVariable("mc_name", renpy.random.choice(names))] # given that your function only does one thing, simply using SetVariable directly seems far more efficient
textbutton "Generate (Function)" action Function(generate_random_mc) # example of using a function if you intend to extend the function further (I really don't see the point of the generator class)
label start:
call screen mc_naming
label greeting:
mc "hello!"
mc "my name is [mc_name]"
return
This has genuinely saved me !!! Thank you!!!!!!
Give it to the newbie to overcomplicate something so simple ahaha
Thank you again !!!!