Skip to content

Commit 391b9a1

Browse files
committed
name tutorial
1 parent 4f063c7 commit 391b9a1

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
13.3 KB
Loading
1.95 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Name Tutorial
3+
description: Name Tutorial
4+
---
5+
6+
create a new main.go file
7+
8+
`touch main.go`
9+
10+
11+
```go
12+
package main
13+
14+
import (
15+
"grow.graphics/gd"
16+
"grow.graphics/gd/gdextension"
17+
)
18+
19+
type HelloName struct {
20+
gd.Class[HelloName, gd.Node2D]
21+
22+
Name gd.TextEdit
23+
Text gd.Label
24+
25+
Button gd.Button
26+
}
27+
28+
29+
func (h *HelloName) Ready(godot gd.Context) {
30+
h.Button.AsObject().Connect(godot.StringName("pressed"), godot.Callable(h.OnButtonPressed), 0)
31+
}
32+
33+
func (h *HelloName) OnButtonPressed(godot gd.Context) {
34+
h.Text.SetText(godot.String("Hello " + h.Name.GetText(godot).String()))
35+
}
36+
37+
func main() {
38+
godot, ok := gdextension.Link()
39+
if !ok {
40+
return
41+
}
42+
gd.Register[HelloName](godot)
43+
}
44+
```
45+
46+
run `go get -u` from the terminal and `go mod tidy`
47+
48+
49+
this should update the module and install it.
50+
51+
52+
after that run `gd` to start the godot project, then save the project in godot.
53+
54+
change the node to a control node, then add `HelloName` as a child of the control node.
55+
56+
then run the project inside godot.
57+
58+
![Node Tree](../../../../assets/tutorials/name/HelloName.png)
59+
60+
61+
if all goes well click the button and you should see hello.
62+
63+
64+
![Running Hello](../../../../assets/tutorials/name/runninghello.png)

0 commit comments

Comments
 (0)