Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Robbie on Sun 26/08/2012 17:31:36

Title: [Solved] Hotspots can't be clicked
Post by: Robbie on Sun 26/08/2012 17:31:36
I've barely begun work on my Ludum Dare game-in-a-weekend challenge. But I'll have to drop out because I've just wasted seven hours swearing at hotspots. Can anybody figure out what's going on?

This isn't an adventure game, it's a sort of mutation video-poker machine. I've disabled all mouse modes except Interact. There are no characters, no inventory, none of that stuff. (Technically, there is a player character -- with an invisible sprite -- just so that the game can move from room to room.)

The game definitely recognises when the mouse is over a hotspot, but it does absolutely nothing when a hotspot is clicked. Here's an example I've just run as a test:

function hHead_AnyClick()
{
  Display("CLICK");
}

Now, how simple is that? And yet it doesn't work. Nothing happens at all. Help!
Title: Re: Hotspots can't be clicked
Post by: Igor Hardy on Sun 26/08/2012 17:36:06
What happens if you run the function hHead_Interact() in the script?

Define it the way you did with AnyClick for example:

function hHead_Interact()
{
  Display("CLICK");
}

If it works, then change the mouse mode to Interact and voila! - it works.
Title: Re: Hotspots can't be clicked
Post by: Robbie on Sun 26/08/2012 17:42:58
Thanks for the quick reply! Wow!

I've tried it both ways -- when Interact didn't work, I hoped Any Click would be more of a catch-all. But no.

At the moment, the hotspots (buttons) have objects over them to generate a "glow" effect. But the objects are non-clickable, and nothing worked even before I put the objects in. So I don't think that's the problem.

(Just to be sure, I've just tried it with Interact again. Nothing.)
Title: Re: Hotspots can't be clicked
Post by: Andail on Sun 26/08/2012 18:21:17
Just to be sure (this is beginners' tehcnical after all); have you used the lightning icon in the event's pane? Just in case you thought it was enough to write the code in the room script.
Title: Re: Hotspots can't be clicked
Post by: Robbie on Sun 26/08/2012 18:37:57
Yep, done that! And it's happy to save and run, so there's no major "grammatical" errors anywhere.

I can make it display a message when the mouse is over a hotspot. So the program is actually running (not paused or frozen), and it knows the hotspots are there. I'm just baffled.
Title: Re: Hotspots can't be clicked
Post by: Andail on Sun 26/08/2012 19:03:21
It has to be a mouse-click problem then. How are your clicks processed? Are you using any of the default templates, or have you scripted your own?
Can you click other things, like objects or characters, without problems?
Title: Re: Hotspots can't be clicked
Post by: Khris on Sun 26/08/2012 22:05:48
Could you upload the source files for us to take a look?
Title: Re: Hotspots can't be clicked
Post by: Robbie on Mon 27/08/2012 15:58:34
I haven't scripted any mouse clicks. All I've done is set the mouse mode to Interact, and disable the other modes. I've set Interact to have a simple arrow sprite, and the other modes don't have any sprites. I can see the arrow pointer, so it must be set to Interact.

There's hardly anything to the game yet. Here's all there is of the scripting. There are nine game rooms plus a starting room, which is the only one with any contents so far. This room only exists to display the rules (part of the room backdrop). When ready, the player clicks a button (hotspot) called Mutate and is sent to one of the other nine rooms at random to start the game itself.

The only object in this room is a non-clickable glow effect that starts invisible and is supposed to come on briefly when the button is clicked. The player character is an invisible, non-clickable sprite that only exists as a way to move the game from room to room.

For test purposes, I set up some other hotspots (the hHead above) and glow effect objects (which will be used in other rooms) -- just to see if the problem was with that particular button -- and have been messing with temporary functions like the "display" one above.

The program is definitely running, and it recognises the mouse and hotspots. I can make it display a message when the mouse moves over a hotspot, and it will do this repeatedly, so it's not frozen.

GlobalScript.asc

Code (AGS) Select
function game_start()
{
  mouse.Mode = eModeInteract;
  mouse.DisableMode(eModeLookat);
  mouse.DisableMode(eModePickup);
  mouse.DisableMode(eModeTalkto);
  mouse.DisableMode(eModeUseinv);
  mouse.DisableMode(eModeWalkto);
  mouse.DisableMode(eModeWait);
}


Room script

Code (AGS) Select
int go;

function room_Load()
{
  go = (Random(8)+1);
}

function hMutate_AnyClick()
{
  oMutateGlow.Visible = true;
  Wait(10);
  oMutateGlow.Visible = false;
  player.ChangeRoom(go);
}

function room_Leave()
{
  GiveScore(1000);
  gPopulation.Visible = true;
  gClimate.Visible = true;
}[code=AGS]
Title: Re: Hotspots can't be clicked
Post by: Robbie on Mon 27/08/2012 16:14:35
I thought I'd just add...

The reason I went with clickable hotspots instead of an actual button GUI is simply that I couldn't (still can't) quite get my head round how GUIs work. I can understand hotspots, so given the competition time pressure I went with the concept I could grasp.

I've dropped out of the competition now, so there's no time pressure any more. If you think a GUI would be better, don't hesitate to say so. (The entire game control mechanism is based on clicking buttons.)
Title: Re: Hotspots can't be clicked
Post by: Andail on Mon 27/08/2012 16:20:22
Oh, well, you need something to call the mouse button and process the clicks.
Like this (in its simplest form):
Code (ags) Select

function on_mouse_click (MouseButton button)
{
    if (button==eMouseLeft){
        ProcessClick (mouse.x, mouse.y, eModeInteract);
    }
}
Title: Re: Hotspots can't be clicked
Post by: Khris on Mon 27/08/2012 16:22:38
Yeah, even an empty game contains rudimentary click handling.
If what you posted is indeed your entire GlobalScript.asc, why did you delete all the other stuff without understanding what you're doing...?
Title: Re: Hotspots can't be clicked
Post by: Robbie on Mon 27/08/2012 16:38:11
HA! Well, that's my Something Learned for today.

I didn't delete anything... I started with the empty game. I thought basic mouse clicks were "built in". That'll teach me to suppose.

Many thanks to all!

-----

AND IT WORKS NOW! HOORAY!
Still too late for the competition, but at least I can finish it. Thanks again!
Title: Re: Hotspots can't be clicked
Post by: Khris on Mon 27/08/2012 16:45:13
If you didn't delete anything, what did you do to make it work?
Title: Re: Hotspots can't be clicked
Post by: Robbie on Mon 27/08/2012 17:02:52
I copypasted what Andail wrote into the global script. Easy peasy. (I can copypaste with the best of 'em.)

How do I mark the thread title as "solved"?
Title: Re: Hotspots can't be clicked
Post by: Khris on Mon 27/08/2012 18:15:37
I'm just curious, because if you simply added what Andail posted, you must have deleted the original function at some point.
Like I said, even starting with the Empty Game template does provide basic click handling because there's an on_mouse_click function already in there. And if you hadn't deleted it, you wouldn't have spent 7 hours trying to get hotspots to react to clicks.

To mark the thread as solved, edit your first post and change the title.
Title: Re: Hotspots can't be clicked
Post by: Robbie on Tue 28/08/2012 17:23:11
I swear, I didn't delete anything. Cross my heart.

I just opened a new Empty Game template and it's got all sorts of starter script in the global script, as you say. But when I started this one, the global script was empty. Totally empty. I have no explanation for it, but there it is.

Anyway, thanks again to you and Andail and Ascovel!