Jump to content

Light disable/enable problem


VikingII

Recommended Posts

My ship has lamps that were run over the ‘streeglightscript’ already in the game that enables, disables it at night.

 

scriptname streetlightscript

begin gamemode

if gamehour >= 18 || gamehour < 7
enable
else
	disable
endif

end

 

But when I travel during the day (when lights are disabled), the travel script disables the ship in Waterfront and enables in Anvil but not the lights (that were already disabled by the streetlightscript), so at night, lights turns enable, alone in the middle of the sea, because they were not affected by the travel script.

 

I tried to script two different scripts instead the ‘streetlightscript’, something like this:

 

scriptname ShipLightAB

begin gamemode

if ((gamehour >= 18) && (ABVesselDeck enable)) || ((gamehour < 7) && (ABVesselDeck enable))
	enable
else
	disable
endif

end

 

So, at last, the lights get disabled when the travel script disables all parts of the ship, but they did not turns off, they remain constantly enabled 24 hours.

 

Is there a better way to disable the lights (that were already disabled by the ‘streetlightscript’) without adding more scripts that adds unnecessary complexity? Or, if is not possible, what is the error in my script?

Link to comment
Share on other sites

Have one light or object that enables/disables itself properly and make it persistent. Then for all the others, set them to "Enable Parent" and assign the one light as a parent.
Link to comment
Share on other sites

If both, lights and travel, work by enabling and disabling, it is paramount not to mix these up. An object can only have one state, enabled or disabled. If your streetlight script disables the lights but the travel script enables the new ones, they will get enabled even though it's not night when you travelled. The same goes for the now-floating lights where the ship was before. They never "moved" away, they just got disabled when traveling away. The streetlight script will still enable them at the proper time, whether their ship is enabled or not. You need to check for both conditions in their scripts, so traveling lights will always disable but not enable during day and only lights the ship of which is enabled will enable during night.

 

Might help to store the ship's location in a quest script or something.

 

edit: Re-reading your second script... "if (ABVesselDeck enable)" actually works and doesn't crash the compiler?? It's totally bogus syntax, enable can't return a value and it can't be used without a reference, that is unless the light the script is running on now is the reference instead... coming to think of it, that's the case, you enable the light by this line but don't actually "check" anything. I would use "ABVesselDeck.GetDisabled" instead. This way you would save storing the ships position as mentioned above.

Edited by DrakeTheDragon
Link to comment
Share on other sites

My ship has lamps that were run over the ‘streeglightscript’ already in the game that enables, disables it at night.

 

scriptname streetlightscript

begin gamemode

if gamehour >= 18 || gamehour < 7
enable
else
	disable
endif

end

 

But when I travel during the day (when lights are disabled), the travel script disables the ship in Waterfront and enables in Anvil but not the lights (that were already disabled by the streetlightscript), so at night, lights turns enable, alone in the middle of the sea, because they were not affected by the travel script.

 

I tried to script two different scripts instead the ‘streetlightscript’, something like this:

 

scriptname ShipLightAB

begin gamemode

if ((gamehour >= 18) && (ABVesselDeck enable)) || ((gamehour < 7) && (ABVesselDeck enable))
	enable
else
	disable
endif

end

 

So, at last, the lights get disabled when the travel script disables all parts of the ship, but they did not turns off, they remain constantly enabled 24 hours.

 

Is there a better way to disable the lights (that were already disabled by the ‘streetlightscript’) without adding more scripts that adds unnecessary complexity? Or, if is not possible, what is the error in my script?

 

 

Try this:

 

scriptname ShipLightAB

begin gamemode

if (ABVesselDeck.getDisabled == 0)
	if ((gamehour >= 18) || (gamehour < 7)) && getDisabled == 1
		enable
	endif
elseif getDisabled == 0
	disable
endif

end

 

Also, as Lanceor suggests, attach this script to only one of the lights. Make it a persistent reference and for the other scriptless lights set their enable parent to this one. This cuts down on the number of scripts running.

Link to comment
Share on other sites

Lanceor, this solution looks more elegant than lots of scripts for each light. I linked the lights to the ship's deck and used the common ‘streetlightscript’ that uses the game. The lights get enables and disables with the deck (no more floating torches without ship), but they not follow their script 'stretlightscript' that disables them on day, so, they are 24 hs on fire, give me a constant sense of waste oil and been not ecologist. xD

 

DrakeTheDragon, thanks for the corrections. Ideally for this script should be (if ABVesselDeck.GetEnabled) but this not exist, so I tried with (if ABVesselDeck != GetDisabled), and it didn’t work. The lights turn on in every dock the ship is (enabled or disabled) at the same time.

 

Evenstargw, I test your script too, and it causes the same behavior as Lanceor suggest, the lights get enabled and disabled when I travel, but they stay on fire all the day. The lights still on even if I don’t trigger the travel script, when I found the ship, at daylight, the torches are on.

 

I have a question: What means the ‘0’ and ‘1’ values that you add to the getDisabled? Do I need to declare a variable in some other place or these are general values?

 

I think a script who adds two conditions at the same time (the hour and the status of the ship) should work. So there are two possible explanations: 1 it is impossible to do in this game, and 2, I am doing something wrongs again (the most possible xD).

 

Thanks for trying to help anyway; it means lot of learning to me!

Link to comment
Share on other sites

I know it's possible as I've done the same thing except with lightbeams through a window which are on during the day but only if you haven't closed the curtains.

 

getDisabled returns 1 if the object it is called on is currently disabled, or 0 otherwise. So using getDisabled == 0 is the same as what you tried to do with getEnabled (a function which doesn't exist). ABVesselDeck.getDisabled == 0 means that the lights will only go on if the deck is enabled (assuming ABVesselDeck is the referenceID you gave to the deck). Now you need to make sure the main light is a persistent reference and has no enable parent. The rest of the lights should be unscripted but have their enable parent set to your main light. The loose getDisabled calls are to check if the light itself is already enabled/disabled so it doesn't have to call enable or disable again until the conditions change. I read somewhere that calling enable/disable is a bit heavier than checking the state so it improves performance.

Link to comment
Share on other sites

Evenstargw, I removed all the lights references from the travel script. That has been causing the malfunction of the light script. Now your script works well in most of the scenarios:

 

-When I first see the ship, the lights are active forever, day or night (That’s wrong).

-But the in the ship’s destinations, lights are inactive like their ships (That’s right).

-When I trigger the travel script, the lights becomes active or inactive together with the ships (That’s right)

-And their behavior is restored, turning active on night and inactive on day (That’s right)

-But this happens only the first time I travel: the lights turns on or off just when I trigger the travel script, then, the time pass and the lights turn on at night and never turn off again.

 

At this point, I have removed the lights from the travel script. They turns on or off with a time reference, and the ship status reference.

 

I think the problem is close to be solving, there must be a little thing that interrupt the on/off behavior.

Link to comment
Share on other sites

The script I typed was meant to be an object script attached to a light object. If you make it part of the travel script then it needs some changes. Also I see I made a silly mistake.

scriptname ShipLightAB

begin gamemode

if (ABVesselDeck.getDisabled == 0)
	if ((gamehour >= 18) || (gamehour < 7)) && getDisabled == 1
		enable		
	elseif (gamehour < 18) && (gamehour >= 7) && getDisabled == 0
		disable
	endif
elseif getDisabled == 0
	disable
endif

end

 

That may work better. Edit - dunno where my head is today.

Edited by evenstargw
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...