Jibble

Author Topic: [SOLVED] Run htspt inter. only when standing on htspot & using a spcific cursr  (Read 747 times)

Hello all. I'm making a "map" room, in which the locations are represented by hotspots. I want it to work in a way so that when the character is standing on the location/hotspot AND he clicks it with the interact cursor, then it changes the room. I know how to do either of those separately, but I can't figure out how to do both of them at the same time.
I need this to work like this because the character can just skip the location by walking over it, so just entering the room by standing on the hotspot is not an option. Also, only interacting with it it's not an option either, because when I interact with a hotspot, the character walks toward it while blocking the other scripts (which I need for monster spawning, yadda yadda).

Any other alternatives to my theoretical method are also welcome!

Thanks in advance! :-D
« Last Edit: 15 Jan 2018, 17:00 by Egmundo Huevoz »

Matti

One possibility would be to put the monster spawning code(or anything else you want to happen) in the repeatedly_execute_always.

Another way would be to make the walking non-blocking and setting a variable that keeps track of what hotspot has been clicked on. Then, you not only check whether the player is standing on a certain hotspot, but also if the variable is equal to the hotspot's ID.

Yeah, I already have it on the repeatedly_execute_always. But still, if the player clicked the location by accident, he would still have to walk all the way there (it takes like 20 seconds) and get ambushed by monsters without having a possibility to move.

Is there a way to make the "walk to hotspot" thingy non-blocking? I'm gonna try the variable thing right now.

Matti

Create a global variable (int hotspotclick = 0) and do something like this:

Code: Adventure Game Studio
  1. // any click on hotspot:
  2. hotspotclick = hotspotname.ID
  3. player.Walk(mouse.x, mouse.y);
  4.  
  5. // stands on hotspot:
  6. if (hotspotclick == hotspotname.ID)
  7. {
  8.   hotspotclick = 0;
  9.   player.Changeroom();
  10. }
  11.  

I arrived to a similar code myself, but the problem with both your and my code is that I can click the hotspot, then interrupt my walking, do something else, and when I walk through the hotspot it without having JUST clicked it, it still changes the room.

After a lot of trial and error, I managed to do it!

Code: Adventure Game Studio
  1. int standing;
  2.  
  3. function repeatedly_execute_always()
  4. {
  5. if (!player.Moving)
  6.     standing=0;
  7. }
  8.  
  9. function on_mouse_click(MouseButton button){
  10. if ((button == eMouseLeft)&&(mouse.Mode==eModeInteract)){
  11.   player.Walk(GetViewportX()+mouse.x, GetViewportY()+mouse.y, eNoBlock);
  12.   Hotspot *h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  13.   standing=h.ID;}
  14. }
  15.  
  16. //then, on the particular hotspot/location walkon function:
  17.  
  18. function hAnyGivenHotspot_WalkOn()
  19. {
  20. if (standing==hAnyGivenHotspot.ID)
  21.   Display("It worked!");
  22. }

Or do this (just nitpicking though):
Code: [Select]
Hotspot* clickedHotspot;

  clickedHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);

  if (clickedHotspot == hAnyGivenHotspot)
i.e. use a variable name actually describing what it stores and a Hotspot pointer.
Fail at Floaty Rog' now!  still having to deal with what games are going through