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

how can i change a background or music #196

Closed MRSEEO closed 1 year ago

MRSEEO commented 1 year ago

I want to play music or change a background in a game. Is there any method I can use, or do I need to write the function myself?

Jeremi360 commented 1 year ago

So Rakugo Core is only Dialogue system. For changing graphics and music from Dialogue will be apart on of RKScript extension in Visual Novel Kit, I'm working on it actively is done in 30%, but rest will be easier to implement after I do it for 2D Nodes. But you can easy add your on keywords to RKScript to do this stuff for now, like this for example:

func _ready():
    var id_regex = "([a-zA-Z0-9_])+"
    Rakugo.parser_add_regex_at_runtime("show", "^show (?<id>%s)" %  id_regex )

func _on_parser_unhandled_regex(key:String, result:RegExMatch):
     match(key):
       "show":
           var id = result.get_string("id")
           # here code that show up node you want by shown by this ID

Result of this example is that you can now write show some_id in RKScript, will run code in func _on_parser_unhandled_regex() if keyword is "show". So yes you need first add this music and images as nodes to your scene before you can use them form dialogue script.

MRSEEO commented 1 year ago

So Rakugo Core is only Dialogue system. For changing graphics and music from Dialogue will be apart on of RKScript extension in Visual Novel Kit, I'm working on it actively is done in 30%, but rest will be easier to implement after I do it for 2D Nodes. But you can easy add your on keywords to RKScript to do this stuff for now, like this for example:

func _ready():
  var id_regex = "([a-zA-Z0-9_])+"
  Rakugo.parser_add_regex_at_runtime("show", "^show (?<id>%s)" %  id_regex )

func _on_parser_unhandled_regex(key:String, result:RegExMatch):
     match(key):
       "show":
           var id = result.get_string("id")
           # here code that show up node you want by shown by this ID

Result of this example is that you can now write show some_id in RKScript, will run code in func _on_parser_unhandled_regex() if keyword is "show". So yes you need first add this music and images as nodes to your scene before you can use them form dialogue script.

Thank you so much!

Jeremi360 commented 1 year ago

Thank you so much!

I'm happy to hear that.

MRSEEO commented 1 year ago

Thank you so much!

I'm happy to hear that.

Wow, dude, i tried it and... IT'S SO AWESOME! Rakugo is the best system I've ever seen!

MRSEEO commented 1 year ago

I have other questions. How i can save and load my game? And can i create an UI for this with screenshots of saved scene for save slots? I saw it in VNKit, but VNKit doesn't work properly for me so i can't use it to see how it works.

Sorry if i bother you... but i'm really interested in Rakugo and VNKit.

Jeremi360 commented 1 year ago

Wow, dude, i tried it and... IT'S SO AWESOME! Rakugo is the best system I've ever seen!

I'm very happy to hear that :D

I have other questions. How i can save and load my game? And can i create an UI for this with screenshots of saved scene for save slots? I saw it in VNKit, but VNKit doesn't work properly for me so i can't use it to see how it works.

Sorry if i bother you... but i'm really interested in Rakugo and VNKit.

Yes, sorry about that I know that saves UI in VNKit is broken I need to rewrite it. So you need to make your own UI for this for now. To save game you just use:

Rakugo.save_game(save_name)

This will save all characters and all vars created using Rakugo.set_variable() and Rakugo.set_character_variable() and also all variable created/changed in RKScripts.

To load game save you use

Rakugo.load_game(save_name)

And you do want you need with this data for example load proper godot scene. then to run last script from where save ended you run:

Rakugo.resume_loaded_script()

And to make screen shot in godot you just do:

var screenshot:Image = get_tree().get_root().get_texture().get_data()
screenshot.flip_y() #you need to flip it propably
MRSEEO commented 1 year ago

Everything work properly, but i don't know how to add second variable. Like in RenPy: show bg(first) city(second) I did "show" with color: show colorwhite. And just sliced it to "color" and "white" in the code.

But i'm interested if i can use [] or anything else to do this instead: show color[white] (or) show color$white Because i want to implement system that changes bg or sprite. I don't want to add node to every image i have, it would be messy.

Jeremi360 commented 1 year ago

Everything work properly, but i don't know how to add second variable. Like in RenPy: show bg(first) city(second) I did "show" with color: show colorwhite. And just sliced it to "color" and "white" in the code.

But i'm interested if i can use [] or anything else to do this instead: show color[white] (or) show color$white Because i want to implement system that changes bg or sprite. I don't want to add node to every image i have, it would be messy.

You can use any symbol that you want, I in Visual Novel Kit uses just space, just need to change to your needs:

var id_regex = "([a-zA-Z0-9_])+"

Its use "regular expressions" called "ragex" But in GDScript regex you must use "\" instead of "\". And so for example to use it with " " (space):

var id_regex = "([a-zA-Z0-9_]+ ?)+"
# then in _on_parser_unhandled_regex
var ids = result.get_string("screen").split(" ")
# and now you have array of strings
# array starts it index from 0 so to get first element of array you do:
var first_element = ids[0]
# to check/use all elements of array you can use `for` loop like this:
for id in ids:
  if id == "node that I want to show":

For example here is how I implementing this for VisualNovelKit (it still wip):

MRSEEO commented 1 year ago

Everything work properly, but i don't know how to add second variable. Like in RenPy: show bg(first) city(second) I did "show" with color: show colorwhite. And just sliced it to "color" and "white" in the code. But i'm interested if i can use [] or anything else to do this instead: show color[white] (or) show color$white Because i want to implement system that changes bg or sprite. I don't want to add node to every image i have, it would be messy.

You can use any symbol that you want, I in Visual Novel Kit uses just space, just need to change to your needs:

var id_regex = "([a-zA-Z0-9_])+"

Its use "regular expressions" called "ragex" But in GDScript regex you must use "\" instead of "". And so for example to use it with " " (space):

var id_regex = "([a-zA-Z0-9_]+ ?)+"
# then in _on_parser_unhandled_regex
var ids = result.get_string("screen").split(" ")
# and now you have array of strings
# array starts it index from 0 so to get first element of array you do:
var first_element = ids[0]
# to check/use all elements of array you can use `for` loop like this:
for id in ids:
  if id == "node that I want to show":

For example here is how I implementing this for VisualNovelKit (it still wip):

Thank you so much! Does Rakugo have an autoskip and rollback?

Jeremi360 commented 1 year ago

Thank you so much! Does Rakugo have an autoskip and rollback?

Rollback is not implented, as we don't have idea how to made properly.

Autoskip is not yet added to vnkit, but are easy to program:

func _ready(): $Path/To/Timer.connect("timeout", self, "_on_timeout")

func _on_timeout(): if Rakugo.is_waiting_step() and autoskip_enabled: Rakugo.do_step()

Jeremi360 commented 1 year ago

@MRSEEO Please consider joining our discord and parteon