0 votes

I'm fairly new to GDScript so I apologize if this is something super obvious that I've missed haha.

I'm basically working on a system where a player can mine a block. Each block has a Block script that has a function to "mine" itself. I'm wanting to call that from the players script when they presses a button but I can't figure out a way to pass a object (being the block) as a parameter to a function. Can't figure out as in I don't know which variable I should be declaring the parameter as when writing the side function.

func MineBlock(direction : Vector2, block : Block <--- ?????):
if direction.x == -1:
    ChangeAnimation("Mine", true);
else:
    ChangeAnimation("Mine", false);

pass
in Engine by (28 points)

1 Answer

0 votes

You have to check which type of node your block is - is it a MeshInstance, Spatial, etc... Click on the block and on the right side in inspector you will have the type of your node.
enter image description here
In this example, the type of block is Spatial.

Another way is if you add a script to your node (Block), first line of autogenerated content should be "extends " and that is the parameter you should write there. But you can also omit that name since it's only a hint - it's not mandatory.

by (699 points)
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.