[an error occurred while processing this directive] Modification
SLIC scripting language Contents SLIC Language Specification Message Boxes
A typical command might be:
Alert Boxes Buttons Event handlers and generating events Functions Important note! As this documenation is being prepared, the
first patch for CTP2 is about to be released. Unfortunately a bug
with functions was discovered too late to fix. Specifically, in some
cases, using members of unit, army, city, and location variables that
are function parameters may not always work as expected. There is,
however, a workaround. Copy the function parameter to a local
variable and use that variable instead. Example: User variables Database Access A record in any of these databases can be accessed by name or by
index. For example, to create a tank, you can use UnitDB(UNIT_TANK)
in a call to the CreateUnit event. If you have the integer index of
the tank stored in a variable, you can also use UnitDB(theTankIndex)
(although this is a little silly since it amounts to the same thing as
writing just "theTankIndex").
But it doesn't stop there. Many fields from each database are also
accessible. Any bitfield, integer, or floating point value that is in
the main body of a record (NOT values in sub-structures!) can be
used. Floating point values are multiplied by 100 and converted to
ints, since SLIC does not otherwise support floating point
variables. Loading your script You can cause your SLIC file to be loaded by using a
[an error occurred while processing this directive]
Date: December 13, 2000
The basic components of the SLIC language are:
MessageBox 'name' {
commands
}
The name can be any string, and may contain spaces, but may not
continue past the end of a line.
Text(ID_THIS_IS_A_MESSAGE_BOX);
Which would cause the dialog box to display the text pointed at by the
string ID "THIS_IS_A_MESSAGE_BOX". Note that string IDs in SLIC are
always preceded by ID_. There are other possible commands for message
boxes:
...
Button (stringid) {
code
}
...
code is the code to be run when the button is clicked. As an example, here is a message box with an "OK" button and a "Tell me more" button:
messageBox 'MSampleBox' {
Text(ID_THIS_IS_A_SAMPLE);
Button(ID_OK) {
Kill(); // Close this message
}
Button(ID_TELL_ME_MORE) {
// Provide another messagebox with more info.
// Does not close this box, since there is no Kill() in this button.
Message(g.player, 'MSampleTellMeMore');
}
}
There is also a special button-like statement called OnClose which
doesn't take a name, and runs when the message is closed. Here is an
example of how to send another message when one message is closed (no
matter how the first message was closed)
messageBox 'MFirstMessage' {
Text(ID_CLOSING_SENDS_ANOTHER_MESSAGE);
OnClose {
Message(g.player, 'MSecondMessage');
}
}
messageBox 'MSecondMessage' {
Text(ID_SENT_WHEN_FIRST_MESSAGE_CLOSED);
}
Built-in Variables
The SLIC engine contains many predefined variables with many
different meanings. See Built-in
variables for a discussion of variable concepts and a full list of
builtin variables.
Function reference
In addition, users may implement their own functions. A declaration
looks like:
int_f AddTwo(int_t num)
{
return num + 2;
}
Note that the type of the function is int_f not int_t. The
latter will result in a syntax error. Valid function types are int_f
and void_f. Any variable type can be used as an argument.
// This version may fail sometimes!
int_f DoesAHumanOwnThisUnit(unit_t theUnit)
{
if(IsHumanPlayer(theUnit.owner)) {
return 1;
}
return 0;
}
// This version should always work
int_f DoesAHumanOwnThisUnit(unit_t theUnit)
{
unit_t copiedUnit;
copiedUnit = theUnit;
if(IsHumanPlayer(copiedUnit.owner)) {
return 1;
}
return 0;
}
The author apologizes for this and promises that if there is another
patch it will be fixed. But the above workaround should always work.
my_var = 1 + 1;
have_flanker = IsFlankingUnit(unit);
counter = counter + 1;
turns_to_go = turns_to_go - 1;
last_checked_year = g.year;
And so on. Their values are global and persistent - they will not
change between various slic objects or when execution stops.
In addition to integer variables, there are Unit, City, Army, and Location
variables. The complete list of types is:
army_t armyVar;
city_t cityVar;
int_t intVar;
location_t locationVar;
unit_t unitVar;
Only integer variables can be used in mathematical expressions, but ==
(equality), != (inequality), and =(assignment) work for all types.
Here is an example that creates a unit in a city at the beginning of
that city's turn, then as soon as that unit moves, kills it.
unit_t myExampleUnit;
int_t saveUnit;
// A handler that runs at the beginning of the turn for every city
HandleEvent(CityBeginTurn) 'MyCityBeginTurnHandler' post
{
saveUnit = 1;
Event:CreateUnit(city[0].owner, city[0].location, city[0],UnitDB(UNIT_WARRIOR), 0);
// Disable this handler as soon as it's fired once
DisableTrigger('MyCityBeginTurnHandler');
}
// A handler that runs whenever a unit is created, use it to store our
// created unit
HandleEvent(CreateUnit) 'MyCreateUnitHandler' post
{
if(saveUnit) {
// The city begin turn handler sets a flag saying the next
// unit created is ours
myExampleUnit = unit[0];
saveUnit = 0;
// Only need to run this once
DisableTrigger('MyCreateUnitHandler');
}
}
// A handler that fires whenever an army moves.
HandleEvent(MoveUnits) 'MyMoveUnitsHandler' post {
int_t i;
unit_t checkUnit;
for(i = 0; i < army[0].size; i = i + 1) {
GetUnitFromArmy(army[0], i, checkUnit);
if(checkUnit == myExampleUnit) {
Event:KillUnit(checkUnit, 0, -1);
}
}
DisableTrigger('MyMoveUnitsHandler');
}
tankAttack = UnitDB(UNIT_TANK).Attack;
costOfAdvInfantryTactics = AdvanceDB(ADVANCE_ADV_INFANTRY_TACTICS).Cost;
minimumHappinessForDefaultStrategy = StrategyDB(STRATEGY_DEFAULT).MinimumHappiness;
Please explore the database text files to see what data you might be
interested in. There are far too many fields available to enumerate
here.
#include "yourfile.slc"
in script.slc. Your file should be
placed in default/gamedata, the same place as script.slc.
Joe Rumsey
BACK TO MODIFICATION INDEX PAGE