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

#31 Post by Watercolorheart » Tue Jan 13, 2009 11:57 pm

PyTom wrote:That error is due to not calling theme.roundrect() or one of the other theme functions in init code.
I see, thank you.

Now, if only I could figure out why eval didn't work ...

My tests also turned up something interesting. If you call the random container again, you will get the same original result that was first called.
So assume $ random1= renpy.random.choice(['1','2','3']) and it calls "3".

Code: Select all

"%(random1)s"
"%(random2)s"
"%(random1)s"
You'd get:

"3"
"something"
"3"

I have a container with over 100 different options so, and it definitely repeats it 1-4 times, no matter how many times I call it, it isn't random once it has already run.

Very frustrating ...
I'm not even the same person anymore

User avatar
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

#32 Post by JQuartz » Wed Jan 14, 2009 12:23 am

You seem to have a lot of coding problems. May I suggest that you just get a coder. Maybe me (currently I'm coding for x_sinister but he gives me work a bit too slow for comfort.) If you want me as a coder, I be glad to code for you but my priority is still x_sinister's project. But that shouldn't be a problem unless he suddenly goes into overdrive. Because I put your project in second priority, you don't need to put me in the credits. And if I give you anything via PM, virus scan it first, because I'm still worried that somebody is hacking into my account (No proof though).
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

#33 Post by Watercolorheart » Wed Jan 14, 2009 12:28 am

I'm not going to give up ... I am going to get this to work the way I want it to if it kills me.
I'm not even the same person anymore

User avatar
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

#34 Post by JQuartz » Wed Jan 14, 2009 12:57 am

BCS wrote:I'm not going to give up ... I am going to get this to work the way I want it to if it kills me
Good for you (the not giving up part not the if it kills me part)
BCS wrote:Now, if only I could figure out why eval didn't work ...
But it worked with mine. I using Renpy version 6.8.1 by the way. I just pasted the code Dusty had given. Maybe there something wrong somewhere else.
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
Dusty
Regular
Posts: 126
Joined: Fri Jul 25, 2008 11:51 pm
Contact:

Re: Renpy random integer and unbound random choices

#35 Post by Dusty » Wed Jan 14, 2009 1:11 am

I have no idea why eval() didn't work for you, because it did for me. Sorry.
BCS wrote: My tests also turned up something interesting. If you call the random container again, you will get the same original result that was first called.
That's supposed to happen.

As you might have figured out,
-warning, kindergarten teacher mode-

Simplest way I know how to explain this:

With pictures... ;D

Right now, random1-box has no value:
#random1[ ]

<renpy.random.choice([1, 2, 3])> spits out a value and then stores it in random1-box:
$ random1 = renpy.random.choice([1, 2, 3])
#<renpy.random.choice> -> 1 -> random1[]


Now, random1-box is 1:
#random1[1]

<r.r.choice()> spits out another value and then stores it in random2-box:
$ random2 = renpy.random.choice([1, 2, 3])
#3<renpy.random.choice> -> 3 -> random2[]


Now, random1-box is still 1, but random2-box is now 2:
#random1[1]
#random2[2]


random1-box does not want to let the value in its box go until the evil del-adventurer takes it away:
$ del random1
#random1[] now has no value. The value'll probably be sold in the market/on eBay :(


random1-box does not want to change its value until the evil = sign tells it to again, so if you keep calling on it to raise its number-hand, it will keep raising the 1 until the = sign comes again to tell it to change its number.
---
Summary: The container (variable) isn't random, the jar it comes out of (renpy.random.choice) is. So if you want random variables every time, you need to do it the long way.

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

#36 Post by Showsni » Wed Jan 14, 2009 1:56 am

Plus renpy.random.choice will give the same values if you rollback and forth over it.

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

#37 Post by Watercolorheart » Wed Jan 14, 2009 1:58 am

$ del random1

Summary: The container (variable) isn't random, the jar it comes out of (renpy.random.choice) is. So if you want random variables every time, you need to do it the long way.


Got it. Thanks. Delete it, roll again, right?
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

#38 Post by Watercolorheart » Wed Jan 14, 2009 4:36 am

I have defeated it! Sort of. It was sloppy, but I managed it. Results in last page of Twilight Princess epilogue beta thread in Hentai Works in Progress and Recruitment.
I'm not even the same person anymore

User avatar
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

#39 Post by JQuartz » Wed Jan 14, 2009 4:40 am

BCS wrote:I have defeated it!
Congratulations! I guess you didn't need a coder after all.
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

#40 Post by Watercolorheart » Wed Jan 14, 2009 4:57 am

Nope, even the worst programmar can conquer problems (if they have solutions) with three simple tactics:

-Save and launch for every major code block, to catch typos that cause traceback errors.
-Once a problem is found, isolate it by deleting irrelevant code and saving it as a second version, then keep on modifying it until it goes away.
-Keep on hunting for code examples or usage, so that bad format doesn't gum everything up.

For example, I know about very little actionscript, but I still manage to make Flash games using lots of tutorials and trial and error.

I have to thank Dusty, though, I couldn't have done it without knowing about $ del command for variables.
I'm not even the same person anymore

User avatar
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

#41 Post by JQuartz » Wed Jan 14, 2009 5:33 am

BCS wrote:Nope, even the worst programmar can conquer problems (if they have solutions) with three simple tactics
You missed out one thing: A strong will. The worst programmer probably end up as the worst cause he gave up too easily unlike you who had a never give up attitude.
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
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Renpy random integer and unbound random choices

#42 Post by Jake » Wed Jan 14, 2009 8:38 am

BCS wrote:Got it. Thanks. Delete it, roll again, right?
You don't even need to delete it, really - just assign a new value over the top and it'll replace what was already there. The distinction is just that the variable will always contain whatever value it was last given, and can't go off and find a new random number on its own - you have to explicitly generate and assign a new random number each time you want it to change.
Server error: user 'Jake' not found

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

#43 Post by Watercolorheart » Wed Jan 14, 2009 10:28 am

Jake wrote:
BCS wrote:Got it. Thanks. Delete it, roll again, right?
You don't even need to delete it, really - just assign a new value over the top and it'll replace what was already there. The distinction is just that the variable will always contain whatever value it was last given, and can't go off and find a new random number on its own - you have to explicitly generate and assign a new random number each time you want it to change.
I think I "got" it by the time I reached the end of my script, instead of copying and pasting gobs of text over. You can use a "call" function to accomplish this repeatedly, right?
I'm not even the same person anymore

User avatar
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

#44 Post by JQuartz » Wed Jan 14, 2009 1:05 pm

BCS wrote: I think I "got" it by the time I reached the end of my script, instead of copying and pasting gobs of text over. You can use a "call" function to accomplish this repeatedly, right?
Yeah. Just remember to add a return at the end of called script.
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

#45 Post by Watercolorheart » Wed Jan 14, 2009 7:21 pm

I wonder if there is any way to prevent a random container from selecting the same thing twice ... ?
I'm not even the same person anymore

Post Reply

Who is online

Users browsing this forum: No registered users