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.
-
Crazy Li
- Regular
- Posts: 113
- Joined: Fri Jan 03, 2014 3:35 pm
-
Contact:
#1
Post
by Crazy Li » Wed Jan 15, 2014 2:45 am
I was looking at
http://www.renpy.org/dev-doc/html/other ... npy-random to try and generate random floats, but I just don't seem to understand how to properly implement it. I tried copying/pasting code as is:
Code: Select all
$ randfloat = renpy.random.random()
But if I try to display the value of "randfloat" to test, I just get an error message: KeyError: u'randfloat'
If I try to base anything in my script on the value of randfloat, I'm told it's not defined.
If I throw the code from above in init:, I'm told: AttributeError: 'NoneType' object has no attribute 'random'
So yeah... I have no clue what to do with renpy.random. I can't seem to use it for anything at all. Any help?
-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#2
Post
by xela » Wed Jan 15, 2014 5:56 am
Code: Select all
label start:
$ randfloat = renpy.random.random()
"[randfloat]"
This just works, period. You're doing everything right, can you post the code with exactly what you're trying to do?
Like what we're doing? Support us at:

-
Crazy Li
- Regular
- Posts: 113
- Joined: Fri Jan 03, 2014 3:35 pm
-
Contact:
#3
Post
by Crazy Li » Wed Jan 15, 2014 1:59 pm
Yes, I did that exactly and got the KeyError message. Posting from phone, so I can't give more info until I'm home.
-
Unin
- Regular
- Posts: 54
- Joined: Wed Sep 01, 2010 8:08 pm
- Location: Florida
-
Contact:
#4
Post
by Unin » Thu Jan 16, 2014 1:13 am
try pre-declaring randfloat with a hardcoded number (eg 1.2345) and then calling random()
Does it show you the pre-set number, a random number, or the same error?
It may just be that python needs to know randfloat is a float first.
Users browsing this forum: Google [Bot]