Null character pointer

Started by Saub, Wed 31/12/2014 12:17:36

Previous topic - Next topic

Saub

Hi, I am trying to create a situation where an enemy (cTigerbad) touches any other character, that character will move to certain co-ordinates.

I thought I could add the below in the rep ex to check if the tiger is touching a character, assign the pointer "Charhit" to that character then make them move, but when the tiger does touch the character the game crashes due to null pointer on the last line.

Code: ags

 if (Character.GetAtScreenXY (cTigerbad.x, cTigerbad.y) != null){
 Character * Charhit =  Character.GetAtScreenXY (cTiger.x, cTiger.y);
 Charhit.Move (100, 180, eNoBlock, eAnywhere);}


I'm worried I may have completely misunderstood the use of the character pointer - any help would be appreciated!

Monsieur OUXX

I think that your issue is very simply that you check what character is at (tigerBad.x, tigerBad.y) but then you compute something using (tiger.x, tiger.y).


The code should be :

Code: ags

Character * Charhit=  Character.GetAtScreenXY (cTigerBad.x, cTigerBad.y);
if (Charhit!=null) {
    Charhit.Move (100, 180, eNoBlock, eAnywhere);
}

 

Saub

Drats! I cannot believe I missed that.

Thanks very much for pointing it out (and also for the more efficient way to write the code!)

Happy new year.

SMF spam blocked by CleanTalk