[Solved] Hotspots can't be clicked

Started by Robbie, Sun 26/08/2012 17:31:36

Previous topic - Next topic

Robbie

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!
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Igor Hardy

#1
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.

Robbie

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.)
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Andail

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.

Robbie

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.
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Andail

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?

Khris

Could you upload the source files for us to take a look?

Robbie

#7
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
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
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]
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Robbie

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.)
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Andail

Oh, well, you need something to call the mouse button and process the clicks.
Like this (in its simplest form):
Code: ags

function on_mouse_click (MouseButton button)
{
    if (button==eMouseLeft){
        ProcessClick (mouse.x, mouse.y, eModeInteract);
    }
}

Khris

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...?

Robbie

#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!
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Khris

If you didn't delete anything, what did you do to make it work?

Robbie

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"?
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

Khris

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.

Robbie

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!
"You are amusing, in a 'what the hell is wrong with you' sort of way."
--Jaheira, Baldur's Gate

SMF spam blocked by CleanTalk