Parsing non Python code in the scripting?

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.
Post Reply
Message
Author
Arq
Newbie
Posts: 3
Joined: Wed Dec 08, 2021 6:42 am
Contact:

Parsing non Python code in the scripting?

#1 Post by Arq »

To begin with, I have minimal experience in working with Python. As a matter of fact, I could probably not do most basic operations, because, as I attempt to learn anything, it makes me wish I was using my native programming tongue instead, Forth. It is probably a confusing and backwards language to anyone who comes to it after learning any other language, but it has become my personal preference in using it now. By random chance, I had located a Forth language parser written in Python, which would allow any Python based environment to read Forth code. It's called forth-py and can be found here, open sourced on Github.

It is a little rough around the edges but it is basically what I wanted in bridging the gap in between languages. I tweaked it slightly to fit my needs, although not completely functional in the way I want yet, it is in some state usable. Great, right? Well, not quite, because I haven't quite been able to figure out how to make RenPy itself parse this parser. I attempted importing the relevant code and declaring the import as python code beforehand, but it gives me this error:

Code: Select all

Traceback (most recent call last):
  File "renpy/common/00console.rpy", line 689, in run
    renpy.python.py_exec(code)
  File "renpy/python.py", line 2258, in py_exec
    exec(py_compile(source, 'exec'), store, locals)
  File "<none>", line 1, in <module>
  File "renpy/loader.py", line 985, in load_module
    exec(code, mod.__dict__)
  File "forthmain.py", line 1, in <module>
  File "renpy/loader.py", line 985, in load_module
    exec(code, mod.__dict__)
  File "lexer.py", line 2, in <module>
ImportError: cannot import name ForthException
The definition of ForthException being:

Code: Select all

class ForthException(Exception):
    def forth__init__(self, msg):
        self.msg = msg

    def forth__str__(self):
        return self.msg
Why is it unable to import this?

Yes, I'm aware it would be faster and easier to learn Python and the scripting of RenPy, and write my code in that. I suspect however if I'm not doing this in a way I enjoy, then it won't be enjoyed. And having to learn a new language entirely would curbstomp my enjoyment.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Parsing non Python code in the scripting?

#2 Post by enaielei »

Ren'Py still uses Python 2.7, your library is based on 3.5.

Arq
Newbie
Posts: 3
Joined: Wed Dec 08, 2021 6:42 am
Contact:

Re: Parsing non Python code in the scripting?

#3 Post by Arq »

OK, so what does that mean for me? Is there a way to backport the code to the older version?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2404
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Parsing non Python code in the scripting?

#4 Post by Ocelot »

Arq wrote: Wed Dec 08, 2021 7:53 am OK, so what does that mean for me? Is there a way to backport the code to the older version?
Short of rewriting it from scratch — no.

There are pretty radical changes between Python 2 and Python 3. This is why process of porting RenPy to Python 3 is still not finished: it is a massive undertaking.
< < insert Rick Cook quote here > >

Arq
Newbie
Posts: 3
Joined: Wed Dec 08, 2021 6:42 am
Contact:

Re: Parsing non Python code in the scripting?

#5 Post by Arq »

Ocelot wrote: Wed Dec 08, 2021 8:01 am
Arq wrote: Wed Dec 08, 2021 7:53 am OK, so what does that mean for me? Is there a way to backport the code to the older version?
Short of rewriting it from scratch — no.

There are pretty radical changes between Python 2 and Python 3. This is why process of porting RenPy to Python 3 is still not finished: it is a massive undertaking.
OK. It is a small repository, so I suspect doing so would not be terribly any difficult for anyone intermediately skilled. Maybe I should start looking into it myself.

User avatar
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 non Python code in the scripting?

#6 Post by PyTom »

Note that you're going to run into a lot of problems. Ren'Py does a lot of things to support load, save, and rollback, and those will likely not work here.
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: AdsBot [Google], Google [Bot], Ocelot, snotwurm