Thread Tools
Old January 6, 2001, 20:28   #1
heardie
Prince
 
heardie's Avatar
 
Local Time: 20:48
Local Date: October 31, 2010
Join Date: Aug 1999
Posts: 684
SLIC for beginners
Some quick notes I made after my first day with SLIC(preying that it will format correctily ):

Beginners intro to SLIC

With my first SLIC code done, I went into CTP, and what did I see? Nothing. So here I present to you
“How to get your code to work”
For this I will describe two things.
1. Events that only appear at the start.
2. Events that appear every turn.

1. To get an event to appear only once is simple once you know how. Here it is.
First create your ‘handle’ (Just a name for each bit of code)
Code:
HandleEvent(EventName) 'HandlerName' [pre | post] 
{
    // Your code here
}
The priority of the handler can be either pre or post. A "pre" handler runs before the in-game code, a "post" handler runs afterwards.

Now I will explain how to get a message box with your name in it to appear!
Where I have written ‘//Your code here’ replace with
Code:
Message (g.player, 'Name');
where name, is an variable name you please.
Now for sanity’s sake (since in large scenarios there are hundreds of messages) you can put your message descriptions in another SLIC file.
Call it ‘msg.slc’
To use this file in your program, on the very last line of your scenario.slc write
Code:
#include “msg.slc”;
Now how do we define what we say in our message?
Well this describes a basic message box, that only has an exit button.
First you open up your ‘msg.slc’
Then type in the following
Code:
messagebox 'Name' 
{
	Show();
	Title(ID_TITLE);
	Text(ID_TEXT);
	Button(ID_EXIT) 
		{
			Kill();
		}
}
Don’t worry if this looks confusing at first I will explain. In the first line, replace ‘name’ with the name you used in ‘scenario.slc’. The first line is telling the game this is that particulare message box.

The 3rd line says Show (). This should be self-explanatory; you don’t want a hidden message box. The next line is a bit more confusing. It the title of the message box, and the title will be in the string Title. Where is this string held?
Look in your scen000 dir. Then create a new directory called english, and then a new directory in that called gamedata. Then create a text file called scen_str. That is where the string Title is held. Open it up.
Type like this
Code:
TITLE	 	"Title of your message box here"
TEXT		"Text of your message box here”
Now you should understand up to line 6 in the code.
Lines 7-10 are easy to expain:
Button(ID_EXIT), is like title and text. In your scen_str file you should write
Code:
EXIT “Exit”
Line 9 means, that when you click on that button the message box disappears. Simple, huh? Now since this is the messagebox we only want to appear on the first turn we do this next
Code:
DisableTrigger('HandlerName');
This means that from now on this will not run.
Next we want a message box that appears each turn and shows you the turn no.
Here is how:
Code:
HandleEvent(EventName) 'Name' [pre | post]
Create another handle.
Then we create the message box:
Code:
Message (g.player, ‘msgtype’);
Then we edit the ‘msg.slc’ file to make the msg appear
Code:
messagebox 'EveryTurn' {
	Show();
	Title(ID_DROUGHT_TITLE);
	Text(ID_DROUGHT_TEXT);
	Button(ID_EXIT) 
		{
			Kill();
		}
}
Also update scen_str
Code:
DROUGHT_TITLE	"Turn #
DROUGHT_TEXT	"Turn {g.year}"
All that is new here is g.year, which accesses what year it is up to in the game. Now since we want it every turn we don’t do DisableTrigger. That is it.

Appendix A.
Here are my completed files with there variable names

scenario.slc

Code:
/////////////////////////
// Do At the beginning //
/////////////////////////

HandleEvent(BeginTurn) 'DStart_F' pre 
{
	Message (g.player, 'AGStartA');
	DisableTrigger('DStart_F');
}


//////////////////////////
// Do Every Turn	//
//////////////////////////

HandleEvent(BeginTurn) 'D_EveryTurn' pre
{
	Message (g.player, 'EveryTurn');
} 
#include "msg.slc"
msg.slc
Code:
messagebox 'AGStartA' {
	Show();
	Title(ID_AG_START_TITLE);
	Text(ID_AG_START_A);
	Button(ID_EXIT) 
		{
			Kill();
		}
}

messagebox 'EveryTurn' {
	Show();
	Title(ID_DROUGHT_TITLE);
	Text(ID_DROUGHT_TEXT);
	Button(ID_EXIT) 
		{
			Kill();
		}
}
scen_str.txt
Code:
EXIT	 	"Exit"
AG_START_TITLE	"Natural Disasters"
AG_START_A	"Made by heardie"
DROUGHT_TITLE	"Drought strikes your Civ!"
DROUGHT_TEXT	"Year {g.year}"
heardie is offline  
Old January 7, 2001, 15:01   #2
MrFun
Emperor
 
MrFun's Avatar
 
Local Time: 04:48
Local Date: October 31, 2010
Join Date: Nov 2000
Location: Illinois
Posts: 8,595
I have bookmarked this post for future reference. Thanks for the info.
MrFun is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:48.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team