Announcement

Collapse
No announcement yet.

SLIC beginner needs help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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
    Concrete, Abstract, or Squoingy?
    "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

    Comment


    • #3
      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.

      Comment


      • #4
        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


        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.

        Comment


        • #5
          I can understand the unit when you build a city, but why do you want to increase the city size?

          Comment


          • #6
            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
            Concrete, Abstract, or Squoingy?
            "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

            Comment


            • #7
              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);
              }

              Comment


              • #8
                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.

                Comment


                • #9
                  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

                  Comment


                  • #10
                    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.

                    Comment


                    • #11
                      Welcome back. That big Locutus shaped hole in the forums was getting unnerving
                      Concrete, Abstract, or Squoingy?
                      "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis

                      Comment


                      • #12
                        Thanks guys, you sure know how to make a guy feel at home
                        Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                        Comment

                        Working...
                        X