Game Development Community

Dynamicly Changing a Light's Color (Solved)

by Steven Crump · in Technical Issues · 12/28/2009 (6:05 am) · 8 replies

I'm a bit new to scripting still, so I'm sorry if this is a very basic problem, I'm sure it is.

I've been trying to get a basic light changing trigger to work, but for some reason that actual color of the light's isn't updating. The basic idea of what I'm trying to is that when, say red team captures blue's base, the lights in the base change from blue to red.

So far I just have some test code I've been trying to mess with:

datablock TriggerData(LightChange)
{
tickPeriodMS = 100;
};

function LightChange::OnEnterTrigger()
{
Light1.color = ("1 1 1 1");
Light2.color = ("1 1 1 1");
Light3.color = ("1 1 1 1");
}

The trigger works halfway so far. When someone walks through the trigger, nothing visually happens to the lights. However, if I am in the World Editor and check the properties of the lights after I walk through the trigger, the values have actually changed to the new color. At this point, if I just click on the field and press 'Enter', the change occurs just fine, but this obviously doesn't actually fix my problem.

One alternative I thinking I could do is to just have 2 sets of lights, and just toggle between the two sets (turning one on and the other off when appropriate), but that just feels like a rather inefficient way to do it.

I'm thinking all I am missing is some sort of update function or something really simple, but I've searched everywhere I can think of and have no idea.

About the author

Student at Columbia College enrolled in their Video Game Design major with a concentration in Game Development. The primary engine we learn is Torque, and I am trying to focus my efforts to becoming as efficient at scripting as I possibly can.

Recent Threads


#1
01/19/2010 (12:57 pm)
Did you ever locate the solution to this question?

I have a similar issue, where a change in a value visible in the palette fields doesn't take effect until the field is clicked in the World Editor.

My attempt is made in trying to set the "coverage" property of a CloudLayer object. This seems to be a networked object, but I can't figure out how to get the change to take effect on the client. The values seem to be set and can be read back in script and printed to the console, but the clouds in the sky do not change until the client is quit and reentered. I am not sure if I have to somehow send the whole CloudLayer object (and just exactly how to trigger that), or just the value of the field.
#2
01/19/2010 (1:28 pm)
You'll at least need to make a function that changes and then updates the change, probably in cpp, and then expose it to script via a console method.
#3
01/19/2010 (11:47 pm)
I am looking at this resource:

http://www.torquepowered.com/community/resources/view/19015

although I am not really certain how that communicates the new information to the client.

Thanks for the reply, Mr. Acaster.
#4
01/24/2010 (7:18 pm)
Hi Steven,

Steve Acaster is correct. Although the values are changed, they need to be applied before they will show up in game. (The actual engine function to do this for a lightBase object is inspectPostApply(), but this function is not exposed to TorqueScript).

I have already posted a resource to allow dynamic light colour changes via script (as Netwyrm has pointed out) using this method. It's a very simple engine mod and can be found here : Dynamic light change console function

Hope this works for you
#5
02/07/2010 (1:15 am)
Sorry for the late response, been busy with other projects and forgot about this reply for a while.

I've tried that resource, but I haven't been able to quite make it work yet. I'd say the current problem is that I'm still a bit new to scripting and am not quite sure how everything works yet.

The main problem I'm having following the resource right now is that I don't know where lightBase.h or lightBase.cpp are. I'm assuming that they are files I have to make and fill out myself at the moment. Then I'm assuming that I have to make light objects inherit from it or something, which I'm not quite sure how to do either.
#6
02/07/2010 (2:27 pm)
Hi Steven,

The lightBase.h and lightBase.cpp files are engine source code ( C++ language ). I see that you have the student edition of T3D - does this include the source code? If not I am afraid you will not be able to implement the resource as it is a change to T3D's actual engine code. As far as I am aware there is no way to dynamically change a light's properties via script.
#7
02/08/2010 (9:59 pm)
Suddenly everything makes sense!

Not really but close, I got it to work. I wasn't actually aware of the "Edit Source" button on the toolbox menu until you mentioned source code. I went in and found the files without any problem and put your code in. It didn't work at first, but I had a friend take a look at it and it didn't work because I didn't know that I had to rebuild the project, and apparently link all of my Direct X Libraries to Torque, both of which I should probably take a look into how to do.

But yeah, I got it to work just fine now. Thanks for all the help!
#8
02/09/2010 (5:59 am)
Excellent! Glad you got it to work Steven.

(And welcome to the dark and mysterious world of programming, hehe :)