Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Plaz_GD |
Hello everyone.
A week later of learning Godot. One of my friends gives me a utils script (utils.gd) for me to try to learn and understand. And so far, I haven’t fully 100% understand it. Here’s the code:
extends Node
var mouse_pos setget, _get_mouse_pos
var main_node setget, _get_main_node
var view_size setget, _get_view_size
func _ready():
pass
func create_timer(wait_time):
var timer = Timer.new()
timer.set_wait_time(wait_time)
timer.set_one_shot(true)
timer.connect("timeout", timer, "queue_free")
add_child(timer)
timer.start()
return timer
pass
func choose(choice):
randomize()
var rand_index = randi() % choice.size()
return choice[rand_index]
pass
func search_node(node):
return self.main_node.find_node(node)
pass
func attach(src_node, src_signal, trg_node, trg_func):
if typeof(src_node) == TYPE_STRING:
src_node = search_node(src_node)
if typeof(trg_node) == TYPE_STRING:
trg_node = search_node(trg_node)
if src_node != null and trg_node != null:
src_node.connect(src_signal, trg_node, trg_func)
pass
func remote_call(src_node, method, arg0 = null, arg1 = null):
src_node = search_node(src_node)
if src_node and src_node.has_method(method):
if arg0 and arg1:
return src_node.call(method, arg0, arg1)
if arg0:
return src_node.call(method, arg0)
return src_node.call(method)
pass
func _get_mouse_pos():
return get_viewport().get_mouse_position()
pass
func _get_main_node():
var root = get_tree().get_root()
return root.get_child( root.get_child_count() -1 )
pass
func _get_view_size():
return get_tree().get_root().get_visible_rect().size
pass
I’m curious to know the usefulness of this utils. If someone could write a specific explanation in detail, that would be appreciated.
~ Regards
Also, I would like to thank Eldam for the answers in my previous topic question, regarding the mute button 10 days ago. Sorry, I forgot to be thankful for the help. ( Mute Button - How to pause the music in game background? - Archive - Godot Forum )
One of my friends gives me a utils script […] I haven’t fully 100% understand it
Just curious: Why don’t you simply ask your friend?
njamster | 2020-05-22 09:57
He often replied: “Try to learn it for yourself for this matter”. Maybe because I ask him too much, considering his always busy.
Plaz_GD | 2020-05-22 10:19