Godot Game Engine Tutorial: Creating a Function for a Button with Basic Programming

in #utopian-io8 years ago (edited)

This is a link for my last tutorial.

https://steemit.com/utopian-io/@rye05/godot-game-engine-tutorial-how-to-create-a-press-start-button

It was about creating a button.

For today's tutorial, it's going to be with creating a button again but we'll be adding an extra functionality using basic programming.

So, let's start.


  • Launch Godot

U5dt7cpPjJxgrzK4irMHVwuzzBFNWMk_1680x8400.png

  • If you followed my previous tutorial, you would have a sample project for the button we created. Double click it to open the editor.

U5dt7cpPjJxgrzK4irMHVwuzzBFNWMk_1680x8400.png

  • On the control asset, right click and then choose attach script.

2.png

  • A new window will pop up, no need to change anything, just leave it as it is.

3.png

  • You can also save this script by clicking the button.

1.png

  • You can name it and then click on save.

2.png

  • This will be the script window for the Control asset. Don't worry, even if you don't have any programming background, you can still do it.

3.png

  • Now, hit on 2D as we're gonna add something new.

4.png

  • Click on the plus button at the right hand side.

5.png

  • We're gonna make a label asset, search for it then create.

6.png

  • The asset will appear but it will be blank. You can put a text using the same process as putting a text to the button. It's on the lower right hand side, I put Steemit.

1.png

  • You can also center the text to make it look better.

2.png

  • And if you scroll down a bit, change the color and background color as well.

3.png

  • Go back to the Button asset and click on the node tab.

1.png

  • You will see different options here for what the buttons can do, locate the pressed option and double click on it.

1.png

  • A new window will pop up and by clicking connect, you will connect the pressed functionality from the Button asset to the Control Asset.

ScreenClip.png

  • Look at the script page of the Control asset, the pressed functionality has been successfully added and it has its own syntax.

ScreenClip.png

  • You can delete the syntax that starts with "pass" as it is not needed.

ScreenClip.png

  • Add a new syntax on the following line, it should be get_nodes() and the system will automatically give you the options available, choose Label.

ScreenClip.png

  • The syntax should be get_nodes("Label") and hit classes at the top.

1.png

  • Then put Label again and click open.

1.png

  • After that, the script for the Label would also appear but you don't have to change anything here.

2.png

  • Locate for the syntax that stars with void set_text and this is what we will put in the Control script.

3.png

  • Let's go back to the Control script page by clicking Control at the top left, then on the syntax we created, add the syntax we got from the Control Script. So the whole syntax should read get_node("Label").set_text("Steemit is the Best"). I put Steemit is the best but you can put anything then hit on play.

4.png

  • And here's what will happen when you click the button, the Label Steemit below the button will change when you click the button.

1.gif


That's the wrap for this tutorial, thank you for reading.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Very nice tutorial that anyone should be able to understand.
Thank you!

Thank you very much, glad you like it

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Rye05 (SteemPH Customer Service) from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP. Be sure to leave at least 50SP undelegated on your account.

you should be able to do this in your previous post. here

so for this post not enough can be received in utopian and get vote, you can return with something more different in the next opportunity.

[utopian-supervisor]

Thank you, I understand it got rejected, no problem with me. It's just that since I have no programming background, I got really confused with the whole tutorial when combining it in one. I just don't want to confuse my readers too. Thank you for the review.

Your contribution cannot be approved because it does not follow the Utopian Rules.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.13
TRX 0.34
JST 0.035
BTC 108074.45
ETH 4399.12
USDT 1.00
SBD 0.83