Topic was automatically imported from the old Question2Answer platform.
Asked By
mabelair88
Hi, I am modifying a Hangman game. I want to search different combinasion of text string by pressing an unique button. Signal documentation is not explaining why I can not add arguments to my script.
extends Node2D
export (String) var input
var line = preload(“res://scenes/space.tscn”)
var arr_labels =
var alpha =
var arr_spaces = #var s =
var alphabetFile = [“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”,
“K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”,
“U”, “V”, “W”, “X”, “Y”, “Z”]
var correspondance = {
‘a’: ‘aàäâ’,
‘c’: ‘CÇ’,
‘e’: ‘eêèéë’,
‘i’: ‘iîï’,
‘o’: ‘oôö’,
‘u’: ‘uùüû’,
‘A’: ‘AÀÄÂÆ’,
‘C’: ‘CÇ’,
‘E’: ‘EÊÈÉËÆŒ’,
‘I’: ‘IÎÏ’,
‘O’: ‘OÔÖŒ’,
‘U’: ‘UÙÜÛ’ }
var abc =
var abc_separer =
var lettre = null
var words = null
var word_separer =
var length
var temp
signal notthere
signal goodjob
signal mayoi
func _ready():
randomize() #abc_separer = alphabetFile.rsplit(“,”)
abc = alphabetFile[randi() % alphabetFile.size()]
lettre = abc #get the words from the file and put them in a list
var word_list = (loadWords()) #load the words into an array #for word_separer in word_list:
# print(word_separer)
func loadWords():
var file = File.new();
file.open(“res://dicto/”+str(abc)+“.txt”, File.READ);
var file_string = file.get_as_text();
return file_string
file.close();
func initialize():
var pos = $start.position
var counter = 0
for i in temp:
var space = line.instance()
arr_spaces.append(space)
space.position = pos
space.translate(Vector2(70 * counter, 0))
var lab = space.get_node("letter")
if i != "/":
arr_labels.append(lab)
elif i == "/":
var temp_line = space.get_node("line")
temp_line.hide()
add_child(space)
counter = counter + 1
func not_there():
emit_signal(“notthere”)
func handle_string(s):
var pos = temp.find(s)
#$main/game/alphabet/menu/VboxContainer/Button.hide()
$click.play()
if pos != -1:
################
print(correspondance)
for i in range(pos, length):
if temp.substr(i, 1) == s:
arr_labels[i].text = s
temp = temp.replace(s, "/")
alpha.append(s)
elif alpha.find(s) != -1:
pass
else:
emit_signal("notthere")
my word in the game is :“effrayés”
My function “func handle_string(s):” is working good with all single letter. But for this example it does not work when I press the key F the function finds 2 F.
But when the key E is pressed, I receive this error: E 0:00:45.648 emit_signal: Error calling method from signal ‘pressed’: ‘Node2D(word.gd)::handle_string’: Method expected 1 arguments, but called with 5…