# In HaxeFlixel, how do I avoid hard-coding dialogue?

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.

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.

• 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. – user1100006 Dec 22 '14 at 4:10
• 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. – Chaosed0 May 6 '15 at 13:38

openfl.Assets.getText("assets/dialogs/exampleDialog.txt"); should do the trick.

• 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! – Javier Bullrich Dec 18 '14 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.