Step One - Using Drag-and-Drop Actions to Retrieve Input
Using drag and drop actions, just as in the GML language, to check for input can be performed in any active object, be it either the player object, a sole object for controlling all input, or if each object has its own input retrieval processes.
You can only use events that are always running to detect input. For example, the step event or the draw event. So, in the object you wish to use for input reading add the step event if you do not already have it added.
Perhaps the easiest way to check for mouse input is to simply click on the add event button, select mouse, and click the desired event. Then add any actions into the newly created event.
Another, more complex, but more flexible way for checking if mouse buttons are pressed is, on the right side of the screen, select the 'control' tab. In the control tab drag and drop the 'Check Mouse' action into the actions portion of the screen. A window will pop up allowing you to select which button you wish to check for, left, right, or middle and to select whether it is or isn't pressed. Now, add a start and a finish block action under the mouse checking action and place whatever action you want to be executed between these.
The fastest way to check for keyboard input is to press the add event button, click keyboard, and select which key you want to check for. Game Maker will make a new event for this specific key where you can place actions.
For a more flexible and in depth look at keyboard, mouse and joystick input continue below to the next step.
Step Two - User Input through GML
As with the drag and drop based events in step one, Game Maker's GML code, when used for detecting user input, should only be place in either of the step or draw events.
To detect keyboard, mouse or joystick input with GML, simply create a 'Execute Code' action in your input object's step event. You will place the proper GML code in this new action. Given below are Game Maker's GML keyboard functions:
keyboard_check(vk_key) - This function will return true(1) or false(0) if the key vk_key has been pressed.
keyboard_lastkey - This function returns the keycode of the last pressed keyboard key.
keyboard_key - This keyboard function returns the keycode of whatever key is currently pressed, if any.
keyboard_check_released(vk_key) - This function will tell if the given key has been released.
Here are Game Maker's GML functions for mouse input:
mouse_check_button(button) - Checks if the given mouse button is pressed or not.
mouse_check_button_released(button) - Checks if the given mouse button has been released or not.
mouse_x - Returns the value of the mouse's current vertical or 'x' position on the screen.
mouse_y - Returns the value of the mouse's current horizontal or 'y' position on the screen.
mouse_button - Returns what mouse button is currently being pressed.
mouse_lastbutton - Returns the last mouse button that was pressed.
mouse_wheel_up - Returns if the mouse wheel has been scrolled up wards.
mouse_wheel_down - Returns if the mouse wheel has been scrolled down wards.
Finally, the GML function for joysticks and controllers:
joystick_exists(number) - Checks if the joystick number is currently plugged in and available.
joystick_check_button(joystick number, button number) - Checks if the given joystick's given button is currently pressed.
For movement controls on joysticks and for further information on all of these events and actions please consult the Game Maker 8 manual.
Conclusion
Making proper use of one of the methods given in the above steps, you can easily incorporate user interaction with all of your Game Maker 8 games. Using GML is probably more efficient then the drag and drop actions method, but actions are easier to use then GML. Its generally best to choose whatever one method suits you the best.
NOTE:
It is typical in the Game Maker community to ask for credit, however these scripts are provided absolutely free and require no credit what so ever.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
- Game Maker Mplay ExampleLearn to code GML to make a mplay game to play over the internet.
- Logitech's MX1000 Laser Cordless Mouse Redefines What a Mouse Can BeIf you think the optical mouse is the best mouse for your computer, think again. With its high performance laser mouse, the Logitech MX1000 blows everything else out of the water.
Saitek Cyborg Evo Force Joystick ReviewThe Saitek Cyborg Evo Force is a great handling Force feedback joystick with all your controls on one stick.- Evolution of PC Input DevicesA lot has changed over the past few decades and with computers getting more powerful, they can handle more data input and newer equipments and gadgets. Here's my view on how PC input devices evolved.
- Comparison of Assisted Search Engines: Google & CAIN In This paper accessibility of Google search engine and CAIN is Compared and Specially Focused on the Blind Users that how the Blind Users can avail this opportunity
- A Review of Game Maker
- Game Maker: Every Programmer's Dream
- Want to Make Your Own Computer Games? a Game Maker 7 Review
- Game Maker 8 Tutorial: Generate a Hexagonal Grid
- Software Review: Game Maker
- Game Maker 8 Tutorial: Draw HUD Elements in 3D
- Free Game Maker Software




