[SOLVED] Is this a bug or am I stupid? Mouse cursors

Started by bx83, Mon 03/04/2017 01:17:16

Previous topic - Next topic

bx83

Hello all

Having a problem with a bug - in my code, or in the AGS interpretor?

in globalscript, in function UpdateMouseGraphic:

Code: ags

...
else if (mouse.Mode==eModeLookat) {
    newGraphic=105; //eye close
    if (lt == eLocationHotspot) {
      Hotspot *hs = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      if (hs != hotspot[0]) {
        if (hs.GetProperty("hidden")==false) { 
            newGraphic=2056;  //eye open
        }
      }
    }
  }
  else if (mouse.Mode==eModeInteract) {
    newGraphic = 2;  //interact off
    Hotspot *hs = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    if (hs != hotspot[0]) {
      if (hs.GetProperty("hidden")==false) {
        newGraphic=286;
      }
    }
    if (lt == eLocationObject) {
      newGraphic=286;
    }
  }  
...


also in globalscript:

Code: ags

function Candlelight_on (Object *obj, InventoryItem *Inv) {
  if (!cJulius.HasInventory(Inv)) {

    obj.Visible=true;
    obj.Clickable=true;

    if ((mouse.x - obj.X) >= 0) {
      if ((mouse.y - obj.Y) >=0) {
        trans = (( (mouse.x - obj.X) + (mouse.y - obj.Y) ) /2);
      } else
      if ((mouse.y - obj.Y) <=0){
        trans = (( (mouse.x - obj.X) - (mouse.y - obj.Y) ) /2);
      }
    } else
    if ((mouse.x - obj.X) <= 0){
      if ((mouse.y - obj.Y) >= 0){
        trans = (( (mouse.x - obj.X) - (mouse.y - obj.Y) ) /2);
      } else
      if ((mouse.y - obj.Y) <= 0){
        trans = (( (mouse.x - obj.X) + (mouse.y - obj.Y) ) /2);
      }
    }
  

    if (trans<0) {
      trans=trans*-1;
    }
    if (trans>100) {
      trans=100;
    }
    
    obj.Transparency=trans;
  }
   
}


and in room 28:

Code: ags

function room_RepExec()
{

  if (CandleLit==true) { 

    Interdimensional_Candle();
    
    Candlelight_on(oGoldCoin1, iWoodCoin1);
    Candlelight_on(oGoldIngot, iGoldBrick);
    Candlelight_on(oGoldPen, iGoldPen);
    
    if (!cJulius.HasInventory(iGoldPen)) {
      hGoldPen.SetProperty("hidden",false);
    }
    if (!cJulius.HasInventory(iWoodCoin1)) {
      hGoldCoin.SetProperty("hidden",false);
    }
    
    if (SafeOpen==true){
      
      DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(137, true);  //safe closed
      DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
 
      sprite.Crop(mouse.x-65, mouse.y-65, 240, 240);
      sprite.CopyTransparencyMask(444);
  
      surface.DrawImage(mouse.x-65, mouse.y-65, sprite.Graphic, 20);
      
      surface.DrawImage(0, 0, 486, 90);            //safe closed
      surface.Release();
      sprite.Delete();
      

    } else {
      DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(169, true);  //safe open
      DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
      
      sprite.Crop(mouse.x-65, mouse.y-65, 240, 240);
      sprite.CopyTransparencyMask(444);
      
      surface.DrawImage(mouse.x-65, mouse.y-65, sprite.Graphic, 20);

      surface.DrawImage(0, 0, 487, 90);            //safe open
      
      surface.Release();
      sprite.Delete();
    
    }
    
  } else {
    
    
    if (SafeOpen==true){
      DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
      surface.DrawImage(0, 0, 486, 0);            //safe open
      surface.Release();
    } else {
      DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
      surface.DrawImage(0, 0, 487, 0);            //safe closed
      surface.Release();
    }
    
    
    hGoldPen.SetProperty("hidden",true);
    hGoldCoin.SetProperty("hidden",true);
    
    oGoldCoin1.Visible=false;
    oGoldIngot.Visible=false;
    oGoldPen.Visible=false;
  }
}



function oGoldIngot_Interact()
{
  if (CandleLit && !cJulius.HasInventory(iGoldBrick)) {
    cJulius.Walk(626, 595, eBlock, eWalkableAreas);
    cJulius.Phylactere("A gold brick! Well, a gold ingot.");
    cJulius.Phylactere("It's yellow reminds me off summer eggs...");
    cJulius.AddInventory(iGoldBrick);
    oGoldIngot.Visible=false;
  }
}


function hGoldPen_Interact()
{
  if (CandleLit && !cJulius.HasInventory(iGoldPen)) {
    cJulius.Walk(355, 650, eBlock, eWalkableAreas);
    cJulius.Phylactere("A gold pen - gee, whoever lived here didn't really care about their fine stuff.");
    cJulius.AddInventory(iGoldPen);
    oGoldPen.Visible=false;
  }
}

function hGoldCoin_Interact()
{
  if (CandleLit && !cJulius.HasInventory(iWoodCoin1)) { 
    cJulius.Walk(353, 646, eBlock, eWalkableAreas);
    cJulius.Phylactere("A gold coin!");
    cJulius.AddInventory(iWoodCoin1);
    oGoldCoin1.Visible=false;
  }
}


"hidden" is a special field in Properties of hotspots is set to =true on oGoldCoin1 and oGoldPen.

The aim of this code is: when the candle is lit (CandleLit), hidden parts of the room appear.
The Candlelight_On function is to set transparancy equal to the proximity of the flame - when close they're visible, when far away they're are progressively more transparent until becoming invisble.

There are hotspets set over the oGoldCoin1 and oGoldPen, set initially to hidden=true. They are there so the person can click on the objects, as there's a time-limit to the candle, and they wouldn't be able to hit the 'pixel perfect' crosshair otherwise.

The UpdateMouseGraphic() function is passed on from repeatedly_execute() in globalscript; icons change to viewable, interact-able, etc when mouse is over them.

The behaviour is that the 'eyes' (look at) icon and 'hand' (interact) are not activated during when CandleLit is off; but they AREN'T when CandleLit is on -- when they SHOULD be, as the "hidden" objects are now visible.
Worse, after CandleLit comes off, the behaviour freezes - hand and eye no longer react to (other) hotspots after this, and eye is premenantly open, no matter where it is.

Is this an insanely difficult bug (which perhaps someone can solve and save me another 3 days of agony), or just a bug in the interpretor?

Happy to provide any and all information if needed. Thanks! :)

bx83

SOLVED

The first line of UpdateMouseGraphic() is
  if (player.ActiveInventory != null) return;
It should be:
  if (mouse.Mode==eModeUseinv) return;

Otherwise, after someone picks an object out of the inventory, all cursors are frozen/

I didn't *show* these pieces of UpdateMouseGraphic(), which is why no-ones worked it out (or, you know, didn't care :P)

Won't ever steal a bit of code from here without knowing what every line does :P

Snarky

I did have a look at the code but couldn't find anything wrong with it, and I guess there wasn't. Glad you found it!

In general, for bugs like this I usually like to trace the execution: i.e. how far does it get before it doesn't do what I expect it to do? Putting in print commands at various places in the code helps narrow down the location of the bug.

SMF spam blocked by CleanTalk