Hello! I’m currently trying to make a modular core for some doors I’m making.
I’m doing this with the idea of not having to rewrite the door’s code every time I’m making something more special, with custom actions and attributes, etc.
With this, instead of writing a long string of if → thens, I decided to create a table with string values assigned to individual functions.
Currently I am using this; keep in mind I’m new to tables.
Actions = {
["Open"] = Open();
["Close"] = Close();
}
InitiateAnim.Event:Connect(function(NewState)
for _,v in pairs(Actions) do
if NewState == Actions[v] then
Actions[NewState] -- Not a thing, that's why I'm posting
return
end
end
end)
Now I don’t even know if I’m properly looking for arguments in the table, but I am unsure how I could fire the assigned function.
Some extra help on how to navigate ‘subarguments’ would be helpful too if you have the time.
In Lua, x[y] is a value and values can’t run alone (unlike Python etc).
As you’re doing Function(), you’re calling the function beforehand, for it to store the function you need to remove the parenthesis.
You’re just indexing the table and not actually calling the functions. The prints should be printing more than just nil though unless you haven’t actually defined open/close. Also, you shouldn’t be using bindable events for this.