At 5:06 at newer versions of Game maker you should put in like this: function create_button(x,y,width,height,text,script){ ...} instead of ////@arg x, ////@arg y... It made buttons work for me in game maker language.
I actually replaced the arguments completely in the function parentheses like so function create_button(_x,_y,_width,_height,_text,_script) { //create button var _button = instance_create_layer(_x,_y,"Instances",obj_button); //set values with (_button) { width = _width; height = _height; text = _text; script = _script; } As long as you reference the correct width, height, text and script from earlier it works fine ;)
for those who get error in get_hover scripts, here's the code to fix it: function get_hover() { var _mouseX = device_mouse_x_to_gui(0); var _mouseY = device_mouse_y_to_gui(0); return point_in_rectangle(_mouseX, _mouseY, x, y, x + width, y + height); }
one of the few places on the internet that has up-to-date and well-exposed game maker tutorials. I couldn't follow my dream of creating games if it wasn't for you. thanks!
In the segment get_hover... device_mouse_x_to_gui(); and device_mouse_y_to_gui(); are functions in Game Maker Studio 2 that convert the position of the mouse on the device (such as a computer screen) to the position on the GUI (Graphical User Interface) of the game. The device_mouse_x_to_gui(0) function takes the x-coordinate of the mouse on the device and converts it to the x-coordinate on the GUI. Similarly, the device_mouse_y_to_gui(0) function takes the y-coordinate of the mouse on the device and converts it to the y-coordinate on the GUI. These functions are useful when designing GUI elements in the game that need to be interacted with using the mouse. By using these functions, the game can accurately determine where the user has clicked on the GUI and respond accordingly. It's worth noting that the parameter 0 passed to these functions specifies the index of the mouse device being used. If the game is designed to support multiple mice (such as in a local multiplayer game), a different index can be used for each device. However, if only one mouse is being used, the index is always 0.
Wonderfully paced. I appreciate the small polish effects, like getting brighter and moving slightly on hover. I've done similar things but definitely learned a few shortcuts.
@@SleepyyBox Well, it's a bit late, but you didn't do what he said then. The scripts name has to go in the create_button function as a parameter. create_button(30,30,300,100,"my button",myScript); The myScript here is the name of the script that will be executed once you press the button, because the attribute "script" of the button references this script. It's a bit hard to understand if you're new to programming because it means you need to understand what function pointers are. Also the "step" event is the event that is called each and every frame of the game for as long as the object remains in the game world/room. If you just call the script there you almost certainly hardcode this object (your button) to only be able to call this script. The point of this tutorial was to make modular buttons, meaning a base object that is able to "morph" into whatever kind of button you want it to be while also not hardcoding the scripts that are run by a button to be exclusive to button presses.
I'm not sure if it's very efficient to put var in a step event cuz you're creating and destroying a variable 30 or 60 times per second (or depending on your room speed), it's not a huge difference but when making a commercial game it's something to consider.
This video was extremely helpful! Thanks for pinning the comment about how to fix the script now that gms2 script system has changed. I worked with this and combined it with Scribble to make it when i hover over buttons the text changes to be wavy and stuff.
At 8:28 try to place your mouse cursor at the exact bottom limit of one of the rectangles. There is a bug that will make the rectangle shake (go up and down indefinitely as long as the cursor is at the bottom limit. Any way to fix that ? ^^
I know this is a bit old but: Most persons are not going to hit the bottom of the box to see what happens. If it concerns you that much you can try minimizing the "hover" area by adding a couple of pixels inward for all sides. Something like: point_in_rectangle( mx, my, x + 2, y + 2, x + width - 2, y + height - 2 ); This might not solve the actual problem but will allow persons not to put there mouse on a border they can see. Trying to find a border that cannot be seen is harder to keep a mouse on. At least I would think so from my own experience.
Can you pass a variable into the on_click script? If not, then these buttons are locked into certain scripts and can't be dynamic. I tried passing a variable into on_click(x,y) but then the click no longer functions and the script just runs whatever code is in it without clicking on the button.
The create_button() function takes a script argument, so whenever you click on a button, that script will be run. You can do your stuff in that script. ;)
If you seen what I made with your tutorial you would know that I stopped at a certain point and started to use only custom code I feel quite proud of myself that I got it to work on a prototype level
I amm not sure why this doesn't work. Maybe the new engine updates. If anyone can help lemme know. HIs tutorials are always the best but game maker makes them outdated sometimes.
I would recommend just going through it slowly. I just followed the tutorial and everything seemed to work fine. Let me know if you still have any problems.
@@GameMakerStation that's great congratulations, I often refer to many tutorials like yours and stitch together and modify examples to get results but I am amazed that people can invent elements like this button system on their own so easily.
When I loaded up my project, all of my buttons were jumbled together. The hovering animation worked, but I could use some advice to know how to fix the button positioning. Edit: Never mind, I figured it out thanks for the video!
Can't guarantee when you'll get it, but I'm pretty sure you will, somewhere down the line. ;) Would you want part 4 to be about shooting projectiles, or about chat?
@@Edel99 GMS paid bad, Godot free good bla bla bla, please shut the fuck up and let people have their preferences. Plus that update has been out for months now, pretty sure anyone who's remotely interested in game dev knows it.
It's not a tutorial, but a fast retalling of what you have done for something to work. It's not allow to understand why you designed it like this nor it allow to catch the idea of what data passed where. Tutorials should not be like this and not everyone is suited for "teaching".
At 5:06 at newer versions of Game maker you should put in like this:
function create_button(x,y,width,height,text,script){
...}
instead of
////@arg x,
////@arg y...
It made buttons work for me in game maker language.
I actually replaced the arguments completely in the function parentheses like so
function create_button(_x,_y,_width,_height,_text,_script)
{
//create button
var _button = instance_create_layer(_x,_y,"Instances",obj_button);
//set values
with (_button)
{
width = _width;
height = _height;
text = _text;
script = _script;
}
As long as you reference the correct width, height, text and script from earlier it works fine ;)
@@jam8munch811 thanks bro
for those who get error in get_hover scripts, here's the code to fix it:
function get_hover() {
var _mouseX = device_mouse_x_to_gui(0);
var _mouseY = device_mouse_y_to_gui(0);
return point_in_rectangle(_mouseX, _mouseY, x, y, x + width, y + height);
}
True life saver
thankyou!
this does not seem to be working for me
Your videos are the perfect example of how tutorials should be. fast, straight to the point and easy to read. good job. excellent channel!
one of the few places on the internet that has up-to-date and well-exposed game maker tutorials. I couldn't follow my dream of creating games if it wasn't for you. thanks!
Very good tutorial! Clear, easy to follow and doesn't waste any time.
Just found this video and i love the process of how you explained everything with on screen details. 10/10
You have absolutely the best GM tutorials on youtube. Well done and thank you.
Tried to skip through this video, didn't work, so I watched the entire thing. You, sir, have earned a like, it's exactly what I needed
In the segment get_hover...
device_mouse_x_to_gui(); and device_mouse_y_to_gui(); are functions in Game Maker Studio 2 that convert the position of the mouse on the device (such as a computer screen) to the position on the GUI (Graphical User Interface) of the game.
The device_mouse_x_to_gui(0) function takes the x-coordinate of the mouse on the device and converts it to the x-coordinate on the GUI. Similarly, the device_mouse_y_to_gui(0) function takes the y-coordinate of the mouse on the device and converts it to the y-coordinate on the GUI.
These functions are useful when designing GUI elements in the game that need to be interacted with using the mouse. By using these functions, the game can accurately determine where the user has clicked on the GUI and respond accordingly.
It's worth noting that the parameter 0 passed to these functions specifies the index of the mouse device being used. If the game is designed to support multiple mice (such as in a local multiplayer game), a different index can be used for each device. However, if only one mouse is being used, the index is always 0.
Wonderfully paced. I appreciate the small polish effects, like getting brighter and moving slightly on hover. I've done similar things but definitely learned a few shortcuts.
Stuff stops working, after 4:50 ... aslo script thing is different color in my case.
Thank you man, I hadn't checked out your channel before, but I love the quick pace on this and how you get right to exactly how your stuff works.
for some reason i get error in get_hover script, says the think it no defined value or width and height
I'm running into the same problem right now. If you found a solution let me know, but I think its due to a change in language
Oh, neat tricks I didn't think of. Thanks for the cool tutorial. ;)
You, sir, make the greatest GameMaker tutorials. Thanks a lot for all of them!
Awesome tutorial! Only question is how do I make the buttons do things?
Apply a script function to its script variable. That function will be executed when you click on the button.
@@GameMakerStation thank you! I subscribed :)
@@GameMakerStation I doesn't seem to work. I added the scipt I wanted to execute in my obutton step event
@@SleepyyBox Well, it's a bit late, but you didn't do what he said then. The scripts name has to go in the create_button function as a parameter.
create_button(30,30,300,100,"my button",myScript);
The myScript here is the name of the script that will be executed once you press the button, because the attribute "script" of the button references this script.
It's a bit hard to understand if you're new to programming because it means you need to understand what function pointers are.
Also the "step" event is the event that is called each and every frame of the game for as long as the object remains in the game world/room.
If you just call the script there you almost certainly hardcode this object (your button) to only be able to call this script.
The point of this tutorial was to make modular buttons, meaning a base object that is able to "morph" into whatever kind of button you want it to be while also not hardcoding the scripts that are run by a button to be exclusive to button presses.
Excellent video, just what I was looking for. Your tutorials have helped me a bunch!
всё очень просто, и к тому же выглядит очень профессионально и красиво.
there is the posibility to block button by sprite?
This is exactly what I needed! Fantastic tutorial, thanks a bunch!!
I'm not sure if it's very efficient to put var in a step event cuz you're creating and destroying a variable 30 or 60 times per second (or depending on your room speed), it's not a huge difference but when making a commercial game it's something to consider.
Don't worry, that's not going to slow your game down. Local variables in frame events are used a lot.
@@GameMakerStation really? I might have been mistaken, I'll look more into that thanks
This video was extremely helpful! Thanks for pinning the comment about how to fix the script now that gms2 script system has changed. I worked with this and combined it with Scribble to make it when i hover over buttons the text changes to be wavy and stuff.
At 8:28 try to place your mouse cursor at the exact bottom limit of one of the rectangles. There is a bug that will make the rectangle shake (go up and down indefinitely as long as the cursor is at the bottom limit. Any way to fix that ? ^^
I know this is a bit old but:
Most persons are not going to hit the bottom of the box to see what happens. If it concerns you that much you can try minimizing the "hover" area by adding a couple of pixels inward for all sides. Something like:
point_in_rectangle( mx, my, x + 2, y + 2, x + width - 2, y + height - 2 );
This might not solve the actual problem but will allow persons not to put there mouse on a border they can see. Trying to find a border that cannot be seen is harder to keep a mouse on. At least I would think so from my own experience.
General Kenobi
Also very helpful tutorial, thanks
Can you pass a variable into the on_click script? If not, then these buttons are locked into certain scripts and can't be dynamic. I tried passing a variable into on_click(x,y) but then the click no longer functions and the script just runs whatever code is in it without clicking on the button.
Great video, but how does one make the buttons actually... Ya know, do stuff?
The create_button() function takes a script argument, so whenever you click on a button, that script will be run. You can do your stuff in that script. ;)
Thanks!
how do you create a play again button?
Lifesaver, and love your interesting accent
i loved it!! you are amazing bro! THANK YOU SO MUCH!
YOU ARE AMAZING TOO!!
excellent; well explained, and the code is so elegant!
Short question: In the User Event 1 you destroy all the buttons. What can I do to only destroy one specific button?
Store the button's ID in a specific variable when you create it, and reference that variable in instance_destroy().
Yeah thank you! That worked fine for me :)
I am not able to use the menu with the Keyboard button. Please help me...
Please join the Discord server linked in the desc, you can get help there.
@@GameMakerStation I have already joined the discord channel. I will ask for help in the discord channel. Thanx for replying.
You can always use events and image_index and image_speed and alarm events, and they look fancier this way, for a real eye candy effect
Pardon my ignorance, but does this work for gamemaker 1?
It should! If you face any issues, let me know. You can find me in my Discord server (link is in the desc.).
@@GameMakerStation brilliant! I'll be giving it a shot tonight!
Yes it works for Gamemaker1. Just implemented it, really great tutorial!
Oh ma gad! I start making ui and buttons today and you upload a tutorial about that! Good tutorial!
Awesome tutorial - thank you - that helped me alot!
subscribed. This will help my youtube-updated project for sure.
Great tutorial, high quality, love the accent
is there a video for the second part?
ruclips.net/video/KjtAhp4rhP4/видео.html&ab_channel=GameMakerStation-Matharoo
Thanks for your teaching, Thanks a lot !!!!!
you will make a video of how connect 2 socket to one server, plix
That should be simple to do. What have you tried?
You can hit me up in my Discord server: discord.gg/TykHyqK
If you seen what I made with your tutorial you would know that I stopped at a certain point and started to use only custom code I feel quite proud of myself that I got it to work on a prototype level
I amm not sure why this doesn't work. Maybe the new engine updates. If anyone can help lemme know. HIs tutorials are always the best but game maker makes them outdated sometimes.
I dont see the buttons when I play it
Great video, I am still on GM1.4 and instance_create_layer doesn't work. However, I love how you made the button in the beginning. Thank you!
Question: Could you PLEASE copy and paste the code somewhere in the video's description?
Hello GameMakerStation - Matharoo
I am John from Pabin Games We found this very useful do we need to credit this in our game?
So I just followed this tutorial and spent like a half hour writing all this script only to get all kinds of errors that I cannot fix. :(
You can get help from the Discord server linked in the description.
I would recommend just going through it slowly. I just followed the tutorial and everything seemed to work fine. Let me know if you still have any problems.
I think it's a version issue. I've got the latest version and he's probably using an old.
I did manage to make a working GUI button system using point_in_rectangle and switch(rooms). Way easier.
I can't use in gms2 new update lol
Help
If it's a script issue, check out this video: ruclips.net/video/KUgZEPqlNtE/видео.html&ab_channel=GameMakerStation-Matharoo
how would you make left & right click functionality with the same button?
Use mb_right to check for right-click input, and add another script argument in the button creation script, for the right click.
Great tutorial thank you :)
and part 2?
Hey I'm just wondering, are you self taught or did you go to college/university? Thanks for the content.
Completely self-taught :)
@@GameMakerStation that's great congratulations, I often refer to many tutorials like yours and stitch together and modify examples to get results but I am amazed that people can invent elements like this button system on their own so easily.
WOW , youre a teacher
When I loaded up my project, all of my buttons were jumbled together. The hovering animation worked, but I could use some advice to know how to fix the button positioning.
Edit: Never mind, I figured it out thanks for the video!
can't wait for part 2
helo dAArreeee
velcum ta pat wun
uv mah UI tadorialssss
Its not working
Please join the Discord server linked in the description and post your issue there with code
U are the best sensei
Short but useful
Thankss man
Networking part 4 please
Can't guarantee when you'll get it, but I'm pretty sure you will, somewhere down the line. ;) Would you want part 4 to be about shooting projectiles, or about chat?
Your accent is Nice to listen to lol
da button
Thanks!
I cant understand about script haha
They're functions now, in 2.3. ruclips.net/video/KUgZEPqlNtE/видео.html
You can do this in Godot in 10 seconds!
Nobody asked!
@@sectorrrrr hey! Did you hear!? GameMaker is now subscription only! How exciting! 😀
@@Edel99 GMS paid bad, Godot free good bla bla bla, please shut the fuck up and let people have their preferences.
Plus that update has been out for months now, pretty sure anyone who's remotely interested in game dev knows it.
dabudduun
It's not a tutorial, but a fast retalling of what you have done for something to work. It's not allow to understand why you designed it like this nor it allow to catch the idea of what data passed where. Tutorials should not be like this and not everyone is suited for "teaching".
I agree
can you please speak normally?
Always copy & paste..... :( I don't reccomend this video...
...speak normal!!...
k
very nice and concise tutorial! @Andrzej Vlasov and @jam8much helped in the comments for the new script.