What would be the best way to extend the editor to allow you to modify text via code in a text event, similar to a Twine macro? #1110
-
Hi! I should first of all mention that I haven't actually used Github for anything but personal projects yet, so if I'm posting this in the wrong place or breaking some written or unwritten rule/etiquette, please let me know! Anyways, some context for my question: I'm making a dating-sim style visual novel, featuring three love interests: one girl, one guy, and one nonbinary person. That means I'm gonna have to write some custom logic for supporting the pluralization of verbs and some other grammar stuff to account for different pronouns. Now, as the title suggests I have a background using Twine, where I'd use something like this macro. So for the question itself: I'm pretty sure there's no equivalent to macros in Dialogic (if there is, please let me know!), so I wanted to try to implement a similar system, where I could in the editor write something along the lines of <<MethodName argument1, argument2, etc.>>, and then write the logic for that method somewhere and have it display in text. Let me give you a simple example: Say I wanted to display the total number of animals the player has seen. I'd like to, in the editor, be able to write for example "You saw <<Add So, would something like this even be possible in Dialogic? Any suggestions on where I would start? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Dialogic 1.x doesn't have any way to do that in timelines. Dialogic 2.0 does allow more complex calculation formulas for conditionals, but I don't think right now we have it able to do evaluations like that for setting the variables, but we could probably add it though. Outside of that, for both 1.x and 2.0 you could also directly do the math in scripts out of a timeline, update another variable there. So in the script set the value of like [totalSeen] to the values of [dogsSeen] and [catsSeen], then in the timeline for the text its just "You saw [totalSeen] animals". You could use a Signal or a Call Node timeline event to call a Godot script function to do all your updates for both that, and the other grammar stuff you mentioned too in other variables (they can store strings as well) |
Beta Was this translation helpful? Give feedback.
-
A small update to this:Since recently 2.x has the ability to define custom text-modifiers in an extension. # In the index.gd file of the extension
func _get_text_modifiers() -> Array[Dictionary]:
return [
{'subsystem':'Text', 'method':'modifier_random_selection'},
] If you don't want to create a custom subsystem you can use a method from a node in the scene tree, in best case an autoload by providing # In the subsystem (in this case the text subsystem)
var modifier_words_select_regex := RegEx.create_from_string("(?<!\\\\)\\[[^\\[\\]]+(\\/[^\\]]*)\\]")
func modifier_random_selection(text:String) -> String:
for replace_mod_match in modifier_words_select_regex.search_all(text):
var string :String= replace_mod_match.get_string().trim_prefix("[").trim_suffix("]")
string = string.replace('//', '<slash>')
var list :PackedStringArray= string.split('/')
var item :String= list[randi()%len(list)]
item = item.replace('<slash>', '/')
text = text.replace(replace_mod_match.get_string(), item.strip_edges())
return text Obviously you can do whatever the heck you want in this method, provided you return the text again. Not sure if this is self-explanatory enough, if anyone has questions, just ask. |
Beta Was this translation helpful? Give feedback.
Dialogic 1.x doesn't have any way to do that in timelines. Dialogic 2.0 does allow more complex calculation formulas for conditionals, but I don't think right now we have it able to do evaluations like that for setting the variables, but we could probably add it though.
Outside of that, for both 1.x and 2.0 you could also directly do the math in scripts out of a timeline, update another variable there. So in the script set the value of like [totalSeen] to the values of [dogsSeen] and [catsSeen], then in the timeline for the text its just "You saw [totalSeen] animals".
You could use a Signal or a Call Node timeline event to call a Godot script function to do all your updates for both that,…