Skip to content

Commit 1949efa

Browse files
authored
Update to demonstrate the new correct lifetime usage.
1 parent b849698 commit 1949efa

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

license

+19-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
This documentation is licensed under the MIT license.
1+
Copyright (C) 2024 Kamei Kojirou.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

src/content/docs/documentation/Overview/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
)
2121

2222
type HelloWorld struct {
23-
gd.Class[HelloWorld, gd.Node2D]
23+
gd.Class[HelloWorld, gd.SceneTree]
2424
}
2525

26-
// Ready implements the Godot Node2D _ready interface (virtual function).
27-
func (h *HelloWorld) Ready(gd.Context) {
26+
// Ready implements the Godot MainLoop _initialize interface (virtual function).
27+
func (h *HelloWorld) Initialize(gd.Context) {
2828
fmt.Println("Hello World from Go!")
2929
}
3030

src/content/docs/documentation/Tutorials/helloworld.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ description: Hello World Example
66
### Hello World Example
77

88

9-
installing the module
9+
Installing the module
1010

1111
```sh
1212
go install grow.graphics/gd/cmd/gd@master
1313
```
1414

15-
create a new go project
15+
Create a new go project
1616

1717
```sh
1818
go mod init main
1919
```
2020

21-
create a new main.go file
21+
Create a new main.go file
2222

2323
```go
2424
package main
@@ -34,7 +34,7 @@ type HelloWorld struct {
3434
}
3535

3636
// Ready implements the Godot Node2D _ready interface (virtual function).
37-
func (h *HelloWorld) Ready(gd.Context) {
37+
func (h *HelloWorld) Ready() {
3838
fmt.Println("Hello World from Go!")
3939
}
4040

@@ -47,7 +47,7 @@ func main() {
4747
}
4848
```
4949

50-
use `go get -u` to make sure the project and all the dependencies are up to date.
50+
Use `go get -u` to make sure the project and all the dependencies are up to date.
5151

5252
```sh
5353
go get -u
@@ -59,11 +59,11 @@ run the project
5959
gd
6060
```
6161

62-
with godot editor running add the `HelloWorld` Node to the the node in the current scene and save the project and close it.
62+
With godot editor running add the `HelloWorld` Node to the the node in the current scene and save the project and close it.
6363

6464
![Find hello world in the create node menu using the scene tree](../../../../assets/tutorials/helloworld/helloworld.png)
6565

66-
add it to the scene tree
66+
Add it to the scene tree.
6767

6868
![Node tree](../../../../assets/tutorials/helloworld/helloworld2.png)
6969

src/content/docs/documentation/Tutorials/name.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Name Tutorial
33
description: Name Tutorial
44
---
55

6-
create a new main.go file
6+
Create a new main.go file
77

88
`touch main.go`
99

@@ -26,12 +26,14 @@ type HelloName struct {
2626
}
2727

2828

29-
func (h *HelloName) Ready(godot gd.Context) {
30-
h.Button.AsObject().Connect(godot.StringName("pressed"), godot.Callable(h.OnButtonPressed), 0)
29+
func (h *HelloName) Ready() {
30+
tmp := h.Temporary // temporary lifetime for new Godot values.
31+
h.Button.AsObject().Connect(tmp.StringName("pressed"), tmp.Callable(h.OnButtonPressed), 0)
3132
}
3233

33-
func (h *HelloName) OnButtonPressed(godot gd.Context) {
34-
h.Text.SetText(godot.String("Hello " + h.Name.GetText(godot).String()))
34+
func (h *HelloName) OnButtonPressed() {
35+
tmp := h.Temporary // temporary lifetime for new Godot values.
36+
h.Text.SetText(tmp.String("Hello " + h.Name.GetText(tmp).String()))
3537
}
3638

3739
func main() {
@@ -43,22 +45,20 @@ func main() {
4345
}
4446
```
4547

46-
run `go get -u` from the terminal and `go mod tidy`
47-
48-
48+
Run `go get -u` from the terminal and `go mod tidy`
4949
this should update the module and install it.
5050

5151

52-
after that run `gd` to start the godot project, then save the project in godot.
52+
After that run `gd` to start the godot project, then save the project in godot.
5353

54-
change the node to a control node, then add `HelloName` as a child of the control node.
54+
Change the node to a control node, then add `HelloName` as a child of the control node.
5555

56-
then run the project inside godot.
56+
Then run the project inside godot.
5757

5858
![Node Tree](../../../../assets/tutorials/name/HelloName.png)
5959

6060

61-
if all goes well click the button and you should see hello.
61+
If all goes well click the button and you should see hello.
6262

6363

6464
![Running Hello](../../../../assets/tutorials/name/runninghello.png)

0 commit comments

Comments
 (0)