![]() |
Attention | 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)
#temp = str(input)
word_separer = word_list.rsplit(",")
input = word_separer[randi() % word_separer.size()]
temp = input
arr_labels.clear()
alpha.clear()
arr_spaces.clear()
temp = temp.replace(" ", "/")
initialize()
temp = temp.replace("/", "")
length = temp.length()
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…
here is the game.tscn file:
enter code here[gd_scene load_steps=6 format=2]
[ext_resource path=“res://scenes/game.gd” type=“Script” id=1]
[ext_resource path=“res://scenes/word.gd” type=“Script” id=2]
[ext_resource path=“res://assets/sounds/click.wav” type=“AudioStream” id=3]
[ext_resource path=“res://scenes/menu.tscn” type=“PackedScene” id=4]
[ext_resource path=“res://scenes/person.tscn” type=“PackedScene” id=5]
[node name=“interactive” type=“Node2D”]
script = ExtResource( 1 )
[node name=“word” type=“Node2D” parent=“.”]
script = ExtResource( 2 )
input = “godot is”
[node name=“start” type=“Position2D” parent=“word”]
position = Vector2( 104.633, 112.391 )
[node name=“click” type=“AudioStreamPlayer” parent=“word”]
stream = ExtResource( 3 )
[node name=“alphabet” parent=“.” instance=ExtResource( 4 )]
margin_left = 314.0
margin_top = 245.0
margin_right = 726.0
margin_bottom = 321.0
[node name=“hangman” parent=“.” instance=ExtResource( 5 )]
[connection signal=“reset” from=“.” to=“word” method=“_on_game_reset”]
[connection signal=“goodjob” from=“word” to=“.” method=“_on_word_goodjob”]
[connection signal=“notthere” from=“word” to=“.” method=“_on_word_notthere”]
[connection signal=“pressed” from=“alphabet/VBoxContainer/Button” to=“word” method=“handle_string” binds= [ “a”, “à”, “ä”, “â” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer/Button2” to=“word” method=“handle_string” binds= [ “n” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer2/Button” to=“word” method=“handle_string” binds= [ “b” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer2/Button2” to=“word” method=“handle_string” binds= [ “o” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer3/Button” to=“word” method=“handle_string” binds= [ “c” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer3/Button2” to=“word” method=“handle_string” binds= [ “p” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer4/Button” to=“word” method=“handle_string” binds= [ “d” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer4/Button2” to=“word” method=“handle_string” binds= [ “q” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer5/Button” to=“word” method=“handle_string” binds= [ “e”, “ê”, “è”, “é”, “ë” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer5/Button2” to=“word” method=“handle_string” binds= [ “r” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer6/Button” to=“word” method=“handle_string” binds= [ “f” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer6/Button2” to=“word” method=“handle_string” binds= [ “s” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer7/Button” to=“word” method=“handle_string” binds= [ “g” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer7/Button2” to=“word” method=“handle_string” binds= [ “t” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer8/Button” to=“word” method=“handle_string” binds= [ “h” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer8/Button2” to=“word” method=“handle_string” binds= [ “u” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer9/Button” to=“word” method=“handle_string” binds= [ “i”, “î”, “ï” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer9/Button2” to=“word” method=“handle_string” binds= [ “v” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer10/Button” to=“word” method=“handle_string” binds= [ “j” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer10/Button2” to=“word” method=“handle_string” binds= [ “w” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer11/Button” to=“word” method=“handle_string” binds= [ “k” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer11/Button2” to=“word” method=“handle_string” binds= [ “x” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer12/Button” to=“word” method=“handle_string” binds= [ “l” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer12/Button2” to=“word” method=“handle_string” binds= [ “y” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer13/Button” to=“word” method=“handle_string” binds= [ “m” ]]
[connection signal=“pressed” from=“alphabet/VBoxContainer13/Button2” to=“word” method=“handle_string” binds= [ “z” ]]
[editable path=“alphabet”]
the software allow us to add arguments in the signal link.
But I do not know how to make the the software verify the existance of E and É