 |
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/showthre...?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 on 07-10-2002 at 23:27
|
|
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/showthre...?threadid=59742
Last edited by mapfi on 07-10-2002 at 22:38
|
|
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/showthre...30&pagenumber=3
Last edited by mapfi on 07-10-2002 at 22:51
|
|
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/showthre...30&pagenumber=3
Last edited by mapfi on 07-10-2002 at 22:59
|
|
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/showthre...?threadid=63901
Last edited by mapfi on 12-10-2002 at 02:54
|
|
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/showthre...?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 on 18-10-2002 at 16:08
|
|
|  |
 |
|
ahenobarb
|
|
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 on 19-10-2002 at 23:33
|
|
|  |
 |
|
mapfi
|
|
Zurich, Switzerland
Jul 2002 time: 06:22
|
|
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/modificati...sion/slic.shtml
|
|
|  |
All times are GMT. The time now is 05:22. Apolyton Time is 00:22. |
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
|
|
|
|
|
|