Beginner's Roblox Scripting Tutorial #7 - Parameters (Beginner to Pro 2019)

preview_player
Показать описание
Beginner's Roblox Scripting Tutorial #7 - Parameters (Beginner to Pro 2019)

Hey guys, in today's video I am teaching you about parameters and I promise you this is the last tutorial on functions for a while because I know the past 3 were on functions and it was probably quite boring! But anyways this is very important so enjoy and learn peace!

Link to Beginner's Tutorial Series:

-- Join my Discord Server to learn and meet other developers!--

--What is this series about and who is it for?

So this series is meant for people who really want to learn exactly how to script, if that is you then I promise by the time you watch this whole series you will know exactly how to script on roblox. Anyways be sure to subscribe to see whenever I release a new tutorial and I will see you guys in the next one. Peace!
Рекомендации по теме
Комментарии
Автор

If anyone wants an example of how this can be used, review this code:

local part = game.Workspace.Baseplate

local function transformfunc (mat, trans)
part.Material = mat
part.Transparency = trans
end

transformfunc("Sand", 0.5 )
wait(10)
transformfunc("LeafyGrass", 0)


Its quite simple, the moment you start the game the baseplate will become sandy and half transparent, then after waiting 10 seconds the code will run the function again, except with different parameters. It can be a huge help when you want an item or value to go through different states after a certain requirement has been met. Parameters are used here simply to save time and simplify code.

TofuTuesdays
Автор

Holy. Thank you sir, you're the only individual who has explained parameters in a way so that I could understand them.

enlasted
Автор

I am so confused

But I’m never giving up! I will watch this series over and over if I have tooo!

emmettnredblue
Автор

others tutorials: 20 minutes
TheDevKing tutorials: 5 minutes


thx god!

GDcelta
Автор

Helllo, U Helped me Alot Im Nomrallly an Animator for stickman figures then i learned how to Animate on roblox But then i said to my self, "I cant ony animate cause i dont even know how to put it in a key or how to make moves and Justu, punching, Magic etc Im so happy, i learned alot from you and u desserve more subs!

kemonogane
Автор

For those who don’t understand or still confused, parameters are like variables. Just think of them as variables, as in function(x, y). If you call function(1, 2), then x = 1 and y = 2.

Since quite a decent amount of people see this, I’ll just add some more information, don’t read further if you’re easily confused. The variables that are passed into the parameters are actually copies. I’ll show you what I mean (and I haven’t touched Lua in a long time so I’ll be doing this with “pseudocode” mixed with C++):
Let’s say we have a function called add that takes two integer variables…

func int add(int x, int y) {
return x + y;
}

And we have two variables called num1 and num2 outside, declared like so:
int num1 = 0;
int num2 = 1;

Then passing that into the function - add(num1, num2) - should return 1 alright.
Now let’s say we want to edit the parameters, adding 2x of each number (ex: x*2 + y*2).

func int add(int x, int y) {
x = x*2;
y = y*2;
return x + y;
}

So what do you think will happen if we run add(num1, num2) now? It should return 2 because 0*2 + 1*2 = 2. But here’s a question that comes up a lot with amateurs: are num1 and num2 multiplied too? No, the variables num1 and num2 are not changed AT ALL. This is because they’re passed in as parameters so int x and int y are simply variables that exist inside the function and the function only. Knowing some of you curious dedicated hardworking learners, you may ask, “Then how would I reference variables outside with my parameters?”

Don’t worry, there’s a way. I’ll update this later because I’m on a phone.

Alright here's the next part :)
So in a language called C++, you can do so easily with something called "pass by reference". It works by defining the function as:
function int changeNum(&num)
Where the symbol & means "reference". However, this is (as far as I know) pretty much a C/C++ thing. We can work around it, however, in other languages like Lua. This requires a decent understanding of classes and objects. Just know that, classes are the templates to making objects, and they are basically "custom" data types programmers can write on their own. So we can have a "Person" class, with attributes like name and age (which has data types of String and int respectively), then we can mass produce people by making a ton of objects from that template. Weird analogy but I think it works (?). Moving on, primitive types are the basic building blocks of code. You've been using them already - int, double, boolean (true/false), char, etc. (Strings are objects btw because they are an array of char). What this basically means is that a String "references" where in the memory the first char is stored, and how many chars are after it, because we can only allocate so many data in a "block" (think binary 1s and 0s). We can't possibly have a whole chunk representing a string when they're just chars put together. If you see where I'm going with this, you're on track.
Yes, we CANNOT pass by reference by doing function changeNum(num) because we're in Lua. But it's a different story if the parameter we're inputting is an object. Just make the primitive type into an object in any miraculous way possible. Store it in a table for example, idk lol.

P/S: I haven't tested any of this second part but my guess should be right lmao you can test it on your own if it doesn't work uhh complain about it to me and I'll work on it.

Lycoriste
Автор

Hotdogs are the student that always gets picked, if he calls in sick the teacher will just call him on the phone.

normalhuman
Автор

TheDevKing: i need a name
hotdog: :I
TheDevKing: ok, i'll use you

EnderghostLD
Автор

hi i am litterilly watching this hole series all night he sun is just coming up

tepara_skates
Автор

great man, i watched your videos a long time ago but got caught up in some work so i forgot a lot, but its good to see that i had still subbed to your channel and now i can re learn it all! :)

overklls
Автор

here before 7, 000, 000, 000 subscribers! dude your the best

thyst
Автор

Guys, if his explanation of parameters was confusing, I'll provide the explanation that worked for me.
Basically, in his first example function, he writes:
local function add(hotdog, ham)
print (hotdog + ham)
end
Then the next line he types add(2, 3), and running the script puts 5 into the output.
Basically, the function add() was defined as adding the two values in the parenthesis. In the first block of code, which acted like a definition of the function, the values are hotdog and ham. In the next line of code, which says print (hotdog + ham), it means that because hotdog and ham are in the parenthesis, it's gonna add the values hotdog and ham and print the result into the output. The function basically says, "If I have two values in my parenthesis, I will be adding those values and printing whatever I get after I added those values."
So basically he used the parameters to help define what he wants his function to do and make it more useful in terms of what it can do. I like to think of parameters as parts of the definition of a function.
Hopefully this was a helpful explanation.

idarky
Автор

You are so underrated. You’re tutorials are amazing and you deserve more subscribers and viewers! You are so friendly and id much prefer to watch your tutorials than anyone else’s because you explain them so much easier and you’re very understanding. ❤️

iideathlymusic
Автор

Here before 6969 subs, I love your tutorials. I always wanted to learn lua, but all tutorials SUCKED, but yours is actually helpful. I will make the best games I can with all this when I reach the end of these tutorials

lacasadepapel
Автор

Somehow this is quite better than any guide i've seen, i'm already an amateur, i've coded a few simple games in roblox. yet this already started explaining in the most understandable ways thing i never understood even after 1 year of programming. sweet.

VodkaDoge
Автор

this series of 4-12 minutes long videos have been more useful than a complete 48 minute long video

ty so much(sorry for bad english)

isandreww
Автор

the more i watch these tutorials and the more devking uses functions and variables, the better i feel. This truly is a beginners tutorial, thank you devking

roatninthethird
Автор

Your videos are so easy to understand and you actually explain everything you do, than just write some code and dont explain anything about it.Ty TheDevKing for your videos, they are truly brilliant.

johnnycrippledboy
Автор

Throughout the whole series I noticed something

DevKing likes hot dogs

fluffypanda
Автор

I have watched up to now and so far, you have been so extremely helpful! The only thing I wish you would do is use the scripts in a way you would normally use it instead of printing Hotdog.

jadenquin