I try to code like that
Code: Select all
init python:
import fight
Instance = fight.Fight("xml/be.xml")
Code: Select all
init:
image bg gh = "images/golden_horn.jpg"
Code: Select all
init python:
import fight
Instance = fight.Fight("xml/be.xml")
Code: Select all
init:
image bg gh = "images/golden_horn.jpg"
Code: Select all
init python:
import fight
Instance = fight.Fight(renpy.loader.transfn("xml/be.xml"))
http://lemmasoft.renai.us/forums/viewto ... 7&#p380566PyTom wrote:renpy.loader.transfn is not a documented API. Don't use it.
As mukashi apparently want to pass the relative path of a file to an external python package ("xml/be.xml", "fight") and renpy.file(fn) returns a read-only file-like object:PyTom wrote:The right way to open a file is renpy.file.
In my case it's pyAIML, an interpreter for AIML (the Artificial Intelligence Markup Language), implemented entirely in standard Python. It's normally used for chatterbots or 'semi-intelligent' desktop utilities.PyTom wrote:What python package is it? Most take file-like objects instead of or in addition to filenames.
I quick test shows that it seems to work from within RenPy, at least on my Linux machine (Eileens response in the screenshot below was generated by pyAIML and a freely available AIML set):PyTom wrote:If you really want a real path, you can try os.path.join(config.gamedir, "myfile.xml"). But that will break on iOS and Android, and if you archive the file, etc...
Karl_C this is awesome, could you please share a demo for ren'py - pyAIML integration? I really want a chatbot /digital assistant in Ren'py and I've been trying to run pyAIML from within ren'py without success.
A big, fat warning: As I'm not a Python programmer, I'm quite sure that there are much better ways to do it. But if you only want a working example, here you are:Asahel wrote: Karl_C this is awesome, could you please share a demo for ren'py - pyAIML integration? I really want a chatbot /digital assistant in Ren'py and I've been trying to run pyAIML from within ren'py without success.
Code: Select all
# You can place the script of your game in this file.
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
define e = Character('Eileen', color="#ffffff")
init:
$ import AIMLBot
# The game starts here.
label start:
e "This is a test of pyAIML from within RenPy"
$ renpy.free_memory()
$ user_input =[]
while True:
$ user_input = renpy.input("Type some input")
$ user_input = user_input.strip()
$ response = AIMLBot.AimlBot().run(user_input)
if user_input == "quit":
jump End_of_loop
e "[response]"
label End_of_loop:
e "End of loop"
return
Code: Select all
import aiml
import os.path
import sys
class AimlBot:
brainFileName = "standard.brn"
kernel = aiml.Kernel()
botName = "Eileen"
def __init__(self):
self.kernel.verbose(False)
self.kernel.setBotPredicate("name", self.botName)
if os.path.isfile(self.brainFileName):
self.kernel.bootstrap(brainFile = self.brainFileName)
else:
self.kernel.bootstrap(learnFiles = "std-startup.xml", commands = "load aiml b")
self.kernel.saveBrain(self.brainFileName)
# runs bot on input and returns answer
def run(self, inputString):
answer = self.kernel.respond(inputString) # second argument is string
#self.kernel.saveBrain(self.brainFileName)
return answer
Code: Select all
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd4 in position 47219: invalid continuation byte
It does not find files like 'game/script.rpy':
So I have to ridiculously strip a part of the filename like this:File "game/screens.rpy", line 1445, in <module>
with renpy.file(fn) as f:
IOError: Couldn't find file 'game/script.rpy'.
Code: Select all
screen this_script():
default fn = renpy.get_filename_line()[0]
python:
if fn[0:5] == "game/":
fn = fn[5:]
with renpy.file(fn) as f:
lines = f.readlines()
Users browsing this forum: No registered users