Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: beaver on Sat 01/05/2004 21:56:11

Title: SetButtonPic on mouseover?
Post by: beaver on Sat 01/05/2004 21:56:11
Ok, I know i can make a button pic change when the mouse goes over a hotspot, (and change back again by using another hotspot around it). and i can make a button pic change when the player stands on a region... but is there a way to make a button pic change when the mouse passes over a character?

thanks
Title: Re:SetButtonPic on mouseover?
Post by: Ishmael on Sat 01/05/2004 22:12:03
Consult the manual on GetLocationType type functions...
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sat 01/05/2004 22:36:07
hmm, usefull, but what if the character was moving/moved to a different location?
Title: Re:SetButtonPic on mouseover?
Post by: Ishmael on Sat 01/05/2004 23:08:19
check in repeadetly_execute if GetLocationType is nothing or GUI...
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sat 01/05/2004 23:34:02
ah i see, i was thinking it would only do it when the player was over the coordinates stated, but it relies on where u put the mouse.

thanks very muchly.
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 00:48:53
doh, that works nicely, only thing is i wanted the button to change to a different pic depending on what character it was over, not just any character. is that possible?
Title: Re:SetButtonPic on mouseover?
Post by: Ashen on Sun 02/05/2004 00:52:46
Yeah, it's possible. you just have to add an extra layer of 'if..' coding, based on:
if (GetPlayerCharacter() == WHATEVER) {
   SetButtonPic(..., ...);
 }
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 01:04:15
im not sure how to implement that... here is what i tried to do using it. but it just made the button change to the same sprite regardless of which character it was over (player or npc)

if (GetLocationType(mouse.x,mouse.y)== 2)
   SetButtonPic(INTY, 0, 1, 179);
   if (GetPlayerCharacter() == 0)
   SetButtonPic(INTY, 0, 1, 177);
   if (GetLocationType(mouse.x,mouse.y)==0)
   SetButtonPic(INTY, 0, 1, 175);
Title: Re:SetButtonPic on mouseover?
Post by: Ashen on Sun 02/05/2004 01:10:41
My mistake - didn't read the question properly. Don't know what I was thinking.

You need it to look something like this:
if (GetLocationType(mouse.x,mouse.y)== 2) {
 if (GetCharacterAt(mouse.x, mouse.y) == 0) {
   SetButtonPic(INTY, 0, 1, 177);
 }
 else SetButtonPic(INTY, 0, 1, 179);
}
if (GetLocationType(mouse.x,mouse.y)==0)
SetButtonPic(INTY, 0, 1, 175);
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 01:13:32
excellent, that works great.
thanks
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 01:17:46
1 last thing, i take it you can only do it with a maximum of 2 characters?
oh, and can rolling over a button change the image on another button?


ignore that, i just found GetGUIObjectAt that should do it i think
Title: Re:SetButtonPic on mouseover?
Post by: Ashen on Sun 02/05/2004 01:31:44
No, you can do as many characteras as you like:

if (GetLocationType(mouse.x,mouse.y)== 2) {
 if (GetCharacterAt(mouse.x, mouse.y) == 0) {
   SetButtonPic(INTY, 0, 1, 177);
 }
 else if (GetCharacterAt(mouse.x, mouse.y) == 1) {
   SetButtonPic(INTY, 0, 1, 178);
 }
 else if (GetCharacterAt(mouse.x, mouse.y) == 2) {
   SetButtonPic(INTY, 0, 1, 180);
 }
 else SetButtonPic(INTY, 0, 1, 179);
}
and so on, using 'else if'. And:

if (GetGUIAt(mouse.x,mouse.y) == INTY) {
 if (GetGUIObjectAt(mouse.x,mouse.y) == 1) {
  SetButtonPic(INTY, 0, 1, 177);
 }
 else SetButtonPic(INTY, 0, 1, 179);
}
should change the object 0 image, when the mouse is over object 1. That's not tested though, so it may not work.

EDIT: was typing this when you re-posted. Hope it helps anyway.
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 01:39:30
hm, something is a bit wrong with it, says parse error unexpected if. would that just be how ive put the script in though?
Title: Re:SetButtonPic on mouseover?
Post by: Ashen on Sun 02/05/2004 01:41:29
What line is the 'unexpected if' on? Can you show the code around it?
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 01:44:03
if (GetLocationType(mouse.x,mouse.y)== 2) {
if (GetCharacterAt(mouse.x, mouse.y) == 0) {
SetButtonPic(INTY, 0, 1, 177);
}
else SetButtonPic(INTY, 0, 1, 179);
}
if (GetLocationType(mouse.x,mouse.y)==0)
SetButtonPic(INTY, 0, 1, 175);  
}
if (GetGUIAt(mouse.x,mouse.y) == INTY) {          <-------------- this one
if (GetGUIObjectAt(mouse.x,mouse.y) == 1) {
SetButtonPic(INTY, 0, 1, 177);
}
else SetButtonPic(INTY, 0, 1, 179);
}

i dont think its your code, i think ive just screwed up =)
Title: Re:SetButtonPic on mouseover?
Post by: Ashen on Sun 02/05/2004 01:52:21
Try:
if (GetLocationType(mouse.x,mouse.y)== 2) {
 if (GetCharacterAt(mouse.x, mouse.y) == 0) {
   SetButtonPic(INTY, 0, 1, 177);
 }
 else SetButtonPic(INTY, 0, 1, 179);
}
if (GetLocationType(mouse.x,mouse.y)==0) { //<---- this runs on GUIs
 if (GetGUIAt(mouse.x,mouse.y) == INTY) {
   if (GetGUIObjectAt(mouse.x,mouse.y) == 1) {
     SetButtonPic(INTY, 0, 1, 177);
   }
 else SetButtonPic(INTY, 0, 1, 179);
}
else SetButtonPic(INTY, 0, 1, 175);
}

As it was, there were two bits of script telling it what to do over a GUI (GetLocationType == 0, and GetGuiAt), which might've confused it, especially since this is the line that returned the error.
Title: Re:SetButtonPic on mouseover?
Post by: beaver on Sun 02/05/2004 01:57:10
yeh that works great. you too kind.
only thing was i had to add another closing bracket at the end of the script