Tuesday, November 1, 2011

Fixing the SLS, light tag bug

Problem: The SLS lighting system relies on the tags of lights. However, saving and reloading the game causes lights to lose their tags, breaking SLS.

Solution: change of the SLS' ginc_sls2 script to reset the tag of the nearest light object when the action to handle placeable lights is called. Solution a bit below.

potential issue: assumes the nearest light object is the one to be used. This is normally the case, but you may want to make a copy of the scripts and use the altered script where you know the closest light will be the right one, such as for usable placeables like torches.

in ginc_sls2, line 352 is:
string sLightTag = GetLocalString(oFitting,"lightTag");

comment that out and replace it with
            //work around tag bug. kamal
            object oLight = GetNearestObject(OBJECT_TYPE_LIGHT, oFitting, 1);
            string sLightTag = GetLocalString(oFitting,"lightTag");
            SetTag(oLight, sLightTag);

This will change the script that controls turning the light on and off, so that it resets the light's tag automatically when the light is used, and then proceeds normally through the script. It does assume the light you want to turn on is the nearest light, but I believe that will be the case in almost all cases.

As an added bonus: If you make this change to ginc_sls2, and save ginc_sls2 to your override folder, it should fix the problem in every single player module that uses the SLS, thanks to the priority of the override (PWs can ignore the override folder).


  1. Hi Kamal,

    What a conincidence! I was fixing my own light system just a few weeks ago and was addressing the same issue of lights losing tags between loads.

    In the end, I simply added a variable on their first reference and then did the checks via the variable rather than tags from that point on.

    i.e. SetLocalInt(oLight, "LightTagFixMood", 1); when first using their tags and then ...
    if(GetLocalInt(oLight, "LightTagFixMood") == 1){SetLightActive(oLight, TRUE);} when doing a search for lighst in an area.

    This way, all and any lights you want to turn on or off can be found in one loop whenever you want them to turn on or off, without being limited to just the nearest one.

    If you want me to send you my full script, then I can do. It simply sits in teh module heartbeat and turns all lighst on or off according to the hour of the day. As long as the lights are initially tagged as ModdLight, the script fixes the tag problem on its first loop pass.

    P.S. I posted again in your last blog as well.


  2. Here's the area again

  3. That is Estate wall 3 and estate ceiling 3 by the way in the picture. It has that pattern if you change the wall colors so they're not all the same.

  4. Hi Kamal,

    I downloaded this again and tried importing again ... it imports OK, but whenever I try to open the area in the toolset, it crashes the toolset again. :(

    Any ideas what may be happening?

    What happens if you try to import your area into a new module build?

    Maybe you ould try zipping or winrar the erf file before uploading it to Dropbox?

    I am looking at your other area now and reworking it to fit in with one of my own area requirements. You have a gift for design. :) I hope you do not mind me working with it like this? It should be different enough to be different, but you might still recognise your own work.


  5. Go ahead and use it. As I did for Path of Evil, I will be releasing all the areas I make for Crimmor. I'll see about trying that area in a blank module when I get the chance.

  6. http://dl.dropbox.com/u/3879894/exported.7z

    for what it's worth, I imported the erf from dropbox without issue.

  7. Couldn't you just use the ResRefs instead? I'm not sure if those are lost upon reloading the module, but I don't see how they could.

    - Anduraga

  8. Hi Kamal,

    I downloaded the latest and it still crashes the toolset whenever I try to open the area to look at it in the toolset. I even tried loading it into another toolset on a second computer and same thing! So ...

    1) I can import the erf no problem.
    2) I try to open area ... crash!

    Can you OPEN the area after importing it?

    0 ---- 0

    Hi Anon,

    I hope Kamal does not mind me answering here as well .... I imagine you could use resrefs as a check instead of a variable. That would be best if you were already aware of the problem and set about using distinct resrefs from the start. However, if you have already placed many lights already, that are supposed to work with tags, then using a small bit of script to add/check a variable is probably easier. After all, it may be that you have some lights that use the same resref (but different tags) that you do not want to turn on and off. You could either redo all the lights that matter throughout the different areas (change their resrefs) of add a bit of script to check the ones that use a certain tag already.

    I hope that makes sense.


  9. Lance,
    Yes, I opened the area and everything. In fact I did that second export from the empty module I'd imported the area into using the first export. So I don't know what's going on, but ask your questions about it and I will look and answer.

  10. I'm not sure if you can get the resref of an object (ive never considered that).

  11. Hi Kamal,

    I was going to ask how you did the "lattice" work, but I think I worked it out that you used "jail" pieces.

    The main reason for being able to get at your work now is somply to adapt it to use for an area I have in mind.

    What are the chances of zipping up a kamal.mod module version of just that area rather than an erf? Maybe we can try getting around it that way?

    It's really strange that one area worked, but the other does not. Are you using a high spec computer that (perhaps) allows areas with more data in them to open and it is a very "busy" area perhaps? I'm just making guesses now.

    If we can try a cut down mod version of just the area, that would be good - if you are OK with trying that?


  12. http://dl.dropbox.com/u/3879894/basic_area.erf

    I've taken out everything not visible in the screenshots, so it's just two rooms and empty tiles elsewhere. It can't get simpler than that. Yes, those are jail pieces. I thought you were referring to the walls themselves, which have a fleur de lis style latticework pattern.

  13. I do have a very high spec pc, but I've done much more complicated work on my old much lower spec pc (like making some of the Crimmor exteriors). This area isn't really heavy with anything.

  14. Hi Kamal.

    That worked! Yeh!

    Thanks for this - It takes a whole load off my mind knowing I can use these to help with my own module.

    I was curious about the wall designs as well, as I had not seen those either. I guessed they must have been an option, but its not always easy to find them unless you are into area designing. :)

    Thanks again!

    Keep up the great work.