Replying through dialogue/ Artificial Intelligence based

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Replying through dialogue/ Artificial Intelligence based

#1 Post by isobellesophia » Mon Jan 27, 2020 7:19 am

Hello everyone.

Since many people asked about typed in coversation, i wanted to share it all of you.
This is called a typed in conversation or simply known as reply the character through dialogues.

This can be used in specific ways denpending on your game.
Note this is made by me, i hope this haven't been made yet, or maybe made it just today.

This also been familiarized to DDLC game named Monika's After Story or like that.
Maybe that is where you can speak to her whatever it is.
Note i didn't copied it, i made this by myself.

First, copy this. (Whatever where you want.)

Code: Select all

define user_input=[]
And then, this.

Code: Select all

label user:
    $ user_input = renpy.input(prompt = "Type anything you want!", allow="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ /.,'?!")

    $ user_input=user_input.lower().strip()

    if user_input == "": #This will happen if there's no input.

        a "You didn't type anything! You have to ask a question first."

        jump user
If didn't type anything, the character may insist you to write anything. But lazy to manage this code so i decided to put that instead.

Here is the main one, where what word you should type in, the Charac will talk back at you.

Code: Select all

if user_input in ['Hello!', 'Hello', 'hello!', 'hello']:
    ###Put it in like...
    a "Oh hi! How are you?"
    jump user
Whenever the character finishes talking, it will lead back to the label user, to talk something else more.

To make it more advanced, here it is, if you want to put more of them.

Code: Select all

if user_input in ['Hello!', 'Hello', 'hello!', 'hello']:
    ###Put it in like...
    a "Oh hi! How are you?"
    jump user
    
    elif user_input in ['I love you!', 'I love you', 'i love you!', 'i love you']:
    a "I love you too! Hugs and kisses! <3"
    jump user
    
    ....And so on.

This is special, if you didnt implement a keyword, the character will say this instead...
(Note, make sure to PLACE this one in the very bottom of the labels above, or else it may break the dialogues.)

Code: Select all

label untype:
    $ randdiag = renpy.random.randint(1, 10)
    show m think with dissolve
    if randdiag == 1:
        a "That word is invalid..."
        jump user
    elif randdiag == 2:
        a "Wywisjdow is not a word!"
        jump user
It can be also indicated by date, month, and also hour!

Code: Select all

init:
    $ import time
    $ year, month, day, hour, minute, second, dow, doy, dst = time.localtime()

Code: Select all

if user_input in ['What time is it?','what time is it?']:
        show a normal with dissolve
        a "The current time is [hour]: [minute]: [second]."
        jump user

Code: Select all

if month == 12 and day == 25:
        if user_input in ['Merry christmas!','merry christmas!','merry christmas','Merry christmas','Merry christmas alia!','merry christmas alia!','merry christmas alia','Merry christmas alia','Merry christmas Alia!','merry christmas Alia!','merry christmas Alia','Merry christmas Alia']:
            show a happyclosed with dissolve
            a "Merry christmas too [name]! Its good to talk to you this season!"
            jump user

    else:
        if user_input in ['Merry christmas!','merry christmas!','merry christmas','Merry christmas','Merry christmas alia!','merry christmas alia!','merry christmas alia','Merry christmas alia','Merry christmas Alia!','merry christmas Alia!','merry christmas Alia','Merry christmas Alia']:
            show a concerned with dissolve
            a "Umm.. i think its not christmas yet, you can wait."
            jump user

Also, a specifical answering.

Code: Select all

default goodmorning = False

Code: Select all

if user_input in ['Good morning','good morning','good morning!','Good morning!']:
        $ goodmorning = True
        show a happyclosed with dissolve
        a "Good morning! Have you drank some water before you wake up? Say yes if you are."
        jump user

    if goodmorning:
        if user_input in ['yes!','yes','Yes!','Yes']:
            show a normal 2 with dissolve
            a "Very good! Keep doing on that, so you will be stay hydrated."
            $ goodmorning = False
            jump user

        if user_input in ['no','No','Nope','nope','not yet','Not yet']:
            show a think with dissolve
            a "I see, then drink alot of it, it is recommended everyday!"
            $ goodmorning = False
            jump user
It will be set to False after, so that the character wont speak it again and again.

And finally, a randomize conversation, this makes the character bit bored when you didn't type anything, the character will give you advices, game guides... etc...

Code: Select all

if user_input in ['random','Random']:
 $ randadvice = renpy.random.randint(1, 20) 
 show a normal 2 with dissolve 
 if randadvice == 1: 
 a "I really love candies, you know?" 
 jump user 
 elif randadvice == 2: 
 a "Come on, say anything, ask anything!" 
 jump user 
 elif randadvice == 3: 
 a "Hmm? Whaddaya keep staring at me?" 
 jump user 
 elif randadvice == 4: 
 a "Im bored, wanna talk something?" 
 jump user 
 else:
 a "How are you? Anything to do?" 
 jump user
(Sorry for the line indention, i was in my tab.)

I hope you find it helpful to use it, i made alot of effort on doing it.
Have fun coding!
Last edited by isobellesophia on Sat May 02, 2020 5:45 am, edited 3 times in total.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
HotMango
Regular
Posts: 27
Joined: Wed Jan 15, 2020 10:36 pm
Skype: aboodal3deny
Contact:

Re: Replying through dialogue

#2 Post by HotMango » Mon Jan 27, 2020 4:25 pm

Wow
This is so helpful, it could be added in a visual novel but to make it more realistic that would take time.
Thank you so much!

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue

#3 Post by isobellesophia » Tue Jan 28, 2020 11:45 am

I will be giving a example script soon, so newbies will be followed step by step, thanks for using.
I am a friendly user, please respect and have a good day.


Image

Image


verysunshine
Veteran
Posts: 328
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#4 Post by verysunshine » Wed Mar 25, 2020 5:49 pm

If a string is modified with .lower, all capital letters become lower case. Besides that, this looks like some very useful code.

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#5 Post by isobellesophia » Sat May 02, 2020 5:42 am

I added a random conversation when the user types 'random/Random' here it is.

Code: Select all

if user_input in ['random','Random']:
        $ randadvice = renpy.random.randint(1, 20)
        show a normal 2 with dissolve
        if randadvice == 1:
            a "I really love candies, you know?"
            jump user
        elif randadvice == 2:
            a "Come on, say anything, ask anything!"
            jump user
        elif randadvice == 3:
            a "Hmm? Whaddaya keep staring at me?"
            jump user
        elif randadvice == 4:
            a "Im bored, wanna talk something?"
            jump user
        else:
            a "How are you? Anything to do?"
            jump user
I considered this by giving user a guide, random events, or maybe etc...
Have fun!
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Paul Kinsella
Regular
Posts: 27
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#6 Post by Paul Kinsella » Mon May 18, 2020 3:20 am

This might be what I've been looking for. :D Unfortunately I've not been able to get it to work. Below is an example I've created. Any idea why it does not function?

Code: Select all

define user_input=[]
image office = "office1.jpg"
label start:
    scene office
    "Welcome!"
label user:
    $ user_input = renpy.input(prompt = "Type anything you want!", allow="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ /.,'?!")
    $ user_input=user_input.lower().strip()
    if user_input == "": #This will happen if there's no input.
        "You didn't say anything. You must be the strong siolent type."
        jump user
if user_input in ['hello','Hello','hi','Hi','howdy','Howdy','yo','Yo']:
        "Hi. Do you want to ask me anything?"
        jump user
    elif user_input in ['cow','cows','Cows','Cow','milk','Milk']:
        "That is not my cow."
        jump user
    elif user_input in ['sword of power','Sword of Power']:
        "What!?!?!??!"
        jump sword
label sword:
    "You know of the sword of power? You must be the 'chosen one' bla bla bla..."
    "The End"
    return

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#7 Post by isobellesophia » Mon May 18, 2020 3:34 am

I want to ask, what is the error? And could you be specific why it doesn't function? I would like to know if i can fix this.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Paul Kinsella
Regular
Posts: 27
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#8 Post by Paul Kinsella » Mon May 18, 2020 6:22 am

isobellesophia wrote:
Mon May 18, 2020 3:34 am
I want to ask, what is the error? And could you be specific why it doesn't function? I would like to know if i can fix this.
I get this error:

Parsing the script failed.
File "game/script.rpy", line 15: indentation mismatch.


line 15 is "elif user_input in ['cow','cows','Cows','Cow','milk','Milk']:"

I think you can test my code for yourself if you replace "office1.jpg" with any background of your choosing.
Last edited by Paul Kinsella on Mon May 18, 2020 6:25 am, edited 1 time in total.

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#9 Post by isobellesophia » Mon May 18, 2020 6:25 am

Check your indention lines in 4 spaces.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#10 Post by isobellesophia » Mon May 18, 2020 6:26 am

To be specific, the if and the elif must be lined up perfectly.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Paul Kinsella
Regular
Posts: 27
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#11 Post by Paul Kinsella » Mon May 18, 2020 6:49 am

I changed my code to this...

Code: Select all

define user_input=[]
image office = "office1.jpg"
label start:
    scene office
    "Welcome!"
label user:
    $ user_input = renpy.input(prompt = "Type anything you want!", allow="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ /.,'?!")
    $ user_input=user_input.lower().strip()
    if user_input == "": #This will happen if there's no input.
        "You didn't say anything. You must be the strong siolent type."
        jump user
if user_input in ['hello','Hello','hi','Hi','howdy','Howdy','yo','Yo']:
        "Hi. Do you want to ask me anything?"
        jump user
elif user_input in ['cow','cows','Cows','Cow','milk','Milk']:
        "That is not my cow."
        jump user
elif user_input in ['sword of power','Sword of Power']:
        "What!?!?!??!"
        jump sword
label sword:
    "You know of the sword of power? You must be the 'chosen one' bla bla bla..."
    "The End"
    return
And got this error...

Code: Select all

I'm sorry, but an uncaught exception occurred.

While loading <'Image' u'office1.jpg'>:
  File "game/script.rpy", line 5, in script
    "Welcome!"
  File "renpy/common/000window.rpy", line 98, in _window_auto_callback
    _window_show()
  File "renpy/common/000window.rpy", line 60, in _window_show
    renpy.with_statement(trans)
IOError: Couldn't find file 'office1.jpg'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 5, in script
    "Welcome!"
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\ast.py", line 671, in execute
    statement_name("say")
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\ast.py", line 45, in statement_name
    i(name)
  File "renpy/common/000window.rpy", line 98, in _window_auto_callback
    _window_show()
  File "renpy/common/000window.rpy", line 60, in _window_show
    renpy.with_statement(trans)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\exports.py", line 1601, in with_statement
    return renpy.game.interface.do_with(trans, paired, clear=clear)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 2251, in do_with
    clear=clear)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 2702, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 3194, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\core.py", line 2094, in draw_screen
    renpy.config.screen_height,
  File "renpy/display/render.pyx", line 490, in renpy.display.render.render_screen (gen\renpy.display.render.c:6805)
    rv = render(root, width, height, st, st)
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "renpy/display/render.pyx", line 166, in renpy.display.render.render (gen\renpy.display.render.c:4075)
    cpdef render(d, object widtho, object heighto, double st, double at):
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\transition.py", line 360, in render
    bottom = render(self.old_widget, width, height, st, at)
  File "renpy/display/render.pyx", line 166, in renpy.display.render.render (gen\renpy.display.render.c:4075)
    cpdef render(d, object widtho, object heighto, double st, double at):
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "renpy/display/render.pyx", line 166, in renpy.display.render.render (gen\renpy.display.render.c:4075)
    cpdef render(d, object widtho, object heighto, double st, double at):
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "renpy/display/render.pyx", line 166, in renpy.display.render.render (gen\renpy.display.render.c:4075)
    cpdef render(d, object widtho, object heighto, double st, double at):
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "accelerator.pyx", line 110, in renpy.display.accelerator.transform_render
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\image.py", line 500, in render
    return wrap_render(self.target, width, height, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\image.py", line 306, in wrap_render
    rend = render(child, w, h, st, at)
  File "renpy/display/render.pyx", line 166, in renpy.display.render.render (gen\renpy.display.render.c:4075)
    cpdef render(d, object widtho, object heighto, double st, double at):
  File "renpy/display/render.pyx", line 259, in renpy.display.render.render (gen\renpy.display.render.c:3520)
    rv = d.render(widtho, heighto, st, at)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\im.py", line 583, in render
    return cache.get(self, render=True)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\im.py", line 266, in get
    surf = image.load()
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\display\im.py", line 628, in load
    surf = renpy.display.pgrender.load_image(renpy.loader.load(self.filename), self.filename)
  File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\loader.py", line 576, in load
    raise IOError("Couldn't find file '%s'." % name)
IOError: Couldn't find file 'office1.jpg'.

Windows-8-6.2.9200
Ren'Py 7.3.5.606
isobellesophia typed in conversation 1.0
Mon May 18 05:39:41 2020

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#12 Post by isobellesophia » Mon May 18, 2020 6:59 am

You need to make a path for the image specificily.

Code: Select all

image office = "images/office.jpg"
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Paul Kinsella
Regular
Posts: 27
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#13 Post by Paul Kinsella » Mon May 18, 2020 11:46 pm

I removed the image to simplify the code. Now it SHOULD work. But the game ends if you type in "hi there" or "nice cow" rather then just "hi" or "cow". The game also ends if you type gibberish "dhfjjstybh4" or something not listed such as "I'm a brave knight looking for a magical weapon?". It would be nice if the player could say anything with "cow" in the sentence, such as "You have a nice cow." and have it go to "That is not my cow." :)

Code: Select all

define user_input=[]
label start:
    scene
    "Welcome!"
label user:
    $ user_input = renpy.input(prompt = "Type anything you want!", allow="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ /.,'?!")
    $ user_input=user_input.lower().strip()
    if user_input == "": #This will happen if there's no input.
        "You didn't say anything. You must be the strong siolent type."
        jump user
if user_input in ['hello','Hello','hi','Hi','howdy','Howdy','yo','Yo']:
        "Hi. Do you want to ask me anything?"
        jump user
elif user_input in ['cow','cows','Cows','Cow','milk','Milk']:
        "That is not my cow."
        jump user
elif user_input in ['sword of power','Sword of Power']:
        "What!?!?!??!"
        jump sword
        label sword:
        "You know of the sword of power? You must be the 'chosen one' bla bla bla..."
        "The End"
        return

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#14 Post by isobellesophia » Tue May 19, 2020 12:40 am

Paul Kinsella wrote:
Mon May 18, 2020 11:46 pm
I removed the image to simplify the code. Now it SHOULD work. But the game ends if you type in "hi there" or "nice cow" rather then just "hi" or "cow". The game also ends if you type gibberish "dhfjjstybh4" or something not listed such as "I'm a brave knight looking for a magical weapon?". It would be nice if the player could say anything with "cow" in the sentence, such as "You have a nice cow." and have it go to "That is not my cow." :)

Code: Select all

define user_input=[]
label start:
    scene
    "Welcome!"
label user:
    $ user_input = renpy.input(prompt = "Type anything you want!", allow="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ /.,'?!")
    $ user_input=user_input.lower().strip()
    if user_input == "": #This will happen if there's no input.
        "You didn't say anything. You must be the strong siolent type."
        jump user
if user_input in ['hello','Hello','hi','Hi','howdy','Howdy','yo','Yo']:
        "Hi. Do you want to ask me anything?"
        jump user
elif user_input in ['cow','cows','Cows','Cow','milk','Milk']:
        "That is not my cow."
        jump user
elif user_input in ['sword of power','Sword of Power']:
        "What!?!?!??!"
        jump sword
        label sword:
        "You know of the sword of power? You must be the 'chosen one' bla bla bla..."
        "The End"
        return

That's because of this.

Code: Select all


label untype: 
$ randdiag = renpy.random.randint(1, 10) 
show m think with dissolve 
if randdiag == 1: 
a "Random words." 
jump user 
elif randdiag == 2: 
a "Wywisjdow is not a word!" 
jump user

Read the example of my post above carefully, this one would appear if the words aren't listed in the codes.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Paul Kinsella
Regular
Posts: 27
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Replying through dialogue/ Artificial Intelligence based

#15 Post by Paul Kinsella » Tue May 19, 2020 2:10 am

isobellesophia wrote:
Tue May 19, 2020 12:40 am
Read the example of my post above carefully, this one would appear if the words aren't listed in the codes.
I have read your example serval times and attempted to run it. Unfortunately I do not have the skills (yet) to understand. The best I could do was make my example as you see it. Could I trouble you to alter the example so I (and other new coders) can better understand what you want to explain. :D

Post Reply

Who is online

Users browsing this forum: No registered users