Hi,
I'm making a game in which objects can be highlighted when the mouse moves over them, and the highlight removed when the mouse moves away.Ã, This works fine for objects, but since I'm worried about hitting the object limit, I've tried to emulate this with hotspots and graphical overlays.Ã, The overlay appears when the mouse moves over the hotspot, but when it moves off the game crashes with this error:
Error: RemoveOverlay: invalid overlay id passed
All of the highlighting stuff is handled in the repeatedly_execute function of the room.Ã, Here is my script:
Ã, // script for room: Repeatedly execute
int over1;
if(GetObjectAt(mouse.x,mouse.y) == 2)Ã, {
Ã, if(GetGlobalInt(0) == 0) {
Ã, Ã, SetObjectGraphic(2,10);
Ã, }
}
if(GetObjectAt(mouse.x,mouse.y) == 3)Ã, {
Ã, SetObjectGraphic(3,17);
}
if(GetObjectAt(mouse.x,mouse.y) == 4)Ã, {
Ã, if(GetGlobalInt(1) == 0) {
Ã, Ã, SetObjectGraphic(4,37);
Ã, }
}
if(GetObjectAt(mouse.x,mouse.y) == 5)Ã, {
Ã, if(GetGlobalInt(2) == 0) {
Ã, Ã, SetObjectGraphic(5,43);
Ã, }
Ã, else SetObjectGraphic(5,44);
}
if(GetHotspotAt(mouse.x,mouse.y) == 1) {
Ã, if(GetGlobalInt(3) == 0) {
Ã, Ã, over1 = CreateGraphicOverlay(40,119,54,1);
Ã, Ã, SetGlobalInt(3,1);
Ã, }
}
//highlights object
if(GetObjectAt(mouse.x,mouse.y) == -1) {
Ã, if(GetObjectGraphic(2) == 10) {
Ã, Ã, SetObjectGraphic(2,2);
Ã, }
Ã, if(GetObjectGraphic(3) == 17) {
Ã, Ã, SetObjectGraphic(3,15);
Ã, }
Ã, if(GetObjectGraphic(4) == 37) {
Ã, Ã, SetObjectGraphic(4,32);
Ã, }
Ã, if(GetObjectGraphic(5) == 43) {
Ã, Ã, SetObjectGraphic(5,38);
Ã, }
Ã, else if(GetObjectGraphic(5) == 44) {
Ã, Ã, SetObjectGraphic(5,42);
Ã, }
}
if(GetHotspotAt(mouse.x,mouse.y) == 0) {
Ã, if(GetGlobalInt(3) == 1) {
Ã, Ã, SetGlobalInt(3,0);
Ã, Ã, RemoveOverlay(over1);
Ã, }
}
//takes off highlight
I'm assuming that 'over1' isn't being recognised in the 'if' section at the bottom.Ã, I can't seem to get it to work with GlobalInts.Ã, All I want to do is remove the overlay, but I get errors about illegal values if I just put in '0' or '1' in RemoveOverlay.Ã, Is it possible to get this to work, or should I go back to objects?
Try moving the declaration (int over1;) out of rep_ex, to the top of the room script.
I think the problem is, since it's currently re-declared every loop, over1 is no longer associated with the graphic overlay, so RemoveOverlay(over1); doesn't do anything.
Also, you should be able to use IsOverlayValid(over1), instead of the GlobalInt, e.g.:
if(GetHotspotAt(mouse.x,mouse.y) == 1) {
if(IsOverlayValid(over1) == 0) over1 = CreateGraphicOverlay(40,119,54,1);
}
Thanks Ashen, it works fine now! I've replaced the global integer with IsOverlayValid too. Thanks again!