Translations of this page:

Icon based dialogues

Hi there.

thanks to the huge interest in doing Icon based dialogus in WME, I decided to create an universal simple object you can use and extend to suit your own needs.

Here's the example how to quickly implement it:

1. Create file scripts\dialogueObject.script with the following contents:

#include "scripts\" 
// Define dimensions of your dialogue icons: 
var ICON_WIDTH = 57;    
var ICON_HEIGHT = 57; 
// the script here is the name where you will handle responses from player's click on the icon 
method initializeDialogue(script) 
    this.script = script; 
    this.iconCount = 0; 
    this.window = Game.LoadWindow("windows\dialogueWindow.window"); 
    var tmpwin = this.window; 
    tmpwin.Visible = true; 
// This will terminate the dialogue and free resources 
method endDialogue() 
    var tmpwindow = this.window; 
// This will add icon to your dialogue window  
method insertIcon(name, sprite, hoversprite) 
    var tmpwin = this.window; 
    var tmpButton = tmpwin.CreateButton(name); 
    tmpButton.X = this.iconCount * ICON_WIDTH;     
    tmpButton.Visible = true; 
    tmpButton.Interactive = true; 
    tmpButton.ParentNotify = true; 
    tmpButton.Disabled = false; 
    tmpButton.PixelPerfect = false; 
    tmpButton.Width = ICON_WIDTH; 
    tmpButton.Height = ICON_HEIGHT; 
    this[this.iconCount] = name; //We store the name for deleting fast reference 
    this.iconCount = this.iconCount + 1; 
// this will remove icon (usually after the topic is worn out) 
method removeIcon(name) 
    var tmpwin = this.window; 
    var reorder = -1; // safe from nonsensical calls; 
    for  (var a = 0; a<this.iconCount; a= a+1) 
        if (this[a] == name) 
            reorder = a;             
    if (reorder == -1)     return; 
    for  (a  = reorder; a<this.iconCount; a = a +1) 
        this[a] = this[a+1]; 
        var button = tmpwin.GetControl(this[a+1]); 
        button.X = a* ICON_WIDTH;         

2. create a file called scripts\reactions.script

on "first" 
    Game.Msg("Do something after the first choice.");     
on "second" 
    Game.Msg("Do something after the second choice.");     
on "third" 
    Game.Msg("Do something after the third choice.");     

3. put into scripts\base inc

global dlgObject;

and into scripts\game.script

dlgObject = new Object("scripts\dialogueObject.script");

Then in your test scene put the following code:

dlgObject.insertIcon("first","icon.png","icon.png"); // insert some real image file instead of icon.png 
dlgObject.insertIcon("second","icon.png","icon.png"); // insert some real image file instead of icon.png 
dlgObject.insertIcon("third","icon.png","icon.png"); // insert some real image file instead of icon.png

And the basic skeleton is set. Then after the dialogue is over, just call

dlgObject.endDialogue(); and probably set Game.Interactive? flag to true (if it was previously false)

Hope that helps, comments welcome!

resource/icon_based_dialogues.txt · Last modified: 2017/07/17 15:00 by Mot
Recent changes RSS feed Creative Commons License Driven by DokuWiki