Making a flashlight.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Making a flashlight.

Post by disanti »

Code: Select all

//flashlight
		case INPUT_F:
			flashlight = !flashlight;
			if(flashlight)
			{
				//make the player light
				playerlightnode = gProc.smgr->addLightSceneNode(camera,
					droid.position, 
					irr::video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 50.0f);
			}
			else
			{
				playerlightnode->removeAll();
			}
		break;
This crashes if I press F (to turn the flashlight on). Is there any knowledge of a better way to do this? :?
________
Zx14 vs hayabusa
Last edited by disanti on Tue Feb 22, 2011 8:05 am, edited 1 time in total.
Nessie
Posts: 14
Joined: Thu Apr 08, 2004 4:27 pm
Location: Madison, WI, USA

Post by Nessie »

I pasted your code into my application and it worked fine. Any other details? Such as, which is the line that causes the crash?

Of course, I'm going to assume you've initialized your flashlight variable to 0, false, etc. I did as well, and no crashes.

Otherwise, if it's a random value at game start, flashlight will be toggled to 0 right after you case INPUT_F: line...and since playerlightnode is probably unitialized at that point, doing a removeAll() is not valid.
"Build a man a fire and he'll be warm for the evening. Set a man on fire and he'll be warm for the rest of his life." -unknown
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

Oh, thats why it wasn't working! :oops: I figured out a faster method anyway, that is to position the light WAY out in the middle of nowhere and then position it back when needed. ;)
________
Swed
Post Reply