Gui button appear above player when on a hotspot (Keyboard only) [SOLVED]

Started by Stranga, Sat 10/02/2018 12:52:52

Previous topic - Next topic

Stranga

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: ags

function repeatedly_execute() 
{
int px = player.x - GetViewportX(),py = player.y - GetViewportY();
Hotspot*h = Hotspot.GetAtScreenXY(px, py);
if (h!=null){
  gHotspot.Visible=true;
  gActionText.Visible=true;
  lblActionText.Text=h.Name;
  btnExclaim.NormalGraphic=866;
  }
  else
  {
  gHotspot.Visible=false;  
  gActionText.Visible=false;
  lblActionText.Text="....";
  btnExclaim.NormalGraphic=0;
  }  
 }


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: ags

function repeatedly_execute() 
{
int px = player.x - GetViewportX(),py = player.y - GetViewportY();
Hotspot*h = Hotspot.GetAtScreenXY(px, py);
if (h.ID ==0 ){ //<CHANGED THIS ----------------------------------------------------------------------
  gHotspot.Visible=false;  
  gActionText.Visible=false;
  lblActionText.Text="....";
  btnExclaim.Animate(82, 0, 1, eOnce);
  }
  else
  {
  gHotspot.Visible=true;
  gActionText.Visible=true;
  lblActionText.Text=h.Name;
  } 




Khris

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: ags
function repeatedly_execute() {
  Hotspot* h = Hotspot.GetAtScreenXY(player.x - GetViewportX(), player.y - GetViewportY());
  if (h.ID > 0 && !gHotspot.Visible) {
    lblActionText.Text = h.Name;
    btnExclaim.Animate(82, 0, 1, eOnce);
    gHotspot.Visible = true;
    gActionText.Visible = true;
  }
  else if (h.ID == 0 && gHotspot.Visible) {
    gHotspot.Visible = false;
    gActionText.Visible = false;
  }
}

 

Stranga

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 :)

SMF spam blocked by CleanTalk