![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | PampoenKoekie |
func _input(event):
# Check the keyboard typing and append it to Global variable typedWord
if event is InputEventKey:
if event.pressed:
var typing = char(event.unicode).to_upper()
Globals.typedWordArray.append(typing)
if event.is_action_pressed("ui_text_backspace"):
Globals.typedWordArray.pop_back()
print (Globals.typedWordArray)
Edited to format the code. Use the Code Sample button.
Also, please don’t post screenshots of your code. It prevents people from testing your code or even reading it. Post the code as text: paste it in the text box, select it, and click the Code Sample button (it needs to be indented by 1 level to be formatted).
pop_back
will only do something if the array is not empty, assuming your if
is entered.
What problem are you actually encountering? What do you mean by “pop_back not working”?
Zylann | 2023-07-06 14:04
Thank you for you reply. The array is not empty, I type a word and show what im typing in a label, all works great. Then when I want to erase the last element by pressing backspace, I want to use pop_back(), but it just does nothing, but if I replace it with pop_front() it works as I want but only in reverse. I print the array to console to see what it does and it writes to to the array fine, it reads from the array fine and when I use pop_front(), the array shows removing the first element in console, but as soon as I change it to pop_back(), nothing happens. Thats why Im not understanding. Even if I use clear() method on the array it works.
I could make a video clip aswell showing it all, but thank you for your help.
PampoenKoekie | 2023-07-06 14:13
Thanks for your help, Im new here so still learning.
PampoenKoekie | 2023-07-06 14:20
I don’t know what’s up with this tbh. Did you try testing pop_back
in a very simple project or scene to see if it works as intented?
I see no reason for pop_front
to work and not pop_back
…
What kind of array is typedWordArray
?
Zylann | 2023-07-06 14:21
Yes, its really weird, all methods work except pop_back(). I will try your advice on a test project and see what’s going on… typedWordArray is a Global String array.
# Array for seperate letters being typed
var typedWordArray = []
PampoenKoekie | 2023-07-06 14:30