The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes
extends Node2D

func _randomize():
    var a = 0
    a = randi()%10 + 1
func _process(delta):
    if Input.is_action_just_pressed("ui_accept"):

When the label text is set to "a" and when "a" is printed I am given two values. I have tested this on other nodes and with many variables, with 2 separate values being the minimum. I know I messed up somewhere because i only get one value in a new project and I know the issue of a declared variable being edited by multiple functions. I apologize if this is common sense, as I am new to coding and have no idea how to fix this issue. Any help would be appreciated, thank you.

in Engine by (12 points)

It seems likely you have this script attached to more than one node, so when you press the key, the function is called on both of them.

This code is attached to a KinematicBody2D that is a child to the main world scene. Should the KinematicBody2D have its own separate scene? I have been putting most things into one scene while nodes that I create have their own scene eg. bullets, afterimage, asteroids. Thank you for the response and all of the help you have provided with tutorials and answers to other users.

edit: The code was originally on a KinematicBody2d but I made a separate node2d and a new script to see if I still got 2 values. That's why the scrips above says Extends Node2d.

change it to prints(self, a) and run it. you will likely see that you have two nodes running the same script at the same time.

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.