SOLVED: Renpy random integer and unbound random choices

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.
Message
Author
Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#16 Post by Watercolorheart »

I have a feeling Ren'Py or python may be too limited for what I'm trying to do ... it simply seems to be impossible to call anything outside of the choice container from within the choices. Bad, bad, bad.
I'm not even the same person anymore

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#17 Post by JQuartz »

BCS wrote:I'm getting this description, but no official traceback error. But the text says:

"randomstopgap unbound"

[/edit]

Face, meet palm.

" %(randomstopgap )s "
$ random appearance = renpy.random.choice(['cute', 'slender', 'fit', 'pretty', 'buxom'
You didn't assign a value to randomstopgap
BCS wrote:I'm trying to figure out if the {nw} tag would work ... basically, what I need is something like {p} or {w} but actually erases the first line and displays the next one ...

I also can't call another %(randompronoun1)s from within the first %(randomstopgap)s ... this is going to be a BIG problem. D:

I tried '\"Person\" \"Hey!\"' but it didn't seem to like that ... it just displays "Person" "Hey!" and that isn't correct. "Person" should be in the name field. :/
I don't understand what you are trying to acheive. On another note if you want a sentence to go to a new line without erasing the previous line you can use \n like so:

Code: Select all

"BCS:\n I going to pull my hair out."
which would result in:
"BCS:
I'm going to pull my hair out"
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#18 Post by Watercolorheart »

I would need to acheive:

"BCS says ... "

"ARGH, I'm going to pull my hair out!"

"BCS says ... {x} ARGH, I'm going to pull all my hair out!"
I'm not even the same person anymore

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#19 Post by Watercolorheart »

JQuartz wrote:
BCS wrote:
BCS wrote:I'm trying to figure out if the {nw} tag would work ... basically, what I need is something like {p} or {w} but actually erases the first line and displays the next one ...

I also can't call another %(randompronoun1)s from within the first %(randomstopgap)s ... this is going to be a BIG problem. D:

I tried '\"Person\" \"Hey!\"' but it didn't seem to like that ... it just displays "Person" "Hey!" and that isn't correct. "Person" should be in the name field. :/
I don't understand what you are trying to acheive.
I think I answered the wrong question. I'm using dialogue like this in Ren'Py (this is the code):

Code: Select all

"Person" "Hey! You!" 
And if you try that trick inside the renpy.random.choice list, it doesn't understand. It prints to the user:
"Person" "Hey! You!"
In other words, I'm trying to set up dialogue within the original renpy.random.choices, but not a new one ...

renpy.random.choices = [('\"Person\" \"This.\"', '\"Person\" \"That.\"', 'You stop, bored.', 'You think to yourself, Hmm!'])
I'm not even the same person anymore

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Renpy random integer and unbound random choices

#20 Post by Showsni »

I see what you want. I'm not quite sure how to achive it, though. In the meantime, here's a hideous workaround:

Code: Select all

$ randomtest = renpy.random.choice([1, 2])
    
    
    if randomtest == 1:
        "Person" "This"
    if randomtest == 2:
        "You think to yourself, hmmm."
But that's clearly horrible.

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#21 Post by Watercolorheart »

Well, if that's how I have to do it ... I'll do it.
I'm not even the same person anymore

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#22 Post by JQuartz »

Showsni wrote:I see what you want.
Man, I still can't see what he wants. I wonder if I can absorb some of your ability...
BCS wrote:In other words, I'm trying to set up dialogue within the original renpy.random.choices, but not a new one ...

renpy.random.choices = [('\"Person\" \"This.\"', '\"Person\" \"That.\"', 'You stop, bored.', 'You think to yourself, Hmm!'])
I still don't understand what you want but here a wild guess.

Code: Select all

    $ randomappearance = renpy.random.choice(['BCS says "I am cute and slender"', 'BCS says "I am going to pull all my hair out"', 'BCS says "I am having some programming trouble"'])
        " %(randomappearance)s"
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#23 Post by Watercolorheart »

JQuartz wrote:he
Try again ...
I still don't understand what you want but here a wild guess.

Code: Select all

    $ randomappearance = renpy.random.choice(['BCS says "I am cute and slender"', 'BCS says "I am going to pull all my hair out"', 'BCS says "I am having some programming trouble"'])
        " %(randomappearance)s"
It can't have 'says' or " " inside the description. That's not how the dialogue in Always Darkest Before Dawn works ...

It works like this:
Attachments
Dialogueexample.JPG
I'm not even the same person anymore

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Renpy random integer and unbound random choices

#24 Post by Showsni »

If you type "Person" "Hello!" you'll get "Hello!" as said by the "Person" (with the Person appearing in a text box, like a normal character.)
renpy.random.choice returns an element from the list given; but can we make that include text and the person saying it? Say, you wanted to get a random one of
"I think long and hard."
"Person" "Hi!"
eileen "Hello."
show giraffe
out of a random choice; is that possible?

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#25 Post by JQuartz »

Showsni wrote:If you type "Person" "Hello!" you'll get "Hello!" as said by the "Person" (with the Person appearing in a text box, like a normal character.)
renpy.random.choice returns an element from the list given; but can we make that include text and the person saying it? Say, you wanted to get a random one of
"I think long and hard."
"Person" "Hi!"
eileen "Hello."
show giraffe
out of a random choice; is that possible?
I don't think it possible but you can fake it by using \n like so:

Code: Select all

    $ randomappearance = renpy.random.choice(['BCS\nI am cute and slender', 'BCS\nI am going to pull all my hair out', 'BCS\nI am having some programming trouble'])
        "%(randomappearance)s"
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Dusty
Regular
Posts: 126
Joined: Fri Jul 25, 2008 11:51 pm
Contact:

Re: Renpy random integer and unbound random choices

#26 Post by Dusty »

Most things you'd want to do with this should be possible with eval(), which will execute a function even if it's in quotation marks.

Code: Select all

init:
   $ eileen = Character("Eileen")
   $ narrator = Character(" ")
   $ person = Character("Person")

label start:
   $ choices = ["narrator('I think long and hard')", "person('Hi!')", "eileen('Hello.')"]
   $ eval(renpy.random.choice(choices))
I don't think eval() works with renpy.show() [?] because trying that gave me a traceback; however, just text should be fine with this...

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#27 Post by JQuartz »

JQuartz wrote:I don't think it possible but you can fake it by using \n like so:
Thanks Dusty, I stand corrected.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#28 Post by Watercolorheart »

Thanks for the discussion, everyone. I hope this benefits someone. Instead of only using some of the fixes, I'm going to try all of them to see how they work.
Dusty wrote:Most things you'd want to do with this should be possible with eval(), which will execute a function even if it's in quotation marks.

Code: Select all

init:
   $ eileen = Character("Eileen")
   $ narrator = Character(" ")
   $ person = Character("Person")

label start:
   $ choices = ["narrator('I think long and hard')", "person('Hi!')", "eileen('Hello.')"]
   $ eval(renpy.random.choice(choices))
I don't think eval() works with renpy.show() [?] because trying that gave me a traceback; however, just text should be fine with this...
This one is strange. This one definitely works, but then it prints this line of code to the player.

$ choices = ["narrator('I think long and hard')", "person('Hi!')", "eileen('Hello.')"] It will go into an infinite loop, repeating the random choice and then the line of code after it.

There's another error not related to the above, but I have NO idea what is causing it ... I get a traceback error when I quit saying there is no yes-no prompt from common.

More specifically:

Code: Select all

I'm sorry, but an exception occurred while executing your Ren'Py
script.

AttributeError: Layout instance has no attribute 'yesno_prompt'

While running game code:
 - script at line 9 of F:\Ren'Py\Always Darkest Before Dawn\renpy-6.8.1\Erotest/game/script.rpy
 - script at line 32 of renpy-6.8.1/common/00menus.rpy
 - python at line 32 of renpy-6.8.1/common/00menus.rpy.
I'm not even the same person anymore

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#29 Post by JQuartz »

Strange, I used the code you gave and it worked without a problem. Maybe the problem was after the set of codes. What is after this?
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Renpy random integer and unbound random choices

#30 Post by PyTom »

That error is due to not calling theme.roundrect() or one of the other theme functions in init code.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Google [Bot], Kocker