Complex data structures of Python with Ren'py
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.
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.
Complex data structures of Python with Ren'py
Hi guys:
I'm planning to make a game with Ren'py. I already have some experience with python so I was wondering if it is possible to use data structures such as lists, dictionaries and classes to store values in my Ren'py game, if so how would I use these data structures?
I was also wondering how would you implement loops such as for loops or while loops with Ren'py? If someone could provide simple examples to demonstrate and hence answer my questions that would be lovely and I would really appreciate it.
Thank you
I'm planning to make a game with Ren'py. I already have some experience with python so I was wondering if it is possible to use data structures such as lists, dictionaries and classes to store values in my Ren'py game, if so how would I use these data structures?
I was also wondering how would you implement loops such as for loops or while loops with Ren'py? If someone could provide simple examples to demonstrate and hence answer my questions that would be lovely and I would really appreciate it.
Thank you
- TrickWithAKnife
- Eileen-Class Veteran
- Posts: 1261
- Joined: Fri Mar 16, 2012 11:38 am
- Projects: Rika
- Organization: Solo (for now)
- IRC Nick: Trick
- Location: Tokyo, Japan
- Contact:
Re: Complex data structures of Python with Ren'py
I'm not even a beginner at Python, but I've managed to import some Python code (including dictionaries) into my renpy projects.
So the answer is yes, you can import some Python code, but as for how, I couldn't make any recommendations. I just hammer it in, and hope I can figure out the error messages long enough to get it working.
Just make sure you precede the python code with:
And import whatever you need (which may be common for python anyway):
Regarding using while, check out this link:
http://www.renpy.org/wiki/renpy/doc/ref ... _Statement
Using for, I *think* it's something like this:
So the answer is yes, you can import some Python code, but as for how, I couldn't make any recommendations. I just hammer it in, and hope I can figure out the error messages long enough to get it working.
Just make sure you precede the python code with:
Code: Select all
init python:
## Whatever your code is here"Code: Select all
import stringhttp://www.renpy.org/wiki/renpy/doc/ref ... _Statement
Using for, I *think* it's something like this:
Code: Select all
for i in whatever_your_maximum_variable_is:
# Do whatever you want
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.
Re: Complex data structures of Python with Ren'py
Yup, you can import everything (or almost everything? I don't know if there are limitations) the same way you normally would under that "init python:" TrickWithAKnife mentioned. Lists, dictionaries, and classes are all included, so you don't have to import those.
- PyTom
- Ren'Py Creator
- Posts: 15893
- 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: Complex data structures of Python with Ren'py
The while loop is just in Ren'Py:GlacyR24 wrote:I was also wondering how would you implement loops such as for loops or while loops with Ren'py? If someone could provide simple examples to demonstrate and hence answer my questions that would be lovely and I would really appreciate it.
Code: Select all
while python_expression:
"Going through the loop."
$ python_statement
Code: Select all
python:
for i in my_list:
do_something_with(i)
Code: Select all
$ j = 0
while j < len(my_list):
$ i = my_list[j]
"The list contains [i]."
$ j += 1
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
Who is online
Users browsing this forum: Bing [Bot]
