godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Code example error in scripting_continued.rst

Open JakeMcCann opened this issue 9 years ago • 3 comments

In the step by step tutorials, there's a block of code on the scripting continued page:

extends Label

var accum=0

func _process(delta):
    accum += delta
    text = (str(accum) # text is a built-in label property

It says that running this will show a counter increasing in each frame.

When I tried running this there's a couple of things that don't work for me in Godot v2.1.4. In the first instance, there's a missing closing bracket on the final line. Adding that, and running it results in a Parser Error: Identifier not found: text. The only way I can get this to work is to change text = (str(accum)) to set("text", (str(accum))). Then, to get the process to start I needed to add:

func _ready():
	set_process(true)

In the end, to get the code block to do what the tutorial said it would do, I ended up with:

extends Label

var accum = 0

func _process(delta):
	accum += delta
	set("text", (str(accum)))

func _ready():
	set_process(true)

I'm new to Godot, so let me know if I've misunderstood, but that's the only way I could get the example to work. If that's right, I'm happy to submit a PR.

JakeMcCann avatar Sep 23 '17 20:09 JakeMcCann

The missing closing bracket should indeed be fixed.

For the rest, the issue is that you've been following the step by step tutorial of the "latest" branch, which is for the upcoming Godot 3.0: http://docs.godotengine.org/en/stable/learning/step_by_step/scripting_continued.html In Godot 3.0, Label does have a text property which can be accessed directly.

Since you are learning Godot 2.1.4, the stable version, you should follow the tutorials from the "stable" branch: http://docs.godotengine.org/en/stable/learning/step_by_step/scripting_continued.html And there the script makes more sense:

extends Label

var accum=0

func _ready():
    set_process(true)

func _process(delta):
    accum += delta
    set_text(str(accum))

akien-mga avatar Sep 23 '17 20:09 akien-mga

Ah, my mistake; that makes sense. Thank you!

JakeMcCann avatar Sep 23 '17 21:09 JakeMcCann

Bracket was fixed.

mhilbrunner avatar Jan 05 '18 21:01 mhilbrunner