0 votes

hi.
im messing a bit around with the gd script and im trying to do something...

i want that if a label has the text hi, an other label writes also hi. i tried to do it like so:

func _process(delta):

if $Labelperson.text = "hi":
$LabelAI.text = "hi"
pass

but this doesnt work.
Has someone an idea to solve this?
the error is "Unexepected assign"

(i dont usually speak english,so im sorry for any
spelling mistakes)

Godot version 3.3
in Engine by (213 points)

4 Answers

+4 votes
Best answer

= is used to assign value to a variable or to a property in inspector so you can use

$label.text = "apple"

To assign value to text property of label.


Whereas to compare values you have to use ==. And hence:

if $label.text == "apple":
    print("labels text is apple")
by (909 points)
selected by
0 votes

if $Labelperson.text == "hi":
$LabelAI.text = "hi"

you put = which means it changes, and == means is it equal to

by (61 points)
edited by
0 votes

so, now i got another problem...
if i want to ask the question to the "AI", i can click a button or press enter.
but the if statement just gets called if you press the button, not if you you press enter.

this is my code:

func process(delta):
if Input.isactionjust_pressed("enter"):
$Labelperson.text = $TextEdit.text
$TextEdit.text = ""

if $Labelperson.text == "apple":
    $LabelAI.text = "ok..."
pass

func onButton_pressed():
$Labelperson.text = $TextEdit.text
$TextEdit.text = ""

pass 
by (213 points)
edited by
+1 vote

Your code seems to be right. There might be some other errors. So try adding both enter keys in the input map for "enter" event. Cross check spelling of enter in both from input event and from your code. And remember "apple" and "Apple" are both different strings.

If still it don't work then add some print() like "enter key was pressed" , "if statement worked" etc. to check which part of code did not worked. And then act accordingly.

by (909 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.