How do I trigger a function in a separate script?

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I’m making my first VR game and I’m trying to make it so that when the player hits a cube it starts the mode that the cube represents. My issue is that the function I’m working on is in another script and I can’t find out how to trigger it from the first script.

Here is the first script.

extends Area3D


func _on_area_entered(area):
	timed_mode()
	queue_free()

and here is the second one to be triggered.

extends Node3D

func _timed_mode():
	var spawn_cube = load("res://cube.tscn").instantiate()
	spawn_cube.position.x = 1
	spawn_cube.position.y = 1
	spawn_cube.position.z = 0
	spawn_cube.rotation.y = 90
	add_child(spawn_cube)

I have both scripts on Autoload:

I have no idea what to do here.

You have to put the name of the node/script, then a dot, the the function.
Like this I think: TimedStartCube.timed_mode()
Also, you don’t need to global your scripts, there are other ways to access it, like right clicking the node and hitting access as unique name, letting you access it from other scripts with %

That seemed to work, Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.