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!
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 }
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. >.<
// 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.
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
Thanks everyone! Got it working now.
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.
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