Overlay Question (SOLVED)

Started by Dualnames, Fri 06/01/2012 23:49:17

Previous topic - Next topic

Dualnames

I want to run something by you guys. I'm using the code below for an overlay thingie.
So I'm running this code on a repeatedly execute always. Start and yaah are just two booleans initially set to false.

Initially the game threw me a error:ScriptOverlay isn't there. So I'm wondering is checking if an Overlay is null and then if it's Valid the best way to make sure, that I don't get the error?


Code: ags

function repeatedly_execute_always() 
{


if (start==true) 
{
    if (yaah==true) 
    {
       bgspeech = Overlay.CreateTextual(cCrispin.x-GetViewportX()-(getheight.Width),  cCrispin.y+25-(getheight.Height), 255, eFontSpeech, cCrispin.SpeechColor, 
    }
    if (yaah==false) 
    {
       if (bgspeech!=null) 
       {
          if (bgspeech.Valid) 
          {
             bgspeech.Remove();
             start=false;
          }
      }
   }
}

}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

Yes, you can do it one go though:

Code: ags
  if (bgspeech && bgspeech.Valid)


AGS will evaluate the condition from left to right and thus shouldn't throw a null pointer error.

Dualnames

Alright. I think I'm satisfied.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk