|
|
|
|
Reply From: |
ramazan |
onready var key_scene = preload(“res://keys.tscn”)
var keys = null
func _ready():
keys = key_scene.instance()
func _on_keys_pressed:
keys.function_name_to_run()
Can you please add some comments about the code you posted?
In which script I need to put it?
The script that I have the fanction which I want to run is the board script.
The on_keys_pressed() function is in keys script.
I suppose the code goes to board script, but then, first var keys need to declared outside the on_ready and what is the onkeyspressed function? Do you mean the function which is in keys script? Then I get error that keys isn’t declare in the current script. If no, then this is another onkeyspressed function which is in board script? If yes how this function triggers? I tried it and it doesn’t work.
dancaer69 | 2022-01-16 09:38
onready var key_scene = preload(“res://keys.tscn”)
var keys = null
func _ready():
keys = key_scene.instance()
#Note = on key pressed(): your pressed sinyal
func -on-keys-pressed():
keys.func name that should work. Write here the name of the func that should work in
this scene.
don’t forget to add the “()” of the end
I hope I explained
If not, let me explain in more detail.
ramazan | 2022-01-16 09:59
I’m not sure you understood what I want to accomplisse, but this doesn’t work as I wrote.
What I want is:
keys script:
func _on_keys_pressed() -> void:
var temp = self.get_child(0).text
print(temp)
Utils.current_char = temp
detect_block() -> *this is the function from board script I want to add*
From my understanding you proposed this:
board script:
var keys
onready var key_scene = preload("res://keys.tscn")
func _ready() -> void:
keys = key_scene.instance()
func _on_keys_pressed():
keys.detect_block()
The above doesn’t work. The actions which are on keys script for pressed button work but the “keys.detect_block()” function from board doesn’t trigger and doesn’t give any error. Just ignored.
dancaer69 | 2022-01-16 10:33
Add a Button to the scene here and
var keys
onready var key_scene = preload(“res://keys.tscn”)
func _ready() → void:
keys = key_scene.instance()
func _on_keys_pressed():
keys.detect_block()
Try
func _on_Button_pressed():
_on_keys_pressed()
pass
ramazan | 2022-01-16 10:38
Why to do that. I already had the 26 buttons I want to use which are inherited scenes of the keys.scene. The script of this scene(keys script) contains the onpressed function and detects which of the 26 buttons is pressed and run the code for this button.
dancaer69 | 2022-01-16 10:51
You want to run the Function in another scene, right? To the scene you sampled
keys = key_scene.instance()
keys._on_keys_pressed()
If not, sorry I misunderstood the question.
ramazan | 2022-01-16 10:59
The function is in board scene’ s script.
The onpressed function is in keys scene’ s script.
Yes, I want to run the function of board scene script in another scene(keys scene).
I have a main scene in which there are instances of board and all keys inherited scenes but not the original keys scene itself. So I don’t know how to get access to the original keys scene and to use a signal and preload this scene doesn’t work as I wrote on my first post.
dancaer69 | 2022-01-16 11:10