Overlay / null pointer problem (Solved very swiftly)

Started by Ali, Fri 06/10/2006 12:03:34

Previous topic - Next topic

Ali

I'm not sure if this belongs here or in beginners, but I'll ask anyway.

I define and export overlay pointer (bellOverlay) at the start of my main script and import it in the global header.
I've scripted an object interaction which creates the overlay and removes it, and that works fine. It's for a ringing bell. I then shifted the code to a dialog request, and that still worked.

The problem is that I need to have the overlay appear during a dialogue and stay on screen for a period of time after, so the bell stays ringing while control returns to the player.

I added a timer and shifted this line:

if (bellOverlay.Valid==1) bellOverlay.Remove ();

from the end of my dialog-request to repeatedly-execute like this:

if (bellTimer==0){
if (bellOverlay.Valid==1) bellOverlay.Remove ();
//stop the bell animation
}

This will compile but the game crashes because of a 'null pointer' reference when I enter the room. I feel I must have failed to import the pointer properly, but I can't see how. I'd be thankful for any help.

-Ali

SSH

#1
You need to do:

Code: ags

if (bellOverlay!=null && bellOverlay.Valid==1) bellOverlay.Remove ();


As the Valid method can only be run on a non-null pointer.
12

Khris

It's gotta be
if (bellOverlay!=null && bellOverlay.Valid) bellOverlay.Remove();
==1 works, too, but the ! is a must :=

Ali

Thanks guys, I think I understand it now. I was a little mixed up about what 'Valid' was actually checking. Let the bells ring out (via a textual overlay)!

monkey0506

It's already been cleared up, but I'd just like to point out that "null" is equal to 0, so when you checked "bellOverlay == 0" you were checking that it was null, not that it wasn't.

Edit by strazer:

Quote from: Pumaman on Wed 18/10/2006 21:28:21The only suggestion I'd make is to remove the bit about null being equivalent to 0, since it isn't. You can't compare a pointer to 0 and mentioning it in the tutorial is probably just going to confuse people.

SSH

That's not a clarification, becuase he wasn't checking that... its also bad practice
12

monkey0506

It's not bad practice. It's a matter of preference. The memory address at 0 will always be the null-pointer-memory address. ALWAYS!


-.-

SSH

Transputer processors used a SIGNED address space so their null pointer was -0x80000000. And there's no reason why null needs to be 0 other than people using bad coding practice. Strongly typed languages will enforce this. Also, using null conveys the meaning of the code mode than 0. Also, it is best to use named constants rather than integer literals where possible.
12

SMF spam blocked by CleanTalk