A DirectButton not responding to mouse clicks

I have a bit of an odd problem - which is perhaps appropriate, as my current use for DirectButtons is perhaps a little odd itself.

I’m currently attempting to set up a first-person perspective adventure game system (real-time, not slideshow or panoramic), and part of that involves allowing the user to perform actions with objects, each such action being represented by a DirectButton, more or less.

When there is more than one such action, I have a special button appear that, when clicked, causes the buttons for the actions themselves to appear, and another that causes them to again disappear. To this end I keep a small number of DirectButtons, each tied to an “act” method, and passing an index as a parameter.

A special case occurs when there is only one action, however. In this case the first DirectButton - which should pass ‘0’ as its parameter - appears directly, in the centre of the screen, without an intervening step.

Movement is handled via the more-or-less standard system of moving the mouse about to look and the W-A-S-D keys to move around, with the mouse being warped to the centre of the screen to produce relative movement.

Despite the cursor being invisible (albeit being made to appear when there is more than one button), this system seems to work. However, under some conditions - which I have not yet properly nailed down, I’m afraid - the case involving a single action seems to fail: the button is visible, but the “act” method doesn’t seem to be called. This seems to be related to going through the standard case, of producing and then dismissing multiple buttons, before the single-button case is invoked, but doesn’t always happen. The issue seems to disappear again if the multi-button case is invoked, but again doesn’t seem to do so consistently.

At the moment I’m fairly confident that I’m no longer disabling any of the buttons, just hiding them.

My best idea at the moment is that the mouse-clicks are, for some reason, not reaching the buttons in some cases. Perhaps they’re being fielded by another button, which is somehow intercepting the clicks (although I would expect that, being hidden, they should not, surely?). Alas, I’m not sure of how to test for this at the moment, I don’t think. :confused:

Does anyone have any suggestions, and if so, what are they, please?

My thanks for any help given. :slight_smile:

Hmmm… hate to say it, but 9 times out of 10 hit-or-miss problems like that ultimately boil down to user error. Try printing some debug stuff whenever you do anything related to enabling/disabling/hiding/showing/accepting/ignoring buttons. Use a proper Find search to make sure you catch everything. Then trace the output against what you EXPECT to be happening (always go in with a known expectation!) and see where the two differ.

Alternatively, for a 3D first-person game, you might look into using the Picker system rather than trying to map directButtons to everything in 2D.

Thank you for the advice. :slight_smile:

I’ll admit that I find debugging somewhat awkward with SPE, since I haven’t gotten around to spending the time on getting WinPdb, which seems to be what comes with it, up and running, and printouts can slow things down eventually, and sometimes be tricky to follow.

Nevertheless, you make some good points - and indeed, I would imagine that it is, as you put it, user error (this has been my assumption thus far, I would say). I have, I think, had some shots at printing out information, but, aside from not getting a print-out from my act method (which I think was my means of determining that it wasn’t being called), things have appeared to work.

I think that I will, however, keep looking for places in which to insert further print-outs, and thank you for the suggestion. :slight_smile:

The picker is an option, although it strikes me as an over-complicated solution to what seems as though it should be a simple problem: I want to click on things placed in 2D on the screen (bear in mind that these buttons are intended to be overlays on the 3D action, not placed in the 3D world itself).

Aha, I think that I may have stumbled upon the problem! It seems - and I feel silly for this - that I wasn’t properly offsetting my buttons, and that thus they were being positioned by their corners. If either they or the mouse was off by just a bit, perhaps as a result of movements, the mouse-click might have missed, causing the bug.

The really silly thing is that I had, I believe, seen the symptoms of this, but had somehow not connected the two. ^^;;;

Thank you for your attention, and my apologies for any time that you feel was spent in vain. ^^;