My GDScript Code and Concatenation

Hello :wave:

So, this is my first line of code and in the challenge we had to create our own string that gradually increases with the spacebar being hit.

I created a variable called count_up and declared it as int and set the value as 0

var count_up: int = 0

I found a way to concatenate the string so that it reads “Spacebar was pressed x times” on one line, rather than two, like so.

image

To do this I updated the print statement to include + str(count_up) (converting the int to a string)

if Input.is_action_just_pressed("ui_accept"):
		print("Spacebar was pressed " + str(count_up) + " times")
		count_up = count_up + 1```

and it displayed nicely in the console.
I hope this helps anyone trying to figure out how to add their message as one long string. :slightly_smiling_face:

1 Like

I think it will help more people if it was posted in the Godot section instead of the Unity section. :wink:

You can edit the title and change the category. I don’t have the permissions to do it for you

1 Like

Oh, I thought it was posted to the Unity section… :man_facepalming:
Thanks anyways, I’ve updated the category :slight_smile:

Privacy & Terms