Hi,
I have made a GUI with a question followed by YES and NO buttons. normally you would have to click the buttons. Can you create a short key so if I pressed the Y key, the YES button will work, and the same with N for No. If yes, how would you go about it please?
You can't have hotkeys by default, but a simple workaround would be to check if the GUI is visible and add something like this to your on_keypress. This allows you to have all sorts of "hotkeys", and GUIs can even use "the same" keys provided only one of them is visible at a time.
if (SomeGui.Visible)
if (Hotkey X pressed) { do function }
Sorry for the pseudocode, but you can easily look up "visible" in the manual, and the on_keypress function in the main script is already full of helpful comments.
Thank you, will try it tomorrow, will let you know how I got on.
Thank you very much, the game is much quicker this way now. I had to adjust the code a bit to fit my game but it worked. Thanks
what is the keycode of enter (return) please?
From the top of my head I'd say 103, but there's a list in the manual when you search "Appendixes: ASCII Code Table."
is the manual the help on the AGS software?
Yes, it comes with AGS. Press F1 when you're working on your game and it will pop up.
I have tried finding the 'Appendixes: ASCII Code Table.' but I can't find it.
found it
Great ;) Is that "hotkey workaround" good enough, though? Depending on the amount of GUIs with hotkeys, I think there might be better solutions (slimmer code, and all that). If you just have a few GUIs, I'd say go with it.
Quote from: Ghost on Thu 21/05/2009 19:55:51
Great ;) Depending on the amount of GUIs with hotkeys, I think there might be better solutions (slimmer code, and all that).
Yes, its great, is there another way of doing it then, if you got a lot of GUIs?
Well, one *could* go and use some tracking system that is updated when GUIs are made visible/invisible, but I think that would only be useful if you really are using a great deal of different GUIs with many different hotkeys. If there are only a few (like, say, half a dozen) your global script won't become too cluttered- and you can still set up different hotkey shemes and check against their owning GUIs with an if/then/else loop.
Like:
if (ReallyQuitGUI.Visible)
{if hotkey1...
if hotkey2...
} else if {StatusBarGUI.Visible)
{if hotkey1...
}
and so on. Sometimes a down'n'dirty approach is just enough ;) (Though I'm going to take cover now)