Can't get flashlight-esque functions to run [solved]

Started by Akatosh, Sun 30/11/2008 14:27:15

Previous topic - Next topic

Akatosh

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

Code: ags

tempsprite=DynamicSprite.CreateFromExistingSprite(gGui1.BackgroundGraphic);

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

//Other crap



repeatedly_execute

Code: ags

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

Code: ags

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;
}

GarageGothic

Shouldn't this code from PlaceLightSource

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


be

Code: ags
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?

Akatosh

Yep, that did the trick...it never occured to me the error could be in THAT function...  :-[

Anyway, thanks for the quick assistance.  :)

SMF spam blocked by CleanTalk