Thread Tools
Old June 29, 2001, 19:02   #1
Jonny
Civilization III Democracy GameNationStatesNever Ending StoriesGalCiv Apolyton EmpireC3C IDG: Apolyton TeamC3CDG The Lost Boys
 
Jonny's Avatar
 
Local Time: 06:12
Local Date: October 31, 2010
Join Date: Nov 2000
Location: Nashville / St. Louis
Posts: 4,263
SLIC beginner needs help
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.
Jonny is offline  
Old June 30, 2001, 11:18   #2
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 12:12
Local Date: October 31, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
Firstly, the way I would suggest coding SLIC is to rip as much coding as you can from other people's code

This is very similar to a simplified version of Locutus' militia code, but I can see that doing it from scratch is a good way to get used to handling SLIC.
(His GetAge function is very useful for all sorts of things btw, and easily changed to suit your needs)

The syntax error occurs because "=" is SLIC is a definer. It makes a = 1. To compare (ie. for use in "if" statements), you have to use ==.
eg.
Code:
...
if(a == 3){
...
Also, I dont think the AddPops bit needs the surrounding {}.

Its good to see someone else learning SLIC. From having no experience in programming, I managed to slowly learn techniques, and its very fun once you get going
Immortal Wombat is offline  
Old July 2, 2001, 15:26   #3
Jonny
Civilization III Democracy GameNationStatesNever Ending StoriesGalCiv Apolyton EmpireC3C IDG: Apolyton TeamC3CDG The Lost Boys
 
Jonny's Avatar
 
Local Time: 06:12
Local Date: October 31, 2010
Join Date: Nov 2000
Location: Nashville / St. Louis
Posts: 4,263
I did that, and I don't get any more error messages. However, the code still has no effect. I think that the code doesn't know when I build a city.
Jonny is offline  
Old July 2, 2001, 17:20   #4
Peter Triggs
CTP2 Source Code ProjectCivilization IV Creators
King
 
Local Time: 11:12
Local Date: October 31, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
You should be getting error messages; I think you've got debugslic=No. Go to ...\ctp2_program\ctp\userprofile.txt and set debugslic=Yes. (There are other profiles, but I think this is the crucial one.) If you're writing a SLIC program you need to have it on this setting while you're debugging it.

Now you should get the error message about 'function HasAdvance wrong kind of argument' thingy. There's an error in the SLIC function documentation: the function HasAdvance takes a string ID argument as in

Quote:

HasAdvance(player[0], ID_ADVANCE_FEUDALISM)
And, yes, this sort of thing is enough to drive you bonkers.

If you don't have it already, go to Locutus's site and get a copy of EditPlus2. Make sure you also get his slic4ep2.zip. This contains some files that you load into EditPlus so that it will handle SLIC (the most important one is slic.stx). I can't remember the details but the EditPlus Help system should tell you how to do it. Once you get this set up, it's absolutely invaluable. (And you soon get used to Locutus's psychedelic colour scheme for SLIC syntax highlighting. )

You might also e-mail Locutus, he hasn't posted here for ages. Ask him how his introduction to SLIC is coming along and *beg* him for a copy of it. It's just what you need and the only alternative I can think of is to download some C-tutorials from the Net and wade through them. The trouble is that C has many features that aren't present in SLIC, so this would be a very inefficient and difficult way of approaching SLIC.
Peter Triggs is offline  
Old July 2, 2001, 18:02   #5
Cube
Warlord
 
Cube's Avatar
 
Local Time: 04:12
Local Date: October 31, 2010
Join Date: Nov 2000
Location: El Paso, Tx
Posts: 120
I can understand the unit when you build a city, but why do you want to increase the city size?
Cube is offline  
Old July 2, 2001, 19:10   #6
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 12:12
Local Date: October 31, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
Yay! I knew I didn't make that avatar in vain Thanks Cube.

Anyway...
The increase in city size is too make the city more productive and richer in the early game, to make it a proper quick-start.

Dutcheese did a very good quick-start for CTP if you want to look at that Jonny.

That Editplus thing really is useful. I didn't like the colour at first, but its much harder to code without it now
Immortal Wombat is offline  
Old July 2, 2001, 19:27   #7
Dale
Emperor
 
Dale's Avatar
 
Local Time: 21:12
Local Date: October 31, 2010
Join Date: Dec 2000
Posts: 3,944
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; July 2, 2001 at 19:32.
Dale is offline  
Old July 2, 2001, 20:22   #8
Cube
Warlord
 
Cube's Avatar
 
Local Time: 04:12
Local Date: October 31, 2010
Join Date: Nov 2000
Location: El Paso, Tx
Posts: 120
Yay! I knew I didn't make that avatar in vain well I didn't know you made the avatar, I was thinking of using a unit, but then i came across it and thought it was cool.

you don't include the machine gunner or hover infantry in the code, and I think they should be in there. I personally think it takes away from the begining of a city and watching it grow and build units.
Cube is offline  
Old July 3, 2001, 18:24   #9
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 13:12
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
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.
__________________
Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

Last edited by Locutus; September 22, 2001 at 02:32.
Locutus is offline  
Old July 3, 2001, 18:56   #10
Dale
Emperor
 
Dale's Avatar
 
Local Time: 21:12
Local Date: October 31, 2010
Join Date: Dec 2000
Posts: 3,944
Locutus:
Good to see ya back mate! Hope you continue the good SLIC work. It's been a bit lonely round here without our number 1 SLICer.
Dale is offline  
Old July 4, 2001, 07:09   #11
Immortal Wombat
Apolytoners Hall of Fame
Prince
 
Immortal Wombat's Avatar
 
Local Time: 12:12
Local Date: October 31, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
Welcome back. That big Locutus shaped hole in the forums was getting unnerving
Immortal Wombat is offline  
Old July 4, 2001, 08:03   #12
Locutus
Apolytoners Hall of FameCiv4 SP Democracy GameCiv4 InterSite DG: Apolyton TeamBtS Tri-LeagueC4BtSDG TemplarsC4WDG Team ApolytonCivilization IV CreatorsCTP2 Source Code ProjectPolyCast Team
Deity
 
Locutus's Avatar
 
Local Time: 13:12
Local Date: October 31, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
Thanks guys, you sure know how to make a guy feel at home
__________________
Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery
Locutus 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 07:12.


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