Author Topic: Can't get flashlight-esque functions to run [solved]  (Read 382 times)  Share 

Akatosh

  • Still dropping by every couple of months
    • Best Innovation Award Winner 2007, for '_Access'
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
  • Akatosh worked on a game that was nominated for an AGS Award!
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]
tempsprite=DynamicSprite.CreateFromExistingSprite(gGui1.BackgroundGraphic);

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

//Other crap
[/code]


repeatedly_execute

[code]
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
[/code]


The functions in question

[code]
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;
}
[/code]
« Last Edit: 30 Nov 2008, 17:05 by Akatosh »

Re: Can't get flashlight-esque functions to run
« Reply #1 on: 30 Nov 2008, 16:16 »
Shouldn't this code from PlaceLightSource

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

be

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

?

As I understand the code, you're searching for the first unused light source, not one that already exists?

Akatosh

  • Still dropping by every couple of months
    • Best Innovation Award Winner 2007, for '_Access'
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
  • Akatosh worked on a game that was nominated for an AGS Award!
Re: Can't get flashlight-esque functions to run [solved]
« Reply #2 on: 30 Nov 2008, 17:04 »
Yep, that did the trick...it never occured to me the error could be in THAT function...  :-[

Anyway, thanks for the quick assistance.  :)