{"id":189,"date":"2017-06-21T02:42:56","date_gmt":"2017-06-21T02:42:56","guid":{"rendered":"https:\/\/www.jasonsblog.place\/?p=189"},"modified":"2017-06-21T02:44:30","modified_gmt":"2017-06-21T02:44:30","slug":"using-rant-in-my-python-program-because-im-a-glutton-for-punishment","status":"publish","type":"post","link":"https:\/\/www.jasonsblog.place\/index.php\/2017\/06\/21\/using-rant-in-my-python-program-because-im-a-glutton-for-punishment\/","title":{"rendered":"Using Rant in my Python program because I&#8217;m a glutton for punishment"},"content":{"rendered":"<p>Over the past few months, I have been researching and developing a little <a href=\"https:\/\/www.jasonsblog.place\/index.php\/2017\/04\/26\/trying-my-hand-at-making-a-system-for-procedurally-generating-stories\/\">procedurally generated game<\/a> which will eventually be created in the <a href=\"https:\/\/godotengine.org\/\">Godot engine<\/a>. This game will have a story that&#8217;s procedurally generated for the players. A part of this game is the dialogue, which will also be procedurally generated. To accomplish this, I set out to find a library of some kind which can create procedurally generated dialogue (or at least the dialogue that I want) and is written in my programming language of choice, Python. From the looks of it, there isn&#8217;t one, and so I had to look elsewhere. That&#8217;s when I stumbled upon something called <a href=\"http:\/\/berkin.me\/rant\/\">Rant<\/a>. This is billed as a library which can procedurally generate dialogue. At first I thought I had found what I was searching for. Sadly, though, it is written in\u00a0 the least open source-friendly language I have ever seen: C#. This can be used on Linux (with the Mono runtime). But I&#8217;m looking for a solution where I don&#8217;t have to use a bunch of programming languages to achieve what I want.<\/p>\n<p>At first, I tried making some kind of dialogue scheme that would suit my needs. I threw in some sentences of what may define the NPC, and mashed it all together. From the looks of it, though, the scheme is getting out of hand. I have several lines of dialogue, and I&#8217;m not even finished. I don&#8217;t entirely know how I&#8217;ll fit it all together, considering this is just for a <em>simple<\/em> demo of the full game. It looks like I&#8217;m going to have to get creative.<\/p>\n<p>I went digging and searching around I came upon several possible ways of integrating C# code into Python code. There&#8217;s <a href=\"http:\/\/ironpython.net\/\">IronPython<\/a>, a fully implemented version of Python in C#. The big problem with this was that it didn&#8217;t look very portable to me, as I would have to bundle the .NET libraries with the game for each platform, and that&#8217;s a royal pain the ass. Then I looked at <a href=\"http:\/\/pythonnet.github.io\/\">Python.NET<\/a>, which looked very promising: you can call some C# code from Python, and you can call some Python code from C#. It looked like the best of both worlds. Now, actually making it work is a bigger problem.<\/p>\n<p>When I tried to use the <code>Rant.dll<\/code> assembly in my Python program, I found that I can&#8217;t do that because, well, it&#8217;s C# code, and the regular old CPython (which comes with many Linux distributions) can only import C or C++ code. Then I looked into using the <code>clr<\/code> module from Python.NET, but I couldn&#8217;t find a version built for Linux. Through a lot of hand wringing, brow beating, and code cracking, I found that I had to use the latest version of Mono (version 5.0.1) along with an unstable version of Python.NET. This one built with the suggested command: <code>python setup.py build_ext --inplace<\/code>. The built shared object library file, &#8220;clr.so&#8221;, and the &#8220;clr&#8221; module load in Python.\u00a0 Heck, I was even able to load the pre-built &#8220;Rant.dll&#8221;. But this is nothing compared what I must do now: actually making some procedurally generated dialogue with Rant. And I don&#8217;t know where to begin with that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the past few months, I have been researching and developing a little procedurally generated game which will eventually be created in the Godot engine. This game will have a story that&#8217;s procedurally generated for the players. A part of this game is the dialogue, which will also be procedurally generated. To accomplish this, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,76,31],"tags":[94,92,55,24,91,95,77,54,79,93,23],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-fun","category-programming","category-video-games","tag-net","tag-c","tag-design","tag-development","tag-godot-engine","tag-mono","tag-procedural-generation","tag-programming-languages","tag-python","tag-rant","tag-video-game"],"_links":{"self":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":3,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/posts\/189\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasonsblog.place\/index.php\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}