Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is is possible to create your own API for scripts?

What I'm trying to say is, I want to make an API for scripting. Basically like JQuery. So how could I make an api so if I write say "Hello", and run it, it outputs Hello. Basically I want to replace print with say. How could I do that, if it's possible?

3 comments

0

say = print

0

I don't think that you can do that. I'm talking about that players can use "say" and don't have to define it in their script.

0

you could create a module with all of your own functions if you wanted to. (I am talking about Module Scripts)

1 answer

✓ Accepted answer

There are two ways that I know of that you can use to create your own API. Both of these were actually mentioned on the comments by @cabbler, and @PyccknnXakep.

Method 1: Variables In your question you said that you would like to "... replace print with say." Well, this is fairly easy to accomplish. Here's a couple variable examples:

local say = print;
local getmod = require;

say "Hello World!";
local module = getmod(game.Workspace.ModuleScript);

These would both work, and there are other parts of the RBXAPI you can use.

Method 2: Module Scripts Module scripts are a fundamental part of Roblox. They serve many purposes and can be used to create an API. Here's a couple examples:

local api = {};

function api:Say(text)
	print(text);
end

function api:getMod(variable)
	return require(variable);
end

return api;

Then inside of another script:

local api = require(game.Workspace.ModuleScript);

api:Say("Hello World!");
local module = api:getMod(000000);

Hope this was helpful.

This discussion is preserved as it was. New answers, comments, and votes are closed.