Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to have a variable assigned to code?

Asked by 3 years ago

Hello, I am not allowed to post on the dev fourm due to my rank so I'm posting here. Anyways I am trying to make a event that happens in my game, but I'm wondering if you can shorten code? Like with variables you can do

local part = workspace.Part

so it can shorten the code. So you don't have to type

workspace.Part.BrickColor

instead you can say

part.BrickColor

But I am wondering if you can do that with code, Ill give you an example:

local fire = if game.Workspace.Fireworks1.FireworksClassicStyle.Trigger.Value == false then
    game.Workspace.Fireworks1.FireworksClassicStyle.Trigger.Value = true
    else
        game.Workspace.Fireworks1.FireworksClassicStyle.Trigger.Value = false
    end 

so instead of my copying and pasting that (which I would probably have something else copied already) I would just type "fire" and the firework launcher would fire a rocket. If you can't make a "code varible" that way then is there any way? I havent seen any of those in the code in free models Ive learnt from. So that doesn't give my that much hope that is exists. But even if it does/doesn't, thanks for your help!

0
Just put your code into a function and then call it Warfaresh0t 414 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Define Code in a function:

function MyFunction()
if ImDumb == true
then
print("I am Dumb")
end
end

If you need it later, call it with the name of the function:

MyFunction()
Ad

Answer this question