SOLVED: Character.GetAtScreenXY not inv mode

Started by Slasher, Mon 20/05/2013 19:15:59

Previous topic - Next topic

Slasher

Hi

I've just discovered that although this works fine the problem is that the inv item is always active so if you change mouse mode to say talk, walk etc the actions still occur. I need the below events to run only if the mouse is eModeUseinv 0 and not other modes.

Can you see what I need to do / change?

Code: AGS
 // SONAR HOVERS OVER CHARACTER CLAMP
function room_RepExec()
{ 
 if (Character.GetAtScreenXY(mouse.x, mouse.y) == clamp && cshifter.ActiveInventory==isonar && gInventory.Visible==false)
{
 mouse.ChangeModeView(eModeUseinv, 10); // Runs inventory cursor view animation
 aBuzz.Play();
 Game.DoOnceOnly("text");
 Label39.Text=("SOME TEXT.");
}
 else
{ 
 mouse.ChangeModeView(eModeUseinv, 0); // Stops inventory cursor view animation
 aBuzz.Stop();
 Label39.Text=("");
}
}


Cheers for all help

Khris

You need a check for mouse.Mode == eModeUseinv.

Also, Game.DoOnceOnly() on its own doesn't do anything. All it does is return something, which means it must go inside an if's condition brackets.

Also, this is once again a classical state change situation; you should avoid calling code every frame unnecessarily.

Code: ags
bool sonar_was_over_clamp;
int timer;

function room_RepExec()
{
  bool active_sonar = cshifter.ActiveInventory == isonar && mouse.Mode == eModeUseinv;
  Character* under_mouse = Character.GetAtScreenXY(mouse.x, mouse.y);

  bool sonar_is_over_clamp = (under_mouse == clamp && active_sonar && gInventory.Visible == false);

  // buzzing
  if (sonar_is_over_clamp)
  {
    timer++;
    if (timer >= GetGameSpeed() / 2)   // play aBuzz every half second
    {
      timer = 0;
      aBuzz.Play();
    }
  }

  // sonar just moved over clamp
  if (sonar_is_over_clamp && !sonar_was_over_clamp)
  {
    mouse.ChangeModeView(eModeUseinv, 10); // Runs inventory cursor view animation
  }
  
  // sonar no longer over clamp
  if (sonar_was_over_clamp && !sonar_is_over_clamp)
  {
    mouse.ChangeModeView(eModeUseinv, 0); // Stops inventory cursor view animation
  }

  sonar_was_over_clamp = sonar_is_over_clamp;
}


Tracking a condition like this allows you to call code exactly once, whenever the condition changes, as opposed to continuously every loop.

Slasher

Hi Khris

With a little bit of tweaking this works fab as it should.

Thank you very much.


SMF spam blocked by CleanTalk