rakugoteam / Rakugo-Dialogue-System

Inspired by Ren'Py, Rakugo is a project aiming to provide a way to make narrative-based games on Godot easily. Simplify your project, if it is a visual novel, point and click, RPG, interactive text game or many other styles and blends of styles.
https://rakugoteam.github.io
MIT License
222 stars 7 forks source link

Rakugo.parser_add_regex_at_runtime() don't work #146

Closed Jeremi360 closed 1 year ago

Jeremi360 commented 1 year ago

@theludovyc I have problem with Rakugo.parser_add_regex_at_runtime(): Here is my code:

extends Node

func _ready():
    Rakugo.parser_add_regex_at_runtime("show", "^show\\s+(?<layers>[{NAME}\\s+])\n")
    Rakugo.parser_add_regex_at_runtime("hide", "^hide\\s+(?<layers>[{NAME}\\s+])\n")
    Rakugo.connect("parser_unhandled_regex", self, "_on_parser_unhandled_regex")

func _on_parser_unhandled_regex(key: String, result: RegExMatch):
    prints(key, result)

and in RkScript I added:

    show test show
    hide test hide

But nothing is printed and rest of script executes with out any problems. I also try using \\s+(?<layers>[a-zA-Z0-9_s]+) or even .+ instead of {NAME} and still nothing in output. What I'm doing wrong ?

Jeremi360 commented 1 year ago

even if I added prints() to check it in parser it self it didn't print any thing :/ even if I added ! or @ before show and hide:

_:
    prints("Unhandled regex: ", line[0], result)
    Rakugo.emit_signal("parser_unhandled_regex", line[0], result)
Jeremi360 commented 1 year ago

it seam like parser don't see show and hide at all - I thouthg that maybe it was intercepted by another regex, however, when he added prints to the parser, nothing appeared with it. Here is part of my Rkscript:

hello_world
character test_ch "Test Character"
first_dialogue:
    "Hello, world !"
    show test show
    hide test hide
jump menu_emily
menu menu_emily:
    "Talk with emily" > emily_talk
    "Wait"
    "Blop" > test_dialog

and here is result from console:

CHARACTER_DEF: character test_ch "Test Character"
SAY: "Hello, world !"
JUMP: jump menu_emily
MENU: menu menu_emily:
SAY: "How are you ?"
theludovyc commented 1 year ago

Hello :) !

I use https://regex101.com/ to test Regex. I like possibility to hover tokens and explanations on right.

If I try "^show\s+(?\[a-z]\s+)\n" with "show test show" not works.

Use a "\n" is not good, it wait a carriage return and a new line.

Use "\s+" inside group is not good too.

Maybe you can test with "^show (?\{NAME})$", it works with "show test". You have some exemples of regex in Parser.gd.

$ for waiting end of line. Something like \n but it did not wait carriage return or new line. It is better.

Jeremi360 commented 1 year ago

I use https://regex101.com/ to test Regex. I like possibility to hover tokens and explanations on right.

I use this one https://regexr.com

If I try "^show\s+(?[a-z]\s+)\n" with "show test show" not works.

Use a "\n" is not good, it wait a carriage return and a new line.

Use "\s+" inside group is not good too.

Maybe you can test with "^show (?{NAME})$", it works with "show test". You have some exemples of regex in Parser.gd.

$ for waiting end of line. Something like \n but it did not wait carriage return or new line. It is better.

Okey I see and I tried this with "^show (?{NAME})$" and as I expeted result is the same :(

CHARACTER_DEF: character test_ch "Test Character"
SAY: "Hello, world !"
JUMP: jump menu_emily
MENU: menu menu_emily:

I want to point out again part that my rkscript look like this:

hello_world # this an unhandled regex
character test_ch "Test Character"
first_dialogue:
    "Hello, world !"
    show test show # unhandled regex
    hide test hide # unhandled regex
jump menu_emily
menu menu_emily:
    "Talk with emily" > emily_talk
    "Wait"
    "Blop" > test_dialog

As you see there are 3 unhandled regexes and one is printed out by debug print I added to parser it self:

_:
    prints("Unhandled regex: ", line[0], result)
    Rakugo.emit_signal("parser_unhandled_regex", line[0], result)
Jeremi360 commented 1 year ago

@theludovyc You were right when I changed my regex to have NAME only in {} without [] then it worked :D But this means also that unfortunately, now there is no error when the script has unsupported regex, do you think it can be solved somehow?

theludovyc commented 1 year ago

@Jeremi360 already handle error image

You regex have no error, is just do not match what you want :)

Jeremi360 commented 1 year ago

@Jeremi360 already handle error image

You regex have no error, is just do not match what you want :)

@theludovyc No, you totally misunderstood me, I didn't mean a bug in the regex, but that in the example script at the very beginning I had a totally unsupported expression hello_world. I totally didn't notice it until this issue, because I didn't get any error about it and my point is that expressions not registered in the system are ignored instead of giving an error.

theludovyc commented 1 year ago

I think I get it. We have no error when parser read something it do not handle ?

Jeremi360 commented 1 year ago

I think I get it. We have no error when parser read something it do not handle ?

Exactly @theludovyc

theludovyc commented 1 year ago

I opened an issue #149

I think we can close this one