Author Topic: Item Animated Light Issue  (Read 1980 times)

I've been messing around with items recently and I made my item emit a particle and a light, however I'd like to have the light animate, as in flicker in and out from the source. Like a fire or candle flame, since my item emits a "flame". I've tried a few things and even found some documentation on the code for it (I believe) but cannot get it to work right or at all. It emits a constant light that doesn't flicker and has a spastic white particle thing where the flame particles are (and the flame particles are still being emitted as well). Any help is much appreciated :)


https://forum.blockland.us/index.php?topic=303883.msg9304914#msg9304914

Hmm I did find that post earlier and tried that and what I said above is the progress I made which is not much lol. Guess I'll have to keep messing with it.

This is what I get along with my emitters/light... (the white "smoke")

This is what I get along with my emitters/light... (the white "smoke")
thats the light flare bitmap, probably. should be defined in th edatablock

thats the light flare bitmap, probably. should be defined in th edatablock

OK I'll look into that later, I just removed all particles/emitters for the time being. I made some progress, tho. I got the light to flicker and to turn off and on with corresponding sounds and whatnot. Now I have an issue with the light not going away -_- Like if you turn on the lamp, then unequip your tools (press CTRL button for me to close them out) the light stays and so does the model of the lamp, which is wrong. Then you can just spam doing that and build up light upon light upon light and its can get really bright. grr.

OK I'll look into that later, I just removed all particles/emitters for the time being. I made some progress, tho. I got the light to flicker and to turn off and on with corresponding sounds and whatnot. Now I have an issue with the light not going away -_- Like if you turn on the lamp, then unequip your tools (press CTRL button for me to close them out) the light stays and so does the model of the lamp, which is wrong. Then you can just spam doing that and build up light upon light upon light and its can get really bright. grr.
need to properly unmount it then? post the addon here

need to properly unmount it then? post the addon here

I messed with it some more and I think I backtracked a little lol but I made one of the sounds better at least. Feel free to take a look.

Download: http://www.mediafire.com/file/95limkhtzw9navn/Item_HandheldLantern.zip

do you need any more help with the light keys or are you happy with the torch light key frames?

Then you can just spam doing that and build up light upon light upon light and its can get really bright. grr.

You could try adding this to each UnMount function
Code: [Select]
if(isObject(%obj.light))
%obj.light.delete();

You could try adding this to each UnMount function
Code: [Select]
if(isObject(%obj.light))
%obj.light.delete();

I thought I tried that but there were some other bits of code or whatever so I'll see if this helps.

do you need any more help with the light keys or are you happy with the torch light key frames?

They are pretty good but not as varied as I'd like, a working placeholder atm. I'll probably add/take away as needed but right now I just need certain things to work.

Why does this...
Code: [Select]
if(isObject(%pl.light))
{
%pl.light.delete();
}
...refuse to work anywhere I put it? And why does my right hand show up again after I turn on the lamp when it was fine before I added the light?

Code: [Select]
function lantern_OFF_Image::onMount(%data, %obj, %slot)
{
%obj.hideNode(RHand);
%obj.hideNode(RHook);

if(isObject(%pl.light))
{
%pl.light.delete();
}
}

function lantern_OFF_Image::onUnMount(%data, %obj, %slot)
{
if(isObject(%client = %obj.client))
{
%client.applyBodyParts();
}

else
{
%obj.unHideNode(RHand);
%obj.unHideNode(RHook);
}
}

function lantern_EQUIP_Image::onMount(%data, %obj, %slot)
{
%obj.hideNode(RHand);
%obj.hideNode(RHook);

if(isObject(%pl.light))
{
%pl.light.delete();
//%pl.schedule(1,mountImage,lantern_OFF_Image,1);
//%pl.playThread(3,plant);
}
}

function lantern_EQUIP_Image::onUnMount(%data, %obj, %slot)
{
if(isObject(%client = %obj.client))
{
%client.applyBodyParts();
}

else
{
%obj.unHideNode(RHand);
%obj.unHideNode(RHook);
}
}

function lantern_ON_Image::onMount(%db, %pl, %data, %obj, %slot)
{
%obj.hideNode(RHand);
%obj.hideNode(RHook);

%pl.light = new fxLight()
{
datablock = lanternLightOn;
};
missionCleanup.add(%pl.light);
%pl.light.setTransform(%pl.getPosition());
%pl.light.attachToObject(%pl);
%pl.light.player = %pl;
}

function lantern_ON_Image::onUnMount(%data, %obj, %slot)
{
if(isObject(%client = %obj.client))
{
%client.applyBodyParts();
}

else
{
%obj.unHideNode(RHand);
%obj.unHideNode(RHook);
}

if(isObject(%pl.light))
{
%pl.light.delete();
}
}

function lantern_EQUIP_Image::onLight(%this, %obj, %slot)
{
%obj.unMountImage(0);
%obj.mountimage(lantern_ON_Image, 0);
}

function lantern_OFF_Image::onFire(%this, %obj, %slot)
{
%obj.unMountImage(0);
%obj.mountimage(lantern_ON_Image, 0);
}

function lantern_ON_Image::onFire(%this, %obj, %slot)
{
%obj.unMountImage(0);
%obj.mountimage(lantern_OFF_Image, 0);

if(isObject(%pl.light))
{
%pl.light.delete();
//%pl.schedule(1,mountImage,lantern_OFF_Image,1);
%pl.playThread(3,plant);
}
}

You're using the wrong variable. For example:

Code: [Select]
function lantern_OFF_Image::onMount(%data, %obj, %slot)
{
%obj.hideNode(RHand);
%obj.hideNode(RHook);

if(isObject(%pl.light))
{
%pl.light.delete();
}
}

You're referring to an attribute of an object referred to as %pl, but you haven't instantiated %pl anywhere. You probably meant to type this instead:

Code: [Select]
function lantern_OFF_Image::onMount(%data, %obj, %slot)
{
%obj.hideNode(RHand);
%obj.hideNode(RHook);

if(isObject(%obj.light))
{
%obj.light.delete();
}
}

In this particular function, %obj refers to the player, %data refers to the image datablock.

You're referring to an attribute of an object referred to as %pl, but you haven't instantiated %pl anywhere. You probably meant to type this instead:

Code: [Select]
function lantern_OFF_Image::onMount(%data, %obj, %slot)
{
%obj.hideNode(RHand);
%obj.hideNode(RHook);

if(isObject(%obj.light))
{
%obj.light.delete();
}
}

In this particular function, %obj refers to the player, %data refers to the image datablock.

Thank you Rally, that worked. Though I don't know why lol. I can't find anywhere that *explains* all these different variables and whatnot and learning by doing is rough but progress is being made :p

Thank you Rally, that worked. Though I don't know why lol. I can't find anywhere that *explains* all these different variables and whatnot and learning by doing is rough but progress is being made :p
Here's how it works:

See the function declaration? The engine handles those arguments and the function calling, so all you have to do is find out what is being passed into your function that you made that the engine is able to implement.

If the engine calls: data::onMount(data, player, slotNum) you can make the 3 args of your function anything you want as long as you use them,
function data::onMount(%data, %player, %slotNum) is the same as function data::onMount(%image, %obj, %slot), it's just you have to use those passed argument names in your function.

If you make function data::onMount(%data, %obj, %slot, %something) the engine will not pass the 4th argument (%something) because the engine is only using 3 arguments to pass.
This is the same when making your own functions and passing your arguments to something else.

Example: We will use the first 4 arguments (args) and have them pass onto another function
abc("test 1", "test ABC", "test c", "useless argument");
Code: [Select]
function abc(%a, %b, %c, %d)
{
      cde(%a, %b, %c);
}

Arguments being passed but named differently, they will still work because they were passed from another function - note that %d will NEVER be passed from abc because this function only has 3 arguments.
Code: [Select]
function cde(%c, %d, %e) {}%c is now "test 1"
%d is now "test ABC"
%e is now "test c"

the 4th argument we tried to pass is now thrown away because we hit the max arguments in our passed function - the engine is like this too except it wants it perfect, if you are low on arguments or have too many the console will yell at you for it because they are engine functions directly in the game for torquescript (not torquescript functions)
« Last Edit: July 21, 2017, 06:21:34 PM by Kyuande »