0 votes

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 arrlabels = []
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Ç',
'I': 'IÎÏ',
'O': 'OÔÖŒ',
'U': 'UÙÜÛ' }
var abc = []
var abcseparer = []
var lettre = null
var words = null
var word
separer = []
var length
var temp

signal notthere
signal goodjob
signal mayoi

func ready():
separer = alphabetFile.rsplit(",")
abc = alphabetFile[randi() % alphabetFile.size()]
lettre = abc
#get the words from the file and put them in a list
var wordlist = (loadWords()) #load the words into an array
#for word
separer in wordlist:
# print(word

#temp = str(input)
word_separer = word_list.rsplit(",")
input = word_separer[randi() % word_separer.size()]
temp = input

temp = temp.replace(" ", "/")


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

func initialize():
var pos = $start.position
var counter = 0

for i in temp:
    var space = line.instance()
    space.position = pos
    space.translate(Vector2(70 * counter, 0))
    var lab = space.get_node("letter")
    if i != "/":
    elif i == "/":
        var temp_line = space.get_node("line")

    counter = counter + 1

func notthere():

func handle_string(s):
var pos = temp.find(s)

if pos != -1:
    for i in range(pos, length):
        if temp.substr(i, 1) == s:
            arr_labels[i].text = s
    temp = temp.replace(s, "/")
elif alpha.find(s) != -1:

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 emitsignal: Error calling method from signal 'pressed': 'Node2D(word.gd)::handlestring': Method expected 1 arguments, but called with 5..

core/object.cpp:1228 @ emit_signal()

here is the game.tscn file:

enter code here[gd_scene load_steps=6 format=2]

[extresource path="res://scenes/game.gd" type="Script" id=1]
resource path="res://scenes/word.gd" type="Script" id=2]
[extresource path="res://assets/sounds/click.wav" type="AudioStream" id=3]
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 )]
marginleft = 314.0
top = 245.0
marginright = 726.0
bottom = 321.0

[node name="hangman" parent="." instance=ExtResource( 5 )]
[connection signal="reset" from="." to="word" method="ongamereset"]
[connection signal="goodjob" from="word" to="." method="
[connection signal="notthere" from="word" to="." method="onwordnotthere"]
[connection signal="pressed" from="alphabet/VBoxContainer/Button" to="word" method="handle
string" binds= [ "a", "à", "ä", "â" ]]
[connection signal="pressed" from="alphabet/VBoxContainer/Button2" to="word" method="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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="handlestring" 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 É

in Engine by (31 points)

Please log in or register to answer this question.

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 [email protected] with your username.