Tint Objects on Mouseover/Interact (SOLVED)

Started by HSIAMetalKing, Sun 09/11/2008 21:56:24

Previous topic - Next topic

HSIAMetalKing

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!

Khris

#1
Create a custom property, type bool, initial value false, call it "tint".

Then add this to rep_ex:

Code: ags
// 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 }

HSIAMetalKing

I keep getting errors-- usually "Unexpected '{'", though I think I placed everything in the right spot. Here's what the global script looks like

Code: ags
{// 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. >.<

Gilbert

Code: ags
// 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.

Trent R

#4
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:

Code: ags
// 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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

HSIAMetalKing

Thanks everyone! Got it working now.

cat

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.

Trent R

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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

SMF spam blocked by CleanTalk