|
|
|
 |
Reply From: |
njamster |
If you access the text
-property of a TextEdit, you’re getting a copy of its current value, not a dynamic reference to it. It’s easy to see by running this script:
func _ready():
var value = $TextEdit.text
print(value)
$TextEdit.text = "Blau"
print(value)
So in your first example, you’re erasing the last character in a copy of the displayed value and then do nothing more with it. In the second example you’re getting the copy, erase from it and then overwrite the current value with the modified copy.
This is wrong. You can call erase on the property but you can’t access the results.
Furthermore it seems that your example proves nothing! Of course when you don’t change “value” its value its not changed. Besides if $TextEdit.text returns a copy of the value, how $TextEdit.text = “Blau” changes the property value?
This is wrong. You can call erase on the property but you can’t access the results.
Where exactly am I wrong? I never wrote, that one cannot useerase
on the property. However, erase
is an in-place operation, i.e. it doesn’t return anything. So if you can access a string, you can also access the result of erase
on it - always! The confusion stems from the fact that $TextEdit.text
returns a string and erase
is called on this string instead of the original value. So the original value won’t change - obviously.
njamster | 2020-03-21 10:00
Sorry I didn’t mean you are wrong. I meant the behavior is wrong. erase should either act on the reference or return the result.
I meant the behavior is wrong.
That’s your opinion. I’d consider it good (and common) practice.
erase should either act on the reference or return the result
It acts on the string you pass it, nothing more, nothing less.
Of course when you don’t change “value” its value its not changed.
If the variable value
would contain a reference to $TextEditor.text
, than changing $TextEdit.text
would also change the variable of value
. As this is not the case (it contains a value) it doesn’t, yes. That’s my point.
Besides if $TextEdit.text returns a copy of the value, how $TextEdit.text = “Blau” changes the property value?
Because the latter is equivalent to calling the setter-method set_text(value)
and the former is equivalent to calling the getter-method get_text(value)
.
njamster | 2020-03-21 20:30
I disagree that it is a common practice and definitely not a good one. The getter should either return a read-only object which no in-place method can be called upon or erase should return the changed string. If non of these options are met, it is simply wrong. It is wrong because erase (or other such methods) are acting on a variable you don’t have a handle of. I conclude it is a GDscript design flaw.