Thread Tools
Old October 7, 2002, 13:25   #1
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
SLIC oddities
I've only recently started modding and there are already four 'screw-ups' of this script language that have cost me hours of error searching. So I hope this thread will save other modders time and I also hope that others can contribute to this (or maybe not - since there are enough odd things to SLIC as it is)

Newbies to modding should not be frightened by this thread. SLIC is after all rather easy and Locutus' and IW's guides help a lot! Check this one out:
http://apolyton.net/forums/showthrea...threadid=33181

If you have questions relating to these issues or have another opinion/experience I think it'd be better to start a new thread or PM the author so he can edit his post since I'd rather like to see this thread stay tidy. If it evolves (God forbid) we might ask Locutus to top it (as he should top the 'Getting started with slic' or some tidied version of that one)

Last edited by mapfi; October 7, 2002 at 14:27.
mapfi is offline  
Old October 7, 2002, 13:25   #2
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
1.Local variables
It's clear to every programmer that a global variable is available to all parts of the code and always retains it's value. Local variable are only available in the code bit they are declared within. In SLIC such a local variable in a eventhandler will keep its value though. This means that next time the code fires up, the value is still there. So always make sure you reset it if your code doesn't overwrite it in the beginning for sure!

Discovered here: http://apolyton.net/forums/showthrea...threadid=59742

Last edited by mapfi; October 7, 2002 at 13:38.
mapfi is offline  
Old October 7, 2002, 13:27   #3
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
2.Calculations
Since SLIC only knows integers one has to be careful with division that will return a double. The available guides will tell you that no rounding takes place but digits are simply cut off. So 5/2 will give you 2, so will 4*7/10. Now when you work with variables a SLIC oddity will finish the last one off. Lets say a=4 and b=10, you'd assume that a*7/b will give you 2 as well. It doesn't! SLIC calculates variable first so you get a/b=0.4 which is 0, and then 0*7, still 0! So make sure you write (a*7)/b, which will return 2.

Discovered here: http://apolyton.net/forums/showthrea...0&pagenumber=3

Last edited by mapfi; October 7, 2002 at 13:51.
mapfi is offline  
Old October 7, 2002, 13:28   #4
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
3.Random numbers
While I wonder of what kind and what the period of SLIC's random number generator is (I might spend time on finding out someday) there's a something simple that is easily misunderstood because it defies logic: random(x); returns an integer starting at/with 0 and ending at/with x-1!
(You're not alone on this if you have believed otherwise for years...)

Discovered here: http://apolyton.net/forums/showthrea...0&pagenumber=3

Last edited by mapfi; October 7, 2002 at 13:59.
mapfi is offline  
Old October 7, 2002, 13:28   #5
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
4.built-in player[] array
Players and integers are more or less the same with the important difference that the built-in player variable allows you to access strings like player[0].civ_name_singular, very useful for messages. Known events use player[0] and player[1], some hidden events or unfinished diplomacy stuff might use player[2] so anything else is save. The array has unlimited size.
Now if you want to use this for a message the following restriction applies:
Immeadetly after assigning player[3] a value you have to send the message. Any additional line of code will render the value inaccessable. So unfortunately you can't have a message using two of those player[] array values. The moment you assign the second one the first one is lost, no matter that you're using a different index.
Unless in the following situation: The event uses player[0]. In that case you can first assign the index 0 and then the a different one and both will be available for the following message.

Discovered here: http://apolyton.net/forums/showthrea...threadid=63901

Last edited by mapfi; October 11, 2002 at 17:54.
mapfi is offline  
Old October 11, 2002, 18:43   #6
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
5a.AlertBox
An AlertBox effectively halts the game until a user input (klicking a button) - that's what the documentation says.
However, even though the human player receives the message more or less immedeately, the game unfortunately doesn't stop till the beginning of his turn.

5b.Messages
To have messages appearing on the screen you need the line show() in your code. However sometimes this still doesn't work. The frustarting thing in this case is that you usually miss what change in the code caused the fault or fixed it.
IW suggested it to be the case that this happens when two messages fire at the same time (read here: http://apolyton.net/forums/showthrea...threadid=63142). I hope this is the only case. Thanks IW.
Another cause can be what Pedrunn describes in the following post, I've experienced the same but just couldn't pin it down.

Last edited by mapfi; October 18, 2002 at 07:08.
mapfi is offline  
Old October 13, 2002, 07:01   #7
Pedrunn
Call to Power II Democracy Game
King
 
Pedrunn's Avatar
 
Local Time: 06:04
Local Date: November 1, 2010
Join Date: Jul 2001
Location: of Natal, Brazil
Posts: 2,555
6. Showing Numbers in messages

If you want to have a number from a variable showing up in the messages. As usual you write the variable between {} in the message field. But you must be aware that this variable has to be a global variable otherwise the message although it will be in the message tab it not only wont show up but it wont open when you click on it in the message tab.

This is from my experience. Dont know any thread about it.
__________________
"Kill a man and you are a murder.
Kill thousands and you are a conquer.
Kill all and you are a God!"
-Jean Rostand
Pedrunn is offline  
Old October 14, 2002, 15:04   #8
ahenobarb
Prince
 
ahenobarb's Avatar
 
Local Time: 09:04
Local Date: November 1, 2010
Join Date: Nov 2001
Posts: 437
6b. Message Duration Command

SLIC documentation says:

VOID Duration(turns)
Kill this message automatically in n turns.

However, this command does not work. Duration should say how long a message remains in the message box before it can be deleted. however, it does not do this at all, the message stays turn after turn unless you left click it.

Last edited by ahenobarb; October 19, 2002 at 14:33.
ahenobarb is offline  
Old October 18, 2002, 07:06   #9
mapfi
Call to Power II Democracy GameCall to Power II Multiplayer
Prince
 
Local Time: 10:04
Local Date: November 1, 2010
Join Date: Jul 2002
Location: San Francisco, CA
Posts: 848
7. Functions, accessing variable members
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:
Code:
// 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;
}
Ok, this has been known from start but it's easily forgotten
http://apolyton.net/ctp2/modificatio...ion/slic.shtml
mapfi is offline  
Old November 16, 2002, 19:56   #10
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: 11:04
Local Date: November 1, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
Not really an oddity but something that probably few people know about or will find out on their own, so I decided to just add it here:

If you want to start a on new line in a text message (i.e. you would like to hit 'Enter'), use '\n'. The next sign will be placed on a new line. Tab is also available: \t.
__________________
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 05:04.


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