I'm planning to develop a visual novel in Haxe Flixel and wanted to know if there is a easier way to add dialogue than to hardcode them in every square. I don't know if I can import a txt file with the dialogues or something like that so I can simple change the txt file instead of have to check the code for every typo.
3 Answers
You'd better use a script engine to do that. There are plenty of script engines in Flash AS3, but for Haxe, all I know is hscript. However, hscript doesn't have the handy ability to suspend in the middle of the scripting, which I think is very important in your case.
So you may need to find a script engine in Haxe that can suspend in the middle of its scripting like the BISE engine in AS3, or write your own in Haxe (Although I'm forking hscript to support that feature, I'm not sure when it'll be ready for a release), or switch to AS3 and use BISE.
-
\$\begingroup\$ To be more specific, you can write all your dialogues/scripts in a text file and execute them on the fly, that's when a scripting engine is needed. Suspending is also needed because you may need to wait for user's input when executing the scripts. The BISE engine contains a very basic text adventure example which you may want to check. \$\endgroup\$ Commented Dec 22, 2014 at 4:10
-
\$\begingroup\$ I wouldn't integrate a scripting engine just for a dialogue system unless I were doing something very complicated. All that's really needed here is some text files and some work to read/display them. \$\endgroup\$– Chaosed0Commented May 6, 2015 at 13:38
openfl.Assets.getText("assets/dialogs/exampleDialog.txt");
should do the trick.
-
1\$\begingroup\$ While the answer could be correct, it's very vague and I can't find any information related, if you could be more specific with your answer and offer a brief explanation I could chose your as correct. Thanks! \$\endgroup\$– JallrichCommented Dec 18, 2014 at 21:40
Gama11's method is the one I would use personally. Basically you put all of your text inside a text file dialog.txt and split each dialog up with some special character or character sequence (i.e. @@).
------ dialog.txt ------
This is dialog for box 1.@@
Dialog for box 2.@@
And so on...@@
inside of your game use the following:
var dilog_boxes:Array<String> =
openfl.Assets.getText(AssetPaths.dialog.__txt).split("@@");
now all you need to do is access the array for each specific block you need. If you need text for block 1, use dialog_boxes[0], block 2 is dialog_boxes[1], etc.