I'm thinking about using an XML file to store a (large) number of values. Then use a parser to convert those data into a [list [of list]]
The tree is something like:
<TREE>
<element>
<NAME>poppy</NAME>
<LEGS>
<feet>1</feet>
<feet>3</feet>
<feet>5</feet>
</LEGS>
</element>
</TREE>
and must return:
$ sillyness=[(poppy,(1,3,5)),...]
for each 'element'.
Being a total noob in parsing stuff, can someone please post a point by point guide to have a game parsing an XML tree?
The guide must include what to download and what to put in the distributable game.
I know about BeautifulSoup, but I'm totally lost with lxml.
Thank you.
Parsing XML [SOLVED o_o]
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.
Parsing XML [SOLVED o_o]
Last edited by gas on Mon Feb 20, 2017 7:49 pm, edited 1 time in total.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.
10 ? "RENPY"
20 GOTO 10
RUN
10 ? "RENPY"
20 GOTO 10
RUN
- SuperbowserX
- Veteran
- Posts: 270
- Joined: Sat Jan 07, 2017 3:09 pm
- Contact:
Re: Parsing XML
Are you trying to make a 2d array? You could use something like this.
https://www.renpy.org/wiki/renpy/doc/co ... _from_file
From there you could study up on the procedure for reading lines from files in Python. Google is your friend!
https://www.renpy.org/wiki/renpy/doc/co ... _from_file
From there you could study up on the procedure for reading lines from files in Python. Google is your friend!
Re: Parsing XML
Hahaha! I was so concerned about importing that lxml thing that I forgot to check the RENPY documentation XD.SuperbowserX wrote:Are you trying to make a 2d array? You could use something like this.
https://www.renpy.org/wiki/renpy/doc/co ... _from_file
From there you could study up on the procedure for reading lines from files in Python. Google is your friend!
Thank you, I think now could be very easy, there's a great documentation for ElementTree.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.
10 ? "RENPY"
20 GOTO 10
RUN
10 ? "RENPY"
20 GOTO 10
RUN
- Ocelot
- Lemma-Class Veteran
- Posts: 2404
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Parsing XML [SOLVED o_o]
Just some points:
1) Do not use renpy.loader.transfn, or anything from renpy.loader. It is not supported. Use renpy.file instead of open+transfn.
2) I prefer JSON over XML. It is more terse, its data structures translates directly to Python ones, there is builtin library to handle it.
1) Do not use renpy.loader.transfn, or anything from renpy.loader. It is not supported. Use renpy.file instead of open+transfn.
2) I prefer JSON over XML. It is more terse, its data structures translates directly to Python ones, there is builtin library to handle it.
< < insert Rick Cook quote here > >
Re: Parsing XML [SOLVED o_o]
Hey, thank you for that hint, I'll try both and I'll see the one I find more comfortable with.Ocelot wrote:Just some points:
1) Do not use renpy.loader.transfn, or anything from renpy.loader. It is not supported. Use renpy.file instead of open+transfn.
2) I prefer JSON over XML. It is more terse, its data structures translates directly to Python ones, there is builtin library to handle it.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.
10 ? "RENPY"
20 GOTO 10
RUN
10 ? "RENPY"
20 GOTO 10
RUN
- PyTom
- Ren'Py Creator
- Posts: 16096
- 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: Parsing XML [SOLVED o_o]
Honestly, unless you have some really special need, just generate a Ren'Py file. You can define objects that are sensible for your game, and use them directly, rather than first having to parse JSON into the format you actually want. (XML is right out.)
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?)
Software > Drama • https://www.patreon.com/renpytom
Who is online
Users browsing this forum: Alex