Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HSIAMetalKing on Sun 09/11/2008 21:56:24

Title: Tint Objects on Mouseover/Interact (SOLVED)
Post by: HSIAMetalKing on Sun 09/11/2008 21:56:24
I want to create a custom property for objects that will execute:

object[1].Tint(150, 150, 0, 100, 100);

when the mouse is over the object, and will

object[1].RemoveTint();

when the mouse is not over the object. I have not been able to find any part of the manual that deals with mouseover scripts for anything other than GUI buttons-- so any help would be greatly appriciated!
Title: Re: Tint Objects on Mouseover/Interact
Post by: Khris on Sun 09/11/2008 23:20:06
Create a custom property, type bool, initial value false, call it "tint".

Then add this to rep_ex:

// this line before rep_ex:
int troom, tobj;

// the following inside
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);

  if (o == null) {
    if (troom == player.Room) {
      object[tobj].RemoveTint();
      troom = 0; tobj = 0;
    }
  }
  else {
    if (o.GetProperty("tint")) {
      if (o.ID != tobj) {
        o.Tint(150, 150, 0, 100, 100);
        tobj = o.ID;
        troom = player.Room;
      }
    }
  }

Not tested!
       
Edit: added missing }
Title: Re: Tint Objects on Mouseover/Interact
Post by: HSIAMetalKing on Mon 10/11/2008 01:59:31
I keep getting errors-- usually "Unexpected '{'", though I think I placed everything in the right spot. Here's what the global script looks like

{// this line before rep_ex:
int troom, tobj;}
function repeatedly_execute()
{// the following inside
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);

  if (o == null) {
    if (troom == player.Room) {
      object[tobj].RemoveTint();
      troom = 0; tobj = 0;
  }
  else {
    if (o.GetProperty("tint")) {
      if (o.ID != tobj) {
        o.Tint(150, 150, 0, 100, 100);
        tobj = o.ID;
        troom = player.Room;}}}}}
     
  // put anything you want to happen every game cycle here
}


My terrible lack of experience is disturbing-- I'm sure I made a noobish mistake. >.<
Title: Re: Tint Objects on Mouseover/Interact
Post by: Gilbert on Mon 10/11/2008 02:02:08
// this line before rep_ex:
int troom, tobj;
function repeatedly_execute()
{// the following inside
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);

  if (o == null) {
    if (troom == player.Room) {
      object[tobj].RemoveTint();
      troom = 0; tobj = 0;
  }
  else {
    if (o.GetProperty("tint")) {
      if (o.ID != tobj) {
        o.Tint(150, 150, 0, 100, 100);
        tobj = o.ID;
        troom = player.Room;}}}}}
     
  // put anything you want to happen every game cycle here
}


Remove the {} for the lines before the function declaration. I didn't check the codes, maybe there'll still be some extra/not enough {} errors.
Title: Re: Tint Objects on Mouseover/Interact
Post by: Trent R on Mon 10/11/2008 03:06:25
Quote from: KhrisMUC on Sun 09/11/2008 23:20:06
Create a custom property, type bool, initial value false, call it "tint".

Then add this to rep_ex:

// this line before rep_ex:
int troom, tobj;

// the following inside
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);

  if (o == null) {
    if (troom == player.Room) {
      object[tobj].RemoveTint();
      troom = 0; tobj = 0;
  }
  else {
    if (o.GetProperty("tint")) {
      if (o.ID != tobj) {
        o.Tint(150, 150, 0, 100, 100);
        tobj = o.ID;
        troom = player.Room;
      }
    }
  }

Not tested!
       


I quoted Khris's code, cause your tabbing is messed up. Putting 5 } brackets in a row is not clean code.

But from Khris's, there needs to be one more } on the line before the else. Otherwise, there should be enough.


~Trent
Title: Re: Tint Objects on Mouseover/Interact
Post by: HSIAMetalKing on Mon 10/11/2008 07:19:39
Thanks everyone! Got it working now.
Title: Re: Tint Objects on Mouseover/Interact (SOLVED)
Post by: cat on Mon 10/11/2008 09:36:48
Shouldn't there also be a removetint in the else statement? Otherewise there might be wrong tinting if there are two objects next to each other.
Title: Re: Tint Objects on Mouseover/Interact (SOLVED)
Post by: Trent R on Mon 10/11/2008 11:53:46
The RemoveTint only needs to be above, if an object isn't under the mouse. If they're next to each other? I personally think that that would be poor design (another form of pixel hunting).


~Trent