How would I get and access a function from inside another table with just the name of said function?

Hard to explain.

Basically, I have a module which will handle the functionality of various objects. I have each object type inside a table, like so:
image

The objects have an attribute appropriately titled “ObjectType”.
image

I tried doing this, but it just gave me an error: attempt to index nil with ‘activate’
image

I’m hoping you understand what im trying to do, and if you do, how would I do it? More info will be provided if needed.

2 Likes

You can use shared() in order to share a table between every script. An example would be:

--functions script
shared().MyFunctions = functions

--another script

shared().MyFunctions['LightBox'].active()

shared() doesn’t get replicated between client and server and I would also recommend to research a bit about shared() since I’m not sure if its deprecated.

1 Like

What you have should work, its just whenever something else has an “ObjectType” its checking for an activate() function, so if another ObjectType doesn’t have that function, its gonna return nil.

1 Like

Sorry, both the first and third image are within the same script.

The issue I’m experiencing is that the GetAllFromModel function cannot find, lets say “Flashlight” inside the functions table, even if both are the same name and everything. I’m confused as to why this isn’t working now since it has worked for me before.

1 Like

print out obj:GetAttribute(“ObjectType”)

2 Likes

Ah. You figured it out, and I’m just realizing how stupid I am.

The issue was that there were other objects with different types that have no functionalities yet, and it always checked for an object named “Flashlight” first, errored, and thus the rest of the code wouldn’t run. Thanks.

2 Likes

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