 |
|  |
 |
|
Jonny
|
 |
Nashville, Tennessee, USA
Nov 2000 time: 23:14
|
|
In my first attempt to write SLIC, I am trying to write code that will create a unit whenever & wherever you build a city. The unit you get will depend on technology as well as make the city start at an increased size. I am getting an error message that points to a syntax error in line 23 (I think where the unit creating process begins) and I can't figure it out. Please help! Here is the code:
code:
//Quickstart Mod SLIC
//events
HandleEvent(CreateCity) 'citycreate' post {
int_t a;
//set value of a
a = 1;
if(hasAdvance(player[0], AdvanceDB(ADVANCE_FEUDALISM))) {
a = 2;
}
if(hasAdvance(player[0], AdvanceDB(ADVANCE_GUNPOWDER))) {
a = 3;
}
if(hasAdvance(player[0], AdvanceDB(ADVANCE_ADV_INFANTRY_TACTICS))) {
a = 4;
}
//make free unit
if(a = 1) {
CreateUnit(player[0], UnitDB(UNIT_HOPLITE), city[0].location, 0);
}
if(a = 2) {
CreateUnit(player[0], UnitDB(UNIT_PIKEMEN), city[0].location, 0);
}
if(a = 3) {
CreateUnit(player[0], UnitDB(UNIT_INFANTRYMAN), city[0].location, 0);
}
if(a = 4) {
CreateUnit(player[0], UnitDB(UNIT_MARINE), city[0].location, 0);
}
//increase city size to 3 (5 if build with urban planner)
{AddPops(city[0], 4);
}
}
This is my first attempt at SLIC and I wouldn't be suprised if there are many errors.
|
|
|  |
 |
|  |
 |
|  |
 |
|
Dale
|
 |
Sir! Why do you keep clicking on me?
Dec 2000 time: 15:14
|
|
Also be careful when using passed variables too. There's always the potential for accidently changing these. My suggested script (usual disclaimer: not tested, so don't expect it to work the first time ).......
code:
HandleEvent(CreateCity) 'citycreate' post {
int_t a;
int_t playerNum;
city_t tmpCity;
location_t tmpLoc;
a = 0; //It is possible not to have advance for Hoplites at start of game. IE. first city built.
playerNum = g.player;
tmpCity = city[0];
tmpLoc = location[0];
// The way you had it, the script was processing many lines, as opposed to this scripts couple of lines before dropping out.
if(HasAdvance(playerNum, ID_ADVANCE_ADV_INFANTRY_TACTICS)) {
a = 4;
}
elseif(HasAdvance(playerNum, ID_ADVANCE_GUNPOWDER)) {
a = 3;
}
elseif(HasAdvance(playerNum, ID_ADVANCE_FEUDALISM)) {
a = 2;
}
elseif(HasAdvance(playerNum, ID_ADVANCE_BRONZEWORKING)) { // Or whatever gives Hoplites
a = 1;
}
if(GetUnitsAtLocation(tmpLoc) < 12) { // Could be a 12-stack finding city in ruins
if(a == 1) {
CreateUnit(playerNum, UnitDB(UNIT_HOPLITE), tmpLoc, 0);
}
elseif(a == 2) {
CreateUnit(playerNum, UnitDB(UNIT_PIKEMEN), tmpLoc, 0);
}
elseif(a == 3) {
CreateUnit(playerNum, UnitDB(UNIT_INFANTRYMAN), tmpLoc, 0);
}
elseif(a == 4) {
CreateUnit(playerNum, UnitDB(UNIT_MARINE), tmpLoc, 0);
}
}
AddPops(tmpCity, 4);
}
Last edited by Dale on 03-07-2001 at 04:32
|
|
|  |
 |
|
Locutus
|
|
ACS CTP1/2 Manager & Civ4 Co-Manager
|
 |
Hengelo, The Netherlands
Nov 1999 time: 06:14
|
|
Behold, for the return of the Borg! I had to go back to my unimatrix and kill some of those Species 8472 bastards but now I'm back and better than ever Resistance is futile, you WILL be assimilated
Sorry 'bout that, I'm afraid I've been watching a bit too many old ST episodes lately Actually I've been extremely busy with some real-life affairs and stuff (school, work, social live, you know the drill) but I'm slowly getting back to CtP. (BTW, I apologize for all unanswered emails, I'll deal with those later).
It's good to see people are still interested in SLIC though SLIC certainly has it's curiosities (to put it mildly) but it's still a great tool for modmakers and a nice toy for programmers (Ah, who am I kidding, it's really a piece of sh*t! But I still love it ).
I should have some instructions around on how to install those EditPlus files, I'll see if I can find them and post those on my website too. Well, Peter, I'd love to take the credit for that color scheme but I think that's not my work Unless I'm mistaken the syntax files only transfer the syntax info, not the color info. To get a color scheme that's perhaps easier on the eye you'll have to change the colors yourself (Tools->Preferences->Settings&Syntax->Syntax Colors, in case anyone hadn't figured that out yet). Not that my own personal color scheme is some much better but it's still an improvement 
I plan on continuing my work on that SLIC documentation very shortly, I'm even considering putting what I already have on my website: it would be a shame to let such potentially useful info go to waste (God knows how long it'll still be before I'll finally finish it, it should have been done months ago). Esp. people like Johnny, who are absolute newbies in the world of programming, it should be very useful even if it's not finished yet. The best advice I can give though is, as IW already said, to study other people's code. My Militia code is indeed very similar to this.
The only potential problem I see with the code (Dale's version that is) is that 'createcity' is a very general name and it's possible that an eventhandler with such a name already exists. If so, the first occurence of the handler will be used and all subsequent handlers ignored. Better to call it JOHN_CreateCity or something like that, put a unique prefix in front of the name.
Last edited by Locutus on 22-09-2001 at 11:32
|
|
|  |
All times are GMT. The time now is 05:14. Apolyton Time is 00:14. |
top of page
|
| archivepost |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|