Writing script for interactions

Godot Version

4.2.2

Question

so im trying to write a script for my game so i can detect objects and interact with those objects but I’m getting two different errors at the moment, the first is when i type the code as it is in the tutorial.

Error could not find type “interactable” in current scope

after i tried adding in a var with the interactable and a ready function but im still receiving an error and dont know what to do at this point.

error 2 intractable is a variable but does not contain a type.

if you could help point me in the right direction on what i can do to make this work id appreciate it

Is this from following a tutorial?

to be used in keyword is it must be a Type, not a variable. You can create a Type with class_name Interactable, best to use this on your base interactable script.

1 Like

so i did write one in the script of the actual object would it make more sense to write it here as well

I do not understand. You wrote a class_name? var Interactable is not a class_name it’s a variable. On the interactable script you should write

class_name Interactable extends Node3D

With Node3D replaced by what ever your base type is.

1 Like

okay thank you for the reference and response.

so i took the class_name interactable out of the object script and rewrote what you put into the raycast so now its class_name Interactable extends RayCast3D.

this code works kinda. it loads the game but it still isn’t recognizing my objects or having my prompt text pop up which is what i want to happen. i have the lable set up as prompt in the script.

im thinking ill have to rewrite that part of the script using a ready function? or should i try a diffrent method all together

It sounds like you did class_name Interactable on your InteractRay script? You can’t if detected is Interactable if your thing detecting is itself the Interactable. I notice a “lockersInteratable” script in your panel, that is probably the on you want to be declared class_name Interactable

1 Like

see i try that but it says it hides a global scrip class and when i add extends to static body it say the same thing. idk how it worked the first time honesty.

i think imma try a work around or do a new project to see if th error continues

It’s because class names can’t be declared twice. Adding a class_name is a global operation, it affects the entire project, you cannot have two class_names that are the same within a single project.

Only your locker or base interactble should have class_name Interactable extends StaticBody not the InteractRay

i know it can’t be twice im saying its acting like the code no longer works.

i had to rewrite it into this


and it work for about 5 minutes before saying this phrase error im not sure why im getting this

Your interactable script has an error, so it cannot parse the type. add pass to the empty interact function body for now.

1 Like

thanks

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