Denne guide viser et simpelt eksempel af brug af Dialogue Manager 3 i Godot 4 med C#.
(easy peasy, japanesee)
Indsæt følgende i filen:
~ start
NPC: Hej! Velkommen til [HTX|EUC Nord] 👋
- Hvem er du?
NPC: Jeg er skolens NPC.
=> END
- Farvel
NPC: Vi ses!
=> END
Begreber i ovenstående:
Gem filen. (opret en dedikeret folder til dine dialoger) som f.eks.:
res://dialogues/htx_dialog.dialogue
| Tegn | betydning |
|---|---|
| Martin : Dingo ate me baby! | Martin says : Dingo ate me baby! |
~ | Cues (Label) |
- | Option |
⇒ | Jump to cue/label |
⇒< | Jump to snippet, and return (sub-routine) |
[sayA|sayB|sayC] | Skifter tilfældig mellem sayA, sayB og sayC |
# | Kommentar |
Man kan anvende multilines for at vise flere linjer dialog fra en enkelt NPC. Her bruger du enten '\n' til at adskille dem på en enkelt linje eller indryk hver yderligere linje.
Nathan: Prepare to duel me, coward!
I’ve studied the fine art of…
pointing a stick and looking angry.
Also, I’m really good at tripping over my own feet.
Tilføj først DialogManager som en Auto-load klasse.
Nu kan du henvise til den fra alle dine C# scripts.
Tilføj et C# i dit FileSystem:
using Godot; using System; using DialogueManagerRuntime; public partial class DialogueTrigger : Area2D { [Export] public Resource DialogueResource; [Export] public string DialogueStartLabel = "start"; //default er altid 'start' public override void _Ready() { base._Ready(); if (this.DialogueResource == null) { GD.Print("Error: You forgot to assign a dialogue resource.."); } } public void StartTheDialog() { DialogueManager.ShowDialogueBalloon(DialogueResource, DialogueStartLabel ); } public void OnBodyEnter(Node2D other) { if (other.Name == "Player") { this.StartTheDialog(); } } }
htx_dialogue.dialogue ind i feltetstart)| Fejl | Årsag |
|---|---|
| DialogueManager.Instance er null | Plugin ikke aktiveret |
| Intet sker | DialogueResource ikke sat |
| C# build fejl | .NET SDK mangler |
For at gøre dialogerne mindre ensformige kan vi indføre tilfældigheder i valget af linier & jumps i dialog scriptet.
Nathan: I will say this. % Nathan: And then I might say this % Nathan: Or maybe this % Nathan: Or even this?
Nathan: Hi there partner, i hope you have a [wonderful|awesome] day.
Combining the randomized line syntax with the jump syntax to randomly jump to a pool of titles.
Nathan: I am feeling lucky. I am gonna choose a random jump :) % => first % => second % => third
Opret en klasse du vil anvende som en global (Autoload).
using Godot; using System; public partial class MyGlobal : Node { public Boolean has_key = false; public int gold = 5; }
Tilføj dit script til Autoload, så det kan tilgåes fra alle scripts på tværs af scener.
Som en del af en dialog
Nathan : I have {{ MyGlobal.gold }} gold nuggets in me pocket..
I en betinget option
- Buy sword [if MyGlobal.gold >= 8] - Leave shop
Du kan også lave inline if/else statements, for fx. at få ental/flertal på plads ift. antal.
Nathan: I have {{MyGlobal.coins}} [if MyGlobal.coins == 1]coin[else]coins[/if], which is nice!
| Tegn | betydning |
|---|---|
do zelda.LookDown | Kalder funktion LookDown() på 'zelda' objekt |
set State.hasAble = true | ændrer propertie i State klasse |