The
  Way Of
    The Wombat
Messages

Contents

6.0 Messagebox Structure
6.1 Using Buttons
6.2 Calling Messages
6.0 Messages

Messageboxes come in two forms. Messageboxes and alertboxes.

Messageboxes appear at the top of the screen, are the larger of the two, and can be left open while the game continues around them.

Alertboxes are smaller, have no titles, appear half-way down the left-hand side of the screen (the message you get when entering a goody hut is an alertbox) and they force play to be stopped until you have responded to them. For this reason, they must contain buttons with the Kill(); command in them.

Like Handlers, you must name messageboxes, and like handlers, they must have unique names. Most people do this by adding an M suffix to the name.
A typical messagebox in SLIC looks like this:

messagebox 'messagebox_nameM' { Show(); Title(ID_TITLE); Text(ID_TEXT); }
And an alertbox looks rather similar.
Buttons, like any other object, must have an opening and closing { }, determining what effect the button has. In most cases, this will just be Kill(); to close the messagebox.

alertbox 'alertbox_nameM' { Show(); Text(ID_TEXT); Button(ID_BUTTON_OK){ Kill(); } }
The ID_TITLE and ID_TEXT correspond to entries somewhere in the string files (in the ctp2_data\english\gamedata folder), the format of which should be:

TITLE "Eye-Catching Title!"
TEXT "Insert text here. You can fit 350 characters in a message box without buttons, and 315 in an alertbox"
BUTTON_OK "OK"



6.1 Using Buttons

The really cool thing about messageboxes though, is that with buttons, you can allow the player to make decisions which affect the way the SLIC runs. The simplest way to do this is to have code triggered by the buttons directly.

messagebox 'kill_unit_or_notM' { Show(); Title(ID_TITLE); Text(ID_TEXT); // TEXT "Do you want to kill this unit?" Button(ID_YES){ Kill(); KillUnit(unit[0]); } Button(ID_NO){ Kill(); } }
Provided you call this messagebox from a situation where there is a unit[0] in context, pressing the YES button will kill the unit in question.


6.2 Calling Messages


To make a message appear, use the message function in the handler.
The message function takes the following structure:
Message(int_t<player>, 'messagebox_name'); - where the player is the integer of the player you wish to receive the message, and the messagebox_name is the name of the messagebox, as you typed it in "messagebox 'kill_unit_or_notM' {"

HandleEvent(SleepUnit) 'kill_the_unit' pre { unit_t tmpUnit; tmpUnit = unit[0]; player[0] = unit[0].owner; if(player[0].cities > 10){ KillUnit(tmpUnit); for(i = 0; i < player[0].cities; i = i + 1){ city_t tmpCity; GetCityByIndex(player[0], i, tmpCity); if(CityHasBuilding(tmpCity, "IMPROVE_SILO")){ AddGold(player[0], 5000); } else { AddGold(player[0], 1000); } } int_t i; location_t tmpLoc; tmpLoc = unit[0].location; i = GetNearestCity(tmpLoc, player[0]); GetCityByIndex(player[0], i, tmpCity); tmpLoc = tmpCity.location; CreateUnit(player[0], unit[0].type, tmpLoc, 0); } else{ message(player[0], 'kill_unit_or_notM'); } }

back close forward