Author Topic: Gui button appear above player when on a hotspot (Keyboard only) [SOLVED]  (Read 155 times)

Stranga

  • Beer Potion!
    • I can help with making music
    •  
    • I can help with story design
    •  
Hey everyone!

I can't quite figure out how to do this. I've tried a few different ways and nothing. What I am trying to achieve is that when the player walks over a hot spot an exclamation mark appears above her head and when not disappears. The game is keyboard only so I'm still new to this.

So far, I've tried this:

Code: Adventure Game Studio
  1. function repeatedly_execute()
  2. {
  3. int px = player.x - GetViewportX(),py = player.y - GetViewportY();
  4. Hotspot*h = Hotspot.GetAtScreenXY(px, py);
  5. if (h!=null){
  6.   gHotspot.Visible=true;
  7.   gActionText.Visible=true;
  8.   lblActionText.Text=h.Name;
  9.   btnExclaim.NormalGraphic=866;
  10.   }
  11.   else
  12.   {
  13.   gHotspot.Visible=false;  
  14.   gActionText.Visible=false;
  15.   lblActionText.Text="....";
  16.   btnExclaim.NormalGraphic=0;
  17.   }  
  18.  }
  19.  

gHotspot has the exclamation mark button in it and I added the action text to see if it works and the action text does, the button changing graphic does not.
Any help would be greatly appreciated.

EDIT

I solved it by changing this:

Code: Adventure Game Studio
  1. function repeatedly_execute()
  2. {
  3. int px = player.x - GetViewportX(),py = player.y - GetViewportY();
  4. Hotspot*h = Hotspot.GetAtScreenXY(px, py);
  5. if (h.ID ==0 ){ //<CHANGED THIS ----------------------------------------------------------------------
  6.   gHotspot.Visible=false;  
  7.   gActionText.Visible=false;
  8.   lblActionText.Text="....";
  9.   btnExclaim.Animate(82, 0, 1, eOnce);
  10.   }
  11.   else
  12.   {
  13.   gHotspot.Visible=true;
  14.   gActionText.Visible=true;
  15.   lblActionText.Text=h.Name;
  16.   }
  17.  


« Last Edit: 10 Feb 2018, 13:20 by Stranga »
Yo.

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
This is what regions are for; they have a "player steps on" and "player steps off" event.

Your code sets up/activates the GUI 40 times per second, and thus keeps restarting the button animation. However, it looks like you're animating the button after turning off the GUI...? This probably means that as soon as you step on any hotspot, AGS stops constantly restarting the animation, so it actually gets to play.
The code is still completely off, it just happens to accidentally produce the result you want. ;)

As for hotspots, yes, any blank part of the screen is actually hotspot[0].

I wrote some code for a keyboard only game here: http://www.adventuregamestudio.co.uk/forums/index.php?topic=44602.msg595707#msg595707
It requires to draw Hotspots as you already do: as part of the walkable area. And it uses Regions for interacting with Objects, where all you need to do is use the same ID for both. The code runs "Interact with" following a keypress.

The repeatedly_execute should look like this:
Code: Adventure Game Studio
  1. function repeatedly_execute() {
  2.   Hotspot* h = Hotspot.GetAtScreenXY(player.x - GetViewportX(), player.y - GetViewportY());
  3.   if (h.ID > 0 && !gHotspot.Visible) {
  4.     lblActionText.Text = h.Name;
  5.     btnExclaim.Animate(82, 0, 1, eOnce);
  6.     gHotspot.Visible = true;
  7.     gActionText.Visible = true;
  8.   }
  9.   else if (h.ID == 0 && gHotspot.Visible) {
  10.     gHotspot.Visible = false;
  11.     gActionText.Visible = false;
  12.   }
  13. }
 
« Last Edit: 10 Feb 2018, 13:57 by Khris »

Stranga

  • Beer Potion!
    • I can help with making music
    •  
    • I can help with story design
    •  
Thanks khris! I just kept shooting at it hoping something would work and it did by accident. And I did originally had an animated button, what you saw were my desperate attempts to get this to work. Thanks for the tip, I'll also check out the link. I could always use better methods of doing things rather than guessing haha :)
Yo.