0 votes

extends Node2D#Spawner

const enemy = preload("res://enemy.tscn")

func onTimer_timeout():
randomize()

var posX = rand_range(700, 1250)   
var posY = 0
var fall = enemy.instance()
add_child(fall)
fall.position = Vector2(posX, posY) 
$Timer.wait_time = max(.01, $Timer.wait_time - 0.01) 

extends Node#global.gd

var letters = ["a", "b", "c"]
var sel = ""

var temp = ""
var A = "a"
var B = "b"
var C = "c"

signal tile_destroyed

func _process(delta):
randomize()

sel = letters[rand_range(0, len(letters))]

func letterDestroyed():

emit_signal("tile_destroyed") 

extends Area2D

var wordA = ""
var motion = Vector2()
onready var sprite = get_node("Sprite")#Get's the Sprite of the node

var A = preload("res://A.png")#Image A
var B = preload("res://B.png")#Image B
var C = preload("res://C.png")#Image C

func ready():
if global.sel == global.A:
print(global.sel + "-")
print(global.A + "-")
sprite.set
texture(A)#Changes the image to A if global.sel = A
pass

if global.sel == global.B: 
    print(global.sel + "+")
    print(global.B + "+")
    sprite.set_texture(B)#Changes the image to B if global.sel = B
    pass

if global.sel == global.C:
    print(global.sel + "'")
    print(global.C + "'")
    sprite.set_texture(C)#Changes the image to C if global.sel = C
    pass

func physicsprocess(delta):
motion.y = 170 * delta
translate(motion)

func onNode2Dinputevent(viewport, event, shapeidx):
if event.is
pressed():
global.temp = global.sel
print(global.temp + " if pressed")

    if global.temp == global.A:
        global.temp = global.A

    elif global.temp == global.B:
            global.temp = global.B

    elif global.temp == global.C:
            global.temp = global.C



    global.letterDestroyed()#Global signal to display the letter if Area2D is destroyed
    queue_free()

extends RichTextLabel

const sp = preload("res://enemy.tscn")

func ready():
global.connect("tile
destroyed", self, "updatetext")
update
text()

func updatetext(): #add letters to the screen(RichTextLabel)
if global.temp == global.A:
add
text(global.temp)
print(global.temp)

elif global.temp == global.B:
    add_text(global.temp)
    print(global.temp)

elif global.temp== global.C:
    add_text(global.temp)
    print(global.temp)
in Engine by (12 points)

Can't see what's the issue here! Your code runs fine: if I click on an enemy (spawning at a random x-position at the top border of the screen and moving downwards with constant velocity), it's freed and the letter currently saved in global.temp is added to the RichTextLabel. Which seems to be exactly what you are asking for?

Also please format your code properly. Every line in a code block has to be indented, use the Preview below the editor window to make sure everything looks alright. You can still edit your post by clicking on the three dots at the lower right of your question.

Thanks and my bad this is the first time I'm posting and I didn't explain it well, my problem is when I clicked the falling letters for example A, sometimes a "C" would display. I random generate the letters in global.gd in the func _process(delta): and even though I save the in global.temp I get that problem.

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 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 webmaster@godotengine.org with your username.