Roblox Function [ ASK ]

I know is a stupid question, but it’s more about my curiousity, is there a way to make function but with split string, like function Hello World() because what I know now you have to combine the string as function Name, like function HelloWorld() or maybe even worse thinking like function Hello(A).World(B)(). This is all just to settle my curiosity

1 Like

with dictionary notation you could, it’s similar to how ModuleScripts work:

local module = {}

function module.HelloWorld()

module["Hello World"] = function()
	print("Hello World")


return module

Now requiring this module will output:

  > require(workspace.ModuleScript)
   ▼  {
    ["Hello World"] = "function",
    ["HelloWorld"] = "function"

Effectively “Hello World” becomes a string-type key inside of the module dictionary, so you can reference it as module["Hello World"]() or the atlernative module.HelloWorld()


Yes, in module script we can make like function Module.Blablabla(A, B) right
But more about my curiousity is let’s say Module(A).Blablabla(B)

Apart from @MP3Face’s work around the general answer is no, because whitespaces and indentation are actually important in Lua, as well as many other similarly typed languages like Python.

1 Like

So according to my curiousity, I reiterate once again this is stupid, I know, just out of curiosity. Is like function Module(A).Thing(B)()
print(A…” “…B)

So player just need to Module(“Hello”).Thing(“World”)
And later it will print(“Hello World”)

Because from how I know it how usually it be is like Module.Thing(“Hello”, “World”)

I know this is so stupid, but yeah what can I say, curiousity.

Or can I run functions on the same line?
So usually is gonna be like

Can it be
A() B()

Yeah i think this question is better than previous.

You can embed things like that in a dictionary. Back to my example:

local module = {}

module["A"] = {
	["B"] = function()
		print("A ... B")

return module

Then you can call module["A"]["B"]() to execute function B within A.

No language I speak can call functions like that, but you may be able to define your own object to parse that sequentially, calling it in reverse order of B()'s return → A()'s parameters. Here’s something close using the modulescript example yet again:

local module = {}

module.Hello = {
	Thing = function(str)
		print("Hello " .. str)

return module

Then calling module.Hello.Thing("World") would work.

1 Like

You can’t have a space inside a variable name, so no.

local Hello World = 6
-- this is bad

When you create a function using function, what you’re doing is creating the function and then assigning it to said variable.

local function Hi()


is the same as

local Hi = function()


In either case, Hi is just a variable.

Functions don’t have “names”, just like numbers and strings don’t have “names.” The “name” of the function isn’t Hi, that’s just the variable it’s assigned to.

When you say

local Hi = 5

you’re not saying the name of 5 is now “Hi,” that’s just the variable it’s assigned to.

Same for functions.