Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Akatosh on Sun 30/11/2008 14:27:15

Title: Can't get flashlight-esque functions to run [solved]
Post by: Akatosh on Sun 30/11/2008 14:27:15
Okay. For an unspecified project of mine, I've been toying around with custom "lighting" functions - as in, having one function for drawing holes into an all-black GUI and one for covering up these holes again once it's time. The former works just fine... the latter doesn't seem to run at all. It's probably soul-crushingly simple, but I just can't see what's wrong with the code. So, uh, some help please?  :-\

The relevant code:

game_start


tempsprite=DynamicSprite.CreateFromExistingSprite(gGui1.BackgroundGraphic);

int MNB=0;
while (MNB<MaximumLightSources) {
lightR[MNB]=-1;
MNB++;}

//Other crap



repeatedly_execute


jiji=0;

while (jiji<MaximumLightSources) {
 
player.SayBackground(String.Format("%d", jiji));

if (lightR[jiji]>-1) { 
  lightT[jiji]--;
  if (lightT[jiji]<=0) RemoveLightSource(jiji);
}

jiji++;
}

//Some stuff about calculating sound[0]
temprad=FloatToInt(sound[0]*2.0);

PlaceLightSource(player.x, player.y, temprad,  1);

//Some stuff about movement



The functions in question


function PlaceLightSource(int x, int y, int radius, int time) {

int countIndex=0;
while ((countIndex<MaximumLightSources)&&(lightR[countIndex]==-1)) countIndex++;

DrawingSurface *lightmap=tempsprite.GetDrawingSurface();

lightX[countIndex]=x;
lightY[countIndex]=y;
lightR[countIndex]=radius+1;
lightT[countIndex]=time+1;

lightmap.DrawingColor=COLOR_TRANSPARENT;
lightmap.DrawCircle(x, y, radius);
lightmap.Release();
gGui1.BackgroundGraphic=tempsprite.Graphic;
}


function RemoveLightSource(int lightSourceNumber) {

DrawingSurface *darkmap=tempsprite.GetDrawingSurface();

darkmap.DrawingColor=33;
darkmap.DrawCircle(lightX[lightSourceNumber], lightY[lightSourceNumber], lightR[lightSourceNumber]+1);
darkmap.Release();
gGui1.BackgroundGraphic=tempsprite.Graphic;

lightX[lightSourceNumber]=-1;
lightY[lightSourceNumber]=-1;
lightR[lightSourceNumber]=-1;
lightT[lightSourceNumber]=-1;
}
Title: Re: Can't get flashlight-esque functions to run
Post by: GarageGothic on Sun 30/11/2008 16:16:26
Shouldn't this code from PlaceLightSource

while ((countIndex<MaximumLightSources)&&(lightR[countIndex]==-1)) countIndex++;

be

while ((countIndex<MaximumLightSources)&&(lightR[countIndex]!=-1)) countIndex++;

?

As I understand the code, you're searching for the first unused light source, not one that already exists?
Title: Re: Can't get flashlight-esque functions to run [solved]
Post by: Akatosh on Sun 30/11/2008 17:04:57
Yep, that did the trick...it never occured to me the error could be in THAT function...  :-[

Anyway, thanks for the quick assistance.  :)