@GetNightcored We use local as it is more efficient then a=2 because a=2 is a global variable and sometimes lua gets confused and doesnt use count the variable as a variable due to it being global so using local is much better
A good definition on returning would be a gamepass. If someone buys your gamepass, you want to make sure that they are getting something in return for buying that gamepass. So for example. You make a gamepass that gives a player maybe extra speed, then once they purchase that gamepass, they will receive it. This is also useful in GUI shops and stuff as well.
@@xeistan7793 You okay? I wrote this comment 2 weeks ago and had the wrong idea of returning. Your comment isn't really an insult, more just trying to look for an argument.
For anyone confused about scope here is an analogy: There are two students named Ave(test 1) and Eve(test 2) Ave has 4 pencils Eve has 2 pencils Ave has a pencil named "A" While Eve dosen't have any pencils named A When the teacher said "raise your pencils named A" (Calling the code) Only Ave can raise her hand (successful output) While Eve dosen't raise her hand (Nil) 10 months later I finally understand returning so let me make an analogy for you: Code: Local Function HowManyMusicians () Return("40 - 100") end Print(HowManyMusicians()) Analogy: Let's say you're surfing Google and you want to search how many musicians there are in the orchestra, just opening Google ( calling the function ) isn't gonna automatically tell you the answer to your question, BUT if you search the question (print the function) it will tell you how many musicians there are in the orchestra Edit: Dont forget to add the '()' since, we would just be saying the name if we didnt extra: you can set a variable to a return: [RETURN] local function plus(x, y) return x + y end local n = plus(2, 3) print(n) >> 5 ----------- [PRINT] local function plus(x, y) print(x + y) end local n = plus(2, 3) print(n) >> nil
@@smplxty this is the best explanation i've heard yet, thanks a lot! i was confused about returning but i understand that wayy better now and how it could be used. Thanks!
The keyword return can be used to take information from a function, and allow it to be used wherever the function was called originally. If your friend asked you for something in another room, you would go get it and bring it back. When a function is called, the script goes to the function, and then returns with a value.
This is what I understand from Returning; Returning: in a function thats a line of code that doesn't activate unless its equal to a variable example; local function bruh2() print("hi") return "lol hi" end bruh2() - wont show return but will show others like print local Hotdog = bruh2() - makes the call into a variable print(Hotdog) - then will show whatever in return
ok that helps it was what i was thinking it is and when i ask a server with good scripters none of them can explain it like normal humans without making it more confusing this is all i needed and i got it now
My own example of when to use a return is like local function question() -->asking a question print("Whats ur name?") return("Bob") -->what the respond is written end print(question) -->gonna print the question but not the respond/return local respond = question() print(respond)--> is only gonna print the 'return' command and so, the output is going to be: What's ur name (From the 'print(question)' Bob (From the 'print(respond)"
Your tutorials are amazing! Others are too fast-paced and have holes but yours are very helpful. I was confused at returning at first but after some practice I understood it. Thank you :)
I came back to this video after a long time to help viewers understand returning: a good example of returning is when you need to use two values, but each of them is in a different function, so for example I wanna make a script that calculates mass, the function will run, and when it ends it would need to do something with the information it calculated, it cant just print it, because then the player wont see it, so it returns the mass so then you can use it later in the script and put it in a gui or something
wait so if you wanted to use it later in the script do you put return 'function' after the part you want to return or the place you are putting the value?
@@moldybread2445 sorry if you still dont understand when we use local it means it can be accessed anywhere in the script but if we put that variable inside a function and remove the local it is only accessible to that function meaning if you try to call it outside the function or in another function it doesn’t work and instead it says nil and that means no value.So in the end what i'm trying to say is local means it’s accessible anywhere but if it doesn’t have a local it has to be in a function or dependent on something to work and it will only for the thing it’s dependent on nothing else.
i think this is what alon means (im also new sry if there are errors in code) local density = 0 local mass = 36 local volume = 42 local function density() density = mass / volume return density end local CowDensity = density() if CowDensity < 1 then print("Float") else print ("Sink") end
first playlist of tutorials that actually make sense, other ones are like "type local and this and that" expecting you already have knowledge on scripting. Thank you for taking the time to explain everything there is to know about scripting
i’m years late, but the straight definition is what helped me figure out returning. if you’re using your function many times throughout your script and need to do different things with the outputs, then returning is essential. what returning does is just in the name; it returns the output to the call, rather than doing anything with it by itself, which is very useful when you want to run different things through the function for different purposes (i.e. a rather convoluted rounding script)
@@Cosmicious let’s say you’re making a rounding function, and use it throughout your script for various purposes. your function would return the rounded value rather than do anything like printing it. later, if you wanted to print the rounded form of a value, you would call the function in place of the regular input for printing; it would look something like this. print(functionname(24.2)) in this case, you’re calling a function named functionname with an input of 24.2, and the function returns a value to where it’s called, in this case into a print command. the print command recieves the value from the function, and prints said value.
So for those who don't understand return it is basically the "result" of a function, the value it gives you after the machine elaborates the script inside. To understand it better, for example math.rad is a function, and it "returns" the rad of the number in input; it is basically an output. hope i helped u
so like replace hotdog with conversation and so it prints hi and the conversation equals hi because its part of a conversation you started so in return the other person is replying to you saying awesome. Is this a good definition of it?
If you are still confused about returning, So example this, a player touched a block and another block will turn off can collide and the transparency to 0, when you used return , after the player is done touching the block the return will terminate the function and returns to normal. When i mean by normal it resets to the very beginning, it resets to cancollide on and the transparency to 1, like reverting everything back like it used to be!
For those who still dont get returning: Lets say there is a function, "return()" This function returns 1 If you just call the function, nothing will happen. Its like if you just put "1" in your script. Nothing will happen. However, you can assign it to a variable, or print it. Therefore, "print(return())" is the same as "print(1)" (in this case) Basically, returning in a function makes the function a placeholder for what it returns. Also, I havent watched the whole video so I am not sure if it works like this in lua, but if you use the "return" statement in the middle of a function, the lines of code after it (in the function) will not run when you call the function. At least that is how it works in the other 4 programming languages I am familiar with. You may be wondering, "Why not just print the value?" This is because you may not want the value to be printed. Maybe you want it to be the amount of damage you take or something like that. You can use a variable for that. However, you dont want to write out the equation every time you use that value. True, you can just reuse the variable, but you might have to change the value. If you use a function, you can make it return the calculated value, and store that in a variable. This makes it much easier to work with the script. I hope this helped :) (I suck at teaching others so if this did not help then I understand why lol)
So what I understand from what returning is, I guess its basically when you want to use a return script in a function, you must assign a variable to the function that uses the return script. And then you must print out that variable to finally see the return script running. Kinda complicated in my opinion but that's probably because I'm just barely learning about this. Edit: I have a much better understanding of returning now.
so like replace hotdog with conversation and so it prints hi and the conversation equals hi because its part of a conversation you started so in return the other person is replying to you saying awesome. Is this a good definition about what its about?
ill be honest, you explain this much better than anyone else. ive watched 2 scripting playlists and i started this one and this is by far the best and also gives most information in little time
Return is used to store data that can be used later on if u want to do changes on the function u wrote. Remeber to make a variable for the function to make return work.
W video. You are an amazing teacher, you prob won't see this, I am a few years late to watching this video. But I can confidently say, that I understand everything you have discussed. Thank you :)
*What I understand from returning:* So there is a function called "hi". And you set a variable that is equal to "hi", which is the said function. So by printing out the variable that is equal to the function, you'll activate it (Since you printed out something that's equal to the function, could be considered as calling it and you know, it activates the function as we see).
HUGE tip for that actually helped me understand everything: at the end of each video, experiment with what you just learned. literally do anything it doesnt matter you just have to make stuff with what you learned to really get it in your head and actually learn it because knowledge is not everything, parctice is everything.
I know I am super late, but I am taking a course on scripting. The way I learned it was making the function like a math function. So --addnums is telling the system to add these two variables local function addnums(n1,n2) --You are telling the system to return this function return (n1,+n2) end --You are setting the answer to this function with the numbers in place of the variables local answer = addnums(1,2) --Finally, you print the answer print(answer) This should result to the answer being printed to 3. Another version of this same function is this --addnums is telling the system to add these two variables local function addnums(n1,n2) --You are telling the system to return this function, this time you break it down return n1..("+")..n2..("=")..(n1+n2) ------------------------------------------------------------------------------------------------| end | --You are setting the answer to this function with the numbers in place of the variables | local answer = addnums(1,2) | --Finally, you print the answer | print(answer) | | This result will yield this answer, 1+2=3. It will return whatever you have on that return line.------------------| My example should give you a good understanding because it is like a math function. You can make sense of this because it is simple arithmetic. When my teacher showed me this, I had and "aha" moment. If you want to try more math examples then just replace "addnums" with "subtractnums", "dividenums", "multiplynums". Make sure the symbols match up too, for the function. Hope this helped. :D
This is what I think return is: -Return won't be seen by players, unless we add it to a variable. 1 - local function hi() 2 - print(hi) 3 - return "Awesome" 4 - end 5 - hi() ---> it's only gonna print hi and return Awesome but we can't see it so we will make a variable to print Awesome 5 - local HotDog = hi() 6 - print(HotDog) -----> now it's gonna print Awesome because it knows what Awesome is due to the hi() function This is only my thinking and I can be wrong but if someone who knows what return is can they comment and tell me if I'm right or wrong? Thank you
I know I’m like 5 YEARS late but these are the BEST videos for learning lua and Roblox studio stuff I understand almost everything you say and your so simple and straight to the point this is very helpful 🌈
I see so many comments not explaining this right. So let me tell you so basically lets say you make a function that will spawn a part and after that function is finished you probably want to access the part later on to maybe change it's color or size. You can't just get the part from the function because its only defined inside that function, so what you can do is return your part after the function is finshed so you can access that part later on. so your varaible that you made for example devking made a varaible = to his function that varaible will now basically define as your part. keep in mind the function still runs even though its in a varaible
Also for anyone wondering the differnce between local function and regular function is that local function can only be accessed in that script (accessed as in like calling the function)
bro you are awesome. I am interested in coding languages for a year i guess and i never understood return. I understood it after i watched your video. Thank you so much!
Notes: The location of *”local”* matter Explanation: if local is not inside, let’s say, a function, then the whole scripts knows it. But if it’s inside a function, then the script doesn’t know it, but only the function does. But if you don’t use “local” it will just let the whole script know. (But will function slower) Creds to @Alon Gal for the following: A function will run, and when it ends it would need to do something with the information it calculated, so it returns the mass so then you can use it later in the script and put it in a gui or something Example: Function named Example has code in it At the end or somewhere it says “return *anything*” The function is now worth *anything*
Let's define local local literally is - belonging or relating to a particular area or neighborhood, typically exclusively so. an inhabitant of a particular area or neighborhood. so like we use it as in our vicinity, most nearest so lets use that to define local in scripting - whatever its in, like the script is the neighborhood, its only in that neighborhood so it only functions there, like when its in a function
For people that doesn't understand returning read this, If you place a function inside a variable the variable will be equal to the line of code you returned. here an example (More explaining at the bottom) local function test() return game.Workspace.Baseplate end local variable = test() variable.Transparency = 0.5 --Function name is equal to test. In the function we typed a line of code in this example game.Workspace.Baseplate we placed return before it. --outside of the variable we created a variable that's equal to the name of the function. Now the script will look inside our functions and will scan for the line of code we returned. now the variable wil ---be equal to that line we returned. so we now know the variable is equal to the returned line of code and that's variable = game.Workspace.Baseplate --This is the location of the Baseplate so if we now do variable.Transparency = 0.5 he will change the Transparency to 0.5 because he knows variable is equals to the returned line of code in the test ----function. --(Still don't understand ask your questions down here)
It has been months i stoped watching your tutorials but i'm back and later or sooner i heard that roblox studio uses programing language called "Lua" and i'm learning that language and your videos help me very much!
it is the 9th time (i counted) watching this and i still do not know what scoping is and why this tutorial came 15 tutorials before learning how to make a tool
If someone still doesn't understand what return does, here is a good explanation: return is like a way of giving back a result from a function. Think of it as a function being a machine that does some work. When you use return, you’re telling the machine what the final answer or result should be. Here’s a simple example: function addNumbers(a, b) return a + b end In this example, the addNumbers function takes two numbers, adds them together, and then returns the result. So, when you call addNumbers(3, 4), it will give back 7. In short, return is used to send a result back from a function to where it was called.
Just a quick tip for anyone that is reading this and doesn't understand what TheDevKing is doing. PRACTICE! Don't spend a couple of seconds on each task spend as long as it takes for you to understand this. I had to dedicate 15 minutes changing the place you put the local to understand this. Honestly, it just get's easier after time and once you understand you feel like you have climbed Mt Everest. (I haven't climbed Mt Everest)
I'm hoping this might help someone, after rewatching it means that basically, when you print Hotdog in this case, it's looking for the value of hi() since hi() is a variable and if you return "Awesome" in this case, "Awesome" then becomes the value meaning it prints "Awesome" I'm very sorry if this is wrong or doesn't help but I tried lol
wait, so basically a return lets your code run through then finished the value? For example. Let say you want to make sure your code works, add a return at the end so if it runs through the code and give the return your code works. Am i correct?
@@jacob2604 Are you an advanced scripter now that this post has been over a year? The reason I ask, is because I assume you followed the rest of these tutorials, and I want to know if they helped.
Learning c language in school really helps with understanding this, i can freely say its easier since u only have local instead of int double chat etc. and u dont need " ; " at the end almost every single line of code. Also nice tutorials man!
If you dont understand returning basically what it does it returnes the data or value of somthing So Local function hi() Print ("hi") --blah blah blah Return "awesome" End Local hotdog = hi () Print (hotdog) Basically when the game runs through the script it creats a function named hi and in the function it prints hi Then it goes through the return awesome command (we willl get to that in a sec), then it ends ths function and then it creates a variable named hotdog and hotdog is equal to the function named hi. Then it will print hotdogs but hotdogs is equal to the function hi so it will print the function and basically when it does that it will print "hi" because thats whats in the function and it will also print awesome because it is returning the value of it
Thanks for doing this scripting series its helping me alot learn about scripting. I havent been having any troubles thanks so much TheDevKing! Your the only one who explains in correct in a video for ne
example of return (put in a local script) local name = game.Players.LocalPlayer local function hi () print ("Hey Bill") return(name.Name) end hi() local response = "Hey..whats your name Joe? Oh ye I remember you from Jailbreak, Hey "..hi() print (response)
(I can be wrong) return for me is like used to gather information from the function or multiple functions EX: local function number1() local var = 5 local var2 = 25 return var + var2 end local function number2() local var = 10 return var end number1() number2() local numbercombination = number1() + number2() print(numbercombination) OUTPUT: 40 Script runs the 2 functions, but return gathers the variables ive set for return, i then use a "local numbercombination" variable to gather these values outside the function, and then i can use these values to do anything like lets say one function was used to calculate your total earnings, and the other function was used to calculate your losses, i can use the values gathered to print the total losses ive made, and so on. I mostly thought while reading the comments was just for debugging code, but i think it can be used like this to. anyways im just starting to learn roblox lua, since ive used visual scripting on another game engine like GDevelop ive got a some understanding on things, but not code related. But i hope this helps someone understand white i think Return function is.
example: (idk if this is correct) function blah() local a = 1 print(a) end function blahVersion2() print(a) end the first function will print a, but the second one doesnt know what a is. but in the first function if you put a = 1 instead of local a = 1 then the second function would know what a is too, and both functions would print 1
Hayden Boshoff I understand the script I don’t understand what you would use it for do you know a more realistic use of scope like in a real roblox game
could say that, or simply if you want the whole script to know a string/number you can type local a = 3 local function print(a) end this will print 2 because it is available to the entire script but if you put local function local a = 2 print(a) end then anything inside the local function has access to a if it makes sense
I think I understand returning, when you make the variable equal to the function, they can both communicate. So the function will have something to return the string to, so it will return the string "Awesome" to the variable, and then the variable can print it for the function.
dude I did not understand it at first, I had to repeat this part of the return and even stick the explanation to understand! but in the end I succeeded, thanks!
Basically, if you don't understand, returning is very helpful for storing data. It can also help in printing data out immediately. For example: local function firstGroup(sun, mercury, venus, earth, mars) - - creates a function and gives it parameters for later use return sun+mercury+venus+earth+mars - - Here we want to calculate the total weight of our given parameters and return them end returnFirstGroup = firstGroup(2000, 1, 1.6, 2.5, 2.4) - - Firstly, we give the parameters numbers each, e.g: (Weight of the Sun is 2000 units, while the weight of Mercury is 1 unit, etc...) Secondly, we calculate the total mass and store them into a variable for later use local function change(a) - - Let's say we calculated the weight wrongly and we are supposed to divide the total mass by 2. We can create a function to change the weight. We also give another parameter for our new function that will be used for diving the total mass. return returnFirstGroup / a end finalMass = change(2) - - We then divide the mass by 2 and store it as a variable. print(finalMass) - - Finally, we print the new mass. Fun fact: You can also shorten the last 2 lines of code by printing our function, for example: finalMass = change(2) print(finalMass) => print(change(2)) Hope it helps! 😊 (even though I'm 2 years late lol)
does he still answer questions in these? so local restricts the variable/function for use within the script or code its placed in right, so does the a=2 variable without local, can other scripts access that since its not local within the script.. 2nd question is on the example with hi and awesome, 6:15, why was hi still printed even tho the hi function wasn't called, all he did was set the function as a variable and print the variable so the print("hi") within the function should not have executed without being called right ?
In the way I understood it clearly: the return statement does indicate that the function has completed its task, its primary purpose is to provide a mechanism for passing results back to the caller and controlling the flow of the function execution.
for those who did't understand. when you use the varible that was = to the function. if you then do something like this: local function hi( ) print("hi") return "awsome" end local hi_function = hi( ) print(hi_function) hi_function would be = to the returned value. which in this case was "awsome". so when i printed hi_function it printed awsome cuse thats the return
Yes it does! and for printing it will work just fine. But I was just using printing as an example. I guess printing was kind of a bad example but Returning is useful when you need values from functions. Just think of it like that. It doesn't always have to be printed.
returning is useful for lets say.. math. local function Double(numbertodouble) return numbertodouble *2 end --i want to double 2, lets run it through the function! local numberiwanttodouble = 2 local answer = Double(numberiwanttodouble) print(answer)
correct me if im wrong but i think return is to make yourself aware that the output of the function is from a variable. if you run the function regularly, the Awesome wont show so you know its being run regularly. if you run the function through the variable, the Awesome will show so you know its being run through a variable. say you got an apple from your front door but you want to know who its from. there are two apple givers and you told the company that gives apples to attach an extra letter to the apple if it is from apple giver B.
so local in a function when you were explaining is basically like one town knows about this thing and the other does not but when you remove local its not just it that town anymore its not local anymore so the other functions or towns know about it. you made it very easy to understand tysm
So the return basically transforms your function a value that your function will become if it becomes a variable. eg; local function lol() print("hi") return "hi" end Then you have to make the function a variable by; local trump = lol() then if you print the variable print(trump) It would give value you assigned to return.
Returning is basically clearing the whole function and only left (return) a variable. SO run all of the code I have in the function, and when it's done. return "DONE" and forget all of the values we've calculated /printed anything: *local function example ()* *--blah blah* *--blah blah* *return "DONE"* *Local Helper = example ()* *print (Helper)* It's gonna print "DONE" because thats the only thing that was left in the function after it got cleared out. and then we made the *local Helper* be equal to the string "DONE"
@@Marciunus16 So it basically deletes everything else that's in a function...? I don't know why I'd want to do that. I know there's probably some niche it fulfills but I have zero idea on what that would be since all of the tutorials I've been viewing for the past 2 years only consist of people messing around with simple variables and print statements instead of showing ways you can REALISTICALLY use them in the studio's 3D environment.
@@SuperBenBoy5886Clear/delete is not the same. Every time a function is 'activated' it can learn new things again by reading lines, But using return we can remember and use a specific value IN EVERYWHERE IN OUR CODE. For example: Local function Calculate () Local a = 4 Local b = 5 Local x = a*b Return x End Local helper = Calculate () Print helper What will be the output of helper? 20 because the function calculates and return x once it's completes. A and b are cleared no longer store memory of our pc and x = 20 value is saved because of return. Hope you understand tell me if I made any errors😅
@@Marciunus16 so the "a" and "b" values no longer exist? I think I understand how it works, but my problem still stands in that I don't know how to utilize this in Roblox's 3d environment.
@@SuperBenBoy5886 Exactly they don't exist until the line of code is read again. These small numbers are not even close to take up lots of storage but when you are making a big game (outside roblox) functions matter as the basics. It's not that hard to use. I'm not even good at programmig yet I use functions all the time. It just stores our code and we can recall it again anytime.
i need to watch all parts Beacuse started Making horror and I think ,"I have idea Lets make powerbox will turning off, on lights next think: No beacuse I don't know how to script I now Learned some script 😀^o^
This is still useful in 2023. I currently am a developer for tons of other syntaxes, so things made more sense to me, but still, this tutorial series is very helpful
Clarification for scope, if local is in an indent or something like that it shows only for that but if it is not indent or in indent it will show to everyone.
I was so confused with that part, why the second function suddenly know what "a" equal to after he delete the local part, my dumb ass thought it know what a=2 is because the second function memorize it from previous run Turns out it know a=2 because its not local anymore
Hey guys! Be sure to join the discord server if you have any questions or if you would like to meet me! discord.gg/FKcSyRh
pls help i still dont understand
GetNightcored idk yet to lol
@GetNightcored exactly lol i m waitnig for that explanation
@GetNightcored nvm he explains but still idk why u should do it outside of function
@GetNightcored We use local as it is more efficient then a=2 because a=2 is a global variable and sometimes lua gets confused and doesnt use count the variable as a variable due to it being global so using local is much better
A good definition on returning would be a gamepass. If someone buys your gamepass, you want to make sure that they are getting something in return for buying that gamepass. So for example. You make a gamepass that gives a player maybe extra speed, then once they purchase that gamepass, they will receive it. This is also useful in GUI shops and stuff as well.
@@xeistan7793 You okay? I wrote this comment 2 weeks ago and had the wrong idea of returning. Your comment isn't really an insult, more just trying to look for an argument.
@@robloxtutorials9187 So that definition you said is not correct? I am confused.
Lol
@@xeistan7793 chill...
@Xeisn Why do you think he or she is watching these tutorials?
For anyone confused about scope here is an analogy:
There are two students named Ave(test 1) and Eve(test 2)
Ave has 4 pencils
Eve has 2 pencils
Ave has a pencil named "A"
While Eve dosen't have any pencils named A
When the teacher said "raise your pencils named A" (Calling the code)
Only Ave can raise her hand (successful output)
While Eve dosen't raise her hand (Nil)
10 months later I finally understand returning so let me make an analogy for you:
Code:
Local Function HowManyMusicians ()
Return("40 - 100")
end
Print(HowManyMusicians())
Analogy:
Let's say you're surfing Google and you want to search how many musicians there are in the orchestra, just opening Google ( calling the function ) isn't gonna automatically tell you the answer to your question, BUT if you search the question (print the function) it will tell you how many musicians there are in the orchestra
Edit: Dont forget to add the '()' since, we would just be saying the name if we didnt
extra:
you can set a variable to a return:
[RETURN]
local function plus(x, y)
return x + y
end
local n = plus(2, 3)
print(n)
>> 5
-----------
[PRINT]
local function plus(x, y)
print(x + y)
end
local n = plus(2, 3)
print(n)
>> nil
even though you commented this 10 months ago, thank you
@@lolh9295 lol saw this notif, learned returning a couple months ago but forgot to place a analogy so here it is + you're welcome :D
@@smplxty this is the best explanation i've heard yet, thanks a lot! i was confused about returning but i understand that wayy better now and how it could be used. Thanks!
@@lolh9295 You're welcome!
@@smplxty i folllwed that returning script and it prints function: 0x8f004ccc88a0cdb0 - server - script:5
The keyword return can be used to take information from a function, and allow it to be used wherever the function was called originally. If your friend asked you for something in another room, you would go get it and bring it back. When a function is called, the script goes to the function, and then returns with a value.
wow, tysm great summary!
@@reeceh_27 no man
@@reeceh_27 no problem**
THANK YOU!
Tysm for the example now i understand!
This is what I understand from Returning;
Returning: in a function thats a line of code that doesn't activate unless its equal to a variable
example;
local function bruh2()
print("hi")
return "lol hi"
end
bruh2() - wont show return but will show others like print
local Hotdog = bruh2() - makes the call into a variable
print(Hotdog) - then will show whatever in return
so a function must be inside a variable to activate all returns?
RETRO STUDIOS yeah
ok that helps it was what i was thinking it is and when i ask a server with good scripters none of them can explain it like normal humans without making it more confusing this is all i needed and i got it now
bruh that was good BRUH!! xD
Its helpful for remote functions when you need either a true or false value. It's pretty basic in concept but advanced in use
My own example of when to use a return is like
local function question() -->asking a question
print("Whats ur name?")
return("Bob") -->what the respond is written
end
print(question) -->gonna print the question but not the respond/return
local respond = question()
print(respond)--> is only gonna print the 'return' command
and so, the output is going to be:
What's ur name (From the 'print(question)'
Bob (From the 'print(respond)"
Thank you so much for the explanation! It really helped me with the return
Ah makes sense
The script exuctes by lines so the function goes first before the local so it prints gain
@gangss just put question() at the bottom to call the function and then you will get ("whats ur name")
@@jordankidd230 I tried it, he’s right
Now I get the whole vid from watching it again, ty so much. XD
Ya me too but I still don't quite understand return. Like do you need to have a variable to call the function with the return or what?
I love ur profile picture
7 is cool
Lol script
@Union Centauri mlm me nerd
Your tutorials are amazing! Others are too fast-paced and have holes but yours are very helpful. I was confused at returning at first but after some practice I understood it. Thank you :)
So tru
I came back to this video after a long time to help viewers understand returning: a good example of returning is when you need to use two values, but each of them is in a different function, so for example I wanna make a script that calculates mass, the function will run, and when it ends it would need to do something with the information it calculated, it cant just print it, because then the player wont see it, so it returns the mass so then you can use it later in the script and put it in a gui or something
wait so if you wanted to use it later in the script do you put return 'function' after the part you want to return or the place you are putting the value?
hi i was a bit confused of what scope does. could u define it a bit.. thank you!
@@moldybread2445 sorry if you still dont understand
when we use local it means it can be accessed anywhere in the script but if we put that variable inside a function and remove the local it is only accessible to that function meaning if you try to call it outside the function or in another function it doesn’t work and instead it says nil and that means no value.So in the end what i'm trying to say is local means it’s accessible anywhere but if it doesn’t have a local it has to be in a function or dependent on something to work and it will only for the thing it’s dependent on nothing else.
i think this is what alon means (im also new sry if there are errors in code)
local density = 0
local mass = 36
local volume = 42
local function density()
density = mass / volume
return density
end
local CowDensity = density()
if CowDensity < 1 then
print("Float")
else
print ("Sink")
end
OooOOoOoOoH That makes sense
first playlist of tutorials that actually make sense, other ones are like "type local and this and that" expecting you already have knowledge on scripting. Thank you for taking the time to explain everything there is to know about scripting
On_Edge for real
i’m years late, but the straight definition is what helped me figure out returning.
if you’re using your function many times throughout your script and need to do different things with the outputs, then returning is essential.
what returning does is just in the name; it returns the output to the call, rather than doing anything with it by itself, which is very useful when you want to run different things through the function for different purposes (i.e. a rather convoluted rounding script)
ty
I think I got you but could you give an example?
@@Cosmicious let’s say you’re making a rounding function, and use it throughout your script for various purposes.
your function would return the rounded value rather than do anything like printing it. later, if you wanted to print the rounded form of a value, you would call the function in place of the regular input for printing; it would look something like this.
print(functionname(24.2))
in this case, you’re calling a function named functionname with an input of 24.2, and the function returns a value to where it’s called, in this case into a print command. the print command recieves the value from the function, and prints said value.
this is not straight i am confused
@@eeeEEEeeeEEEEEE-eeeeeee you can call a function as an argument in another statement, and the value the function returns will be used.
So for those who don't understand return it is basically the "result" of a function, the value it gives you after the machine elaborates the script inside.
To understand it better, for example math.rad is a function, and it "returns" the rad of the number in input; it is basically an output.
hope i helped u
so like replace hotdog with conversation and so it prints hi and the conversation equals hi because its part of a conversation you started so in return the other person is replying to you saying awesome. Is this a good definition of it?
@mikela5025 ye i think so
I’m gonna watch this playlist 3 times so I fully understand
I was gonna do that same!
Lol relatable
This is my fourth time XD
@@cha0ticClipzz did u also do the advanced playlist one cause that one is very important as well
me: 4
If you are still confused about returning,
So example this, a player touched a block and another block will turn off can collide and the transparency to 0, when you used return , after the player is done touching the block the return will terminate the function and returns to normal. When i mean by normal it resets to the very beginning, it resets to cancollide on and the transparency to 1, like reverting everything back like it used to be!
oh okay, thanks btw
i still dont understand whats the point of returning- is this true?
omfg tysm
Thank you sir
so it means it will repeat the function ?
4:20
Don't mind this, it's just a timestamp for me to remember when the returning starts
(Also 420 lol)
Thankyou I think we all needed to see that twice lol
tyty
we cant understand it cuz the return code is outdated
420 lol
@@HarryDKH well I fixed it I am on the advanced.seriris thanks for trying to help me
For those who still dont get returning:
Lets say there is a function, "return()"
This function returns 1
If you just call the function, nothing will happen.
Its like if you just put "1" in your script.
Nothing will happen.
However, you can assign it to a variable, or print it.
Therefore, "print(return())" is the same as "print(1)" (in this case)
Basically, returning in a function makes the function a placeholder for what it returns.
Also, I havent watched the whole video so I am not sure if it works like this in lua, but if you use the "return" statement in the middle of a function, the lines of code after it (in the function) will not run when you call the function. At least that is how it works in the other 4 programming languages I am familiar with.
You may be wondering, "Why not just print the value?"
This is because you may not want the value to be printed. Maybe you want it to be the amount of damage you take or something like that.
You can use a variable for that. However, you dont want to write out the equation every time you use that value. True, you can just reuse the variable, but you might have to change the value.
If you use a function, you can make it return the calculated value, and store that in a variable.
This makes it much easier to work with the script.
I hope this helped :)
(I suck at teaching others so if this did not help then I understand why lol)
This is the only comment I understood, thanks!
I still struggled understanding until you explained about the damage, thanks!
:)
O thanks, u made me understand returning better!
I’ll be honest I still don’t understand
can you give a shorter example?
So what I understand from what returning is, I guess its basically when you want to use a return script in a function, you must assign a variable to the function that uses the return script. And then you must print out that variable to finally see the return script running. Kinda complicated in my opinion but that's probably because I'm just barely learning about this.
Edit: I have a much better understanding of returning now.
so like replace hotdog with conversation and so it prints hi and the conversation equals hi because its part of a conversation you started so in return the other person is replying to you saying awesome. Is this a good definition about what its about?
So If I get this right returning is used to make something equal something else but only if conditions are met first unlike variables?
@@cyro5535 thanks I get it now
ill be honest, you explain this much better than anyone else. ive watched 2 scripting playlists and i started this one and this is by far the best and also gives most information in little time
I watched this like 8 times and I finally understand it!!
You make it so simple thats why you are my favorite roblox Scripting RUclipsr
Return is used to store data that can be used later on if u want to do changes on the function u wrote. Remeber to make a variable for the function to make return work.
i understand now tysm daddy
@@Flamecasts ayo
@@godrole2481 oya
This dude learned me more than those 1 hour long vids. Thank you so much!
4:20 gotta *return* to this a few times... *laugh track plays*
Edit: only just now came back to this lmao, and this joke is just 👁👄👁
@Antoine Goulet jojo fan lmao
@Antoine Goulet I thought I was gonna get RickRolled
Ohhh LOL
👁👄👁
@Antoine Goulet d
you saying you struggled with returns and me getting a good grasp on it, either you're an amazing teacher or this is my calling xD
Oh my god it is freaking tricky, I literally sat down for 30 minutes alone just to figure it out hahahaa thanks bro
W video. You are an amazing teacher, you prob won't see this, I am a few years late to watching this video. But I can confidently say, that I understand everything you have discussed. Thank you :)
*What I understand from returning:*
So there is a function called "hi". And you set a variable that is equal to "hi", which is the said function. So by printing out the variable that is equal to the function, you'll activate it (Since you printed out something that's equal to the function, could be considered as calling it and you know, it activates the function as we see).
HUGE tip for that actually helped me understand everything: at the end of each video, experiment with what you just learned. literally do anything it doesnt matter you just have to make stuff with what you learned to really get it in your head and actually learn it because knowledge is not everything, parctice is everything.
I know I am super late, but I am taking a course on scripting. The way I learned it was making the function like a math function. So
--addnums is telling the system to add these two variables
local function addnums(n1,n2)
--You are telling the system to return this function
return (n1,+n2)
end
--You are setting the answer to this function with the numbers in place of the variables
local answer = addnums(1,2)
--Finally, you print the answer
print(answer)
This should result to the answer being printed to 3. Another version of this same function is this
--addnums is telling the system to add these two variables
local function addnums(n1,n2)
--You are telling the system to return this function, this time you break it down
return n1..("+")..n2..("=")..(n1+n2) ------------------------------------------------------------------------------------------------|
end |
--You are setting the answer to this function with the numbers in place of the variables |
local answer = addnums(1,2) |
--Finally, you print the answer |
print(answer) |
|
This result will yield this answer, 1+2=3. It will return whatever you have on that return line.------------------|
My example should give you a good understanding because it is like a math function. You can make sense of this because it is simple arithmetic. When my teacher showed me this, I had and "aha" moment.
If you want to try more math examples then just replace "addnums" with "subtractnums", "dividenums", "multiplynums". Make sure the symbols match up too, for the function.
Hope this helped. :D
Thanks! it helped!
@@lucky_zak2426 Glad I could help!
@@BwithTea hi can I tell you what I did understand from return.. I want to make sure I understand it right
This is what I think return is:
-Return won't be seen by players, unless we add it to a variable.
1 - local function hi()
2 - print(hi)
3 - return "Awesome"
4 - end
5 - hi() ---> it's only gonna print hi and return Awesome but we can't see it so we will make a variable to print Awesome
5 - local HotDog = hi()
6 - print(HotDog) -----> now it's gonna print Awesome because it knows what Awesome is due to the hi() function
This is only my thinking and I can be wrong but if someone who knows what return is can they comment and tell me if I'm right or wrong?
Thank you
thank you
@@kasatero no problem
yeah that’s what I got from this video too
i have been struggling to understand returning for a long time but when i watched your video i finally understood the concept. thank you so much!
this is the best video that explains returning imo.. every other tutorial was rather difficult
#Question if I don't use the return keyword will the function not be able to go inside a variable?
Yo Idk you were coding back in the day💀
LOL
Blud gave up tryna learn to code and went to play blox fruits instead
ggs on you
´´
I know I’m like 5 YEARS late but these are the BEST videos for learning lua and Roblox studio stuff I understand almost everything you say and your so simple and straight to the point this is very helpful 🌈
fr
I see so many comments not explaining this right. So let me tell you so basically lets say you make a function that will spawn a part and after that function is finished you probably want to access the part later on to maybe change it's color or size. You can't just get the part from the function because its only defined inside that function, so what you can do is return your part after the function is finshed so you can access that part later on. so your varaible that you made for example devking made a varaible = to his function that varaible will now basically define as your part. keep in mind the function still runs even though its in a varaible
OMGGGG THX
Omg this is the best playlist i have ever looked at!Your just the right guy for these kind of things.Thanks so much!!!
Also for anyone wondering the differnce between local function and regular function is that local function can only be accessed in that script (accessed as in like calling the function)
What's the difference between a variable and a function?
Btw so if i do a function(not a local function) i can call that function in another script such as a serverside script?
Ty
bro you are awesome. I am interested in coding languages for a year i guess and i never understood return. I understood it after i watched your video. Thank you so much!
Notes:
The location of *”local”* matter
Explanation: if local is not inside, let’s say, a function, then the whole scripts knows it.
But if it’s inside a function, then the script doesn’t know it, but only the function does.
But if you don’t use “local” it will just let the whole script know. (But will function slower)
Creds to @Alon Gal for the following:
A function will run, and when it
ends it would need to do something with
the information it calculated, so it returns the mass so then you can
use it later in the script and put it in a gui
or something
Example:
Function named Example has code in it
At the end or somewhere it says “return *anything*”
The function is now worth *anything*
Let's define local
local literally is - belonging or relating to a particular area or neighborhood, typically exclusively so.
an inhabitant of a particular area or neighborhood. so like we use it as in our vicinity, most nearest
so lets use that to define local in scripting - whatever its in, like the script is the neighborhood, its only in that neighborhood so it only functions there, like when its in a function
For people that doesn't understand returning read this,
If you place a function inside a variable the variable will be equal to the line of code you returned.
here an example (More explaining at the bottom)
local function test()
return game.Workspace.Baseplate
end
local variable = test()
variable.Transparency = 0.5
--Function name is equal to test. In the function we typed a line of code in this example game.Workspace.Baseplate
we placed return before it.
--outside of the variable we created a variable that's equal to the name of the function. Now the script will look inside our functions and will scan for the line of code we returned. now the variable wil ---be equal to that line we returned. so we now know the variable is equal to the returned line of code and that's variable = game.Workspace.Baseplate
--This is the location of the Baseplate so if we now do variable.Transparency = 0.5 he will change the Transparency to 0.5 because he knows variable is equals to the returned line of code in the test ----function.
--(Still don't understand ask your questions down here)
you made this so much easier to understand thx
@@nateguop thx 😊
Here's an example of what return could be useful for:
function something(a, b)
return (a+b), (a-b), (a*b), (a/b)
end
c, d, e, f = something(6, 3)
print(c)
print(d)
print(e)
print(f)
It has been months i stoped watching your tutorials but i'm back and later or sooner i heard that roblox studio uses programing language called "Lua" and i'm learning that language and your videos help me very much!
what I heard devking say: it has o start with scope. me: puts scope on my sniper ah yes I knew this would come in handy.
Sure did
hahaha comedy
I dont remember typing this lol (this is my alt)
you explained returning like a boss appreciate you, im starting my journey as a solo dev
Tutorial 1-3:
Me: Haha that's easy.
Tutorial 6+: SIKE
Me: MY BRAIN
i feel so dumb because everyone can understand this and this is my 3rd time watching and it’s still hard for me
@@ehtz You'll understand it someday, keep up the work
it is the 9th time (i counted) watching this and i still do not know what scoping is and why this tutorial came 15 tutorials before learning how to make a tool
@@ehtz I can tell you are hard working, you might wanna skip this one until U learn the basics then come back to this
I’m watching this as an experienced developer (who forgot lua) and I would recommend this series to anyone who wants to learn scripting in roblox
Me:*understand what returns are but couldn't explain it to someone if they asked*
@gangss 6:18
DUDE I HAVE BEEN TRYING TO LEARN SCRIPTING FOR SOO LONG U HAVE NO IDEA TYSM
4:36, no it won't because it is not in quotation marks to make it a string!
ya it would just print something like 'function 0x33addf3000a"
@@jassskmaster7575 same
Hi is a variable so it doesn't need quotation marks
Man got his own script wrong
It's hard to understand the thing for a moment but as soon you explain more and more it gets More understanding
3:32 how come when dev king takes out the local it starts working for both blocks of code?
Because thats how it works
If someone still doesn't understand what return does, here is a good explanation:
return is like a way of giving back a result from a function. Think of it as a function being a machine that does some work. When you use return, you’re telling the machine what the final answer or result should be.
Here’s a simple example:
function addNumbers(a, b)
return a + b
end
In this example, the addNumbers function takes two numbers, adds them together, and then returns the result. So, when you call addNumbers(3, 4), it will give back 7.
In short, return is used to send a result back from a function to where it was called.
Just a quick tip for anyone that is reading this and doesn't understand what TheDevKing is doing. PRACTICE!
Don't spend a couple of seconds on each task spend as long as it takes for you to understand this. I had to dedicate 15 minutes changing the place you put the local to understand this. Honestly, it just get's easier after time and once you understand you feel like you have climbed Mt Everest.
(I haven't climbed Mt Everest)
@Yuvi5000 cool, teach me?? ;)
This dude is explaining things in minutes but other RUclipsrs are taking an hour just to explain one line of code this dude explains the whole script
Can you give us a example? Like u r gonna build something and u have to use the returning
Do you have a discord server or something for this so its easier to ask questions and stuff?
I'm hoping this might help someone, after rewatching it means that basically, when you print Hotdog in this case, it's looking for the value of hi() since hi() is a variable and if you return "Awesome" in this case, "Awesome" then becomes the value meaning it prints "Awesome"
I'm very sorry if this is wrong or doesn't help but I tried lol
And that’s what we like trying
wait, so basically a return lets your code run through then finished the value?
For example.
Let say you want to make sure your code works, add a return at the end so if it runs through the code and give the return your code works.
Am i correct?
What the fuck are you talking about
@@zkn8665 why the fuck you respond 8 months later.
why the fuck didn't I understand
@@Batuh_n I have no fucking clue
@@jacob2604 Are you an advanced scripter now that this post has been over a year?
The reason I ask, is because I assume you followed the rest of these tutorials, and I want to know if they helped.
Learning c language in school really helps with understanding this, i can freely say its easier since u only have local instead of int double chat etc. and u dont need " ; " at the end almost every single line of code. Also nice tutorials man!
I have a really important question how to you make a script run from walking on a part
You'll need whatever_you_named_the_part.position = vector3(position)
You'll have also to call the humanoid
*workspace* .YOURPARTNAMEHERE.Touched:Connect( *function* ()
--_Your scripts here_
end
If you dont understand returning basically what it does it returnes the data or value of somthing
So
Local function hi()
Print ("hi")
--blah blah blah
Return "awesome"
End
Local hotdog = hi ()
Print (hotdog)
Basically when the game runs through the script it creats a function named hi and in the function it prints hi
Then it goes through the return awesome command (we willl get to that in a sec), then it ends ths function and then it creates a variable named hotdog and hotdog is equal to the function named hi. Then it will print hotdogs but hotdogs is equal to the function hi so it will print the function and basically when it does that it will print "hi" because thats whats in the function and it will also print awesome because it is returning the value of it
who is looking at this in 2024
👇
Thanks for doing this scripting series its helping me alot learn about scripting. I havent been having any troubles thanks so much TheDevKing! Your the only one who explains in correct in a video for ne
example of return (put in a local script)
local name = game.Players.LocalPlayer
local function hi ()
print ("Hey Bill")
return(name.Name)
end
hi()
local response = "Hey..whats your name Joe? Oh ye I remember you from Jailbreak, Hey "..hi()
print (response)
yeah I think you just made it more complicated
(I can be wrong) return for me is like used to gather information from the function or multiple functions
EX:
local function number1()
local var = 5
local var2 = 25
return var + var2
end
local function number2()
local var = 10
return var
end
number1()
number2()
local numbercombination = number1() + number2()
print(numbercombination)
OUTPUT: 40
Script runs the 2 functions, but return gathers the variables ive set for return, i then use a "local numbercombination" variable to gather these values outside the function, and then i can use these values to do anything like lets say one function was used to calculate your total earnings, and the other function was used to calculate your losses, i can use the values gathered to print the total losses ive made, and so on. I mostly thought while reading the comments was just for debugging code, but i think it can be used like this to. anyways im just starting to learn roblox lua, since ive used visual scripting on another game engine like GDevelop ive got a some understanding on things, but not code related. But i hope this helps someone understand white i think Return function is.
Can someone give me a good example of scope because I don’t understand what it does but I did understand the code part of it
example: (idk if this is correct)
function blah()
local a = 1
print(a)
end
function blahVersion2()
print(a)
end
the first function will print a, but the second one doesnt know what a is. but in the first function if you put a = 1 instead of local a = 1 then the second function would know what a is too, and both functions would print 1
Hayden Boshoff I understand the script I don’t understand what you would use it for do you know a more realistic use of scope like in a real roblox game
@@xxrice_pickerxx2720you can do this with other stuff I think not just printing
I think it if you want 1 answer in a function I’m still super confused
@@xxrice_pickerxx2720can you tell me now bc I’m 11 and just starting coding and Mabye u know now I’m still stuck on everything
ngl i learned a lot from each and every video
cant wait to see what happens next
parameters
So is local just used when you want to save an action in a function and Scope just used to save it throughout the whole script?
could say that, or simply if you want the whole script to know a string/number you can type
local a = 3
local function
print(a)
end
this will print 2 because it is available to the entire script but if you put
local function
local a = 2
print(a)
end
then anything inside the local function has access to a if it makes sense
Basically a shortcut like u can make on ur phone where u could type idk and it auto corrects to I don’t know
I think I understand returning, when you make the variable equal to the function, they can both communicate. So the function will have something to return the string to, so it will return the string "Awesome" to the variable, and then the variable can print it for the function.
local gametime% () 10:23
idk about this but does this work?
No replays in 1 year omg u got would record bud
@@curuptedv.256 lmao what a fucking loser amirite
@@TheDrghu ikr
dude I did not understand it at first, I had to repeat this part of the return and even stick the explanation to understand! but in the end I succeeded, thanks!
This is so difficult to pick up lol
so basically a return will not activate unless the function its under equals something else
@@Zenith_Nulls thx
omg ty so much i have been on a problem script for making a game this is so much betteer than every tutorial and its short
who us here in 2024
Me
Me
Me
Like If u agree
Just kidding
I have been struggling with Returning but now that I have seen this I do understand them now
Wow, this is actually similar to python.
Yeah, I've been noticing that too. I have some knowledge of Python so I was able to catch onto this very quickly.
Basically, if you don't understand, returning is very helpful for storing data. It can also help in printing data out immediately. For example:
local function firstGroup(sun, mercury, venus, earth, mars) - - creates a function and gives it parameters for later use
return sun+mercury+venus+earth+mars - - Here we want to calculate the total weight of our given parameters and return them
end
returnFirstGroup = firstGroup(2000, 1, 1.6, 2.5, 2.4) - - Firstly, we give the parameters numbers each, e.g: (Weight of the Sun is 2000 units, while the weight of Mercury is 1 unit, etc...) Secondly, we calculate the total mass and store them into a variable for later use
local function change(a) - - Let's say we calculated the weight wrongly and we are supposed to divide the total mass by 2. We can create a function to change the weight. We also give another parameter for our new function that will be used for diving the total mass.
return returnFirstGroup / a
end
finalMass = change(2) - - We then divide the mass by 2 and store it as a variable.
print(finalMass) - - Finally, we print the new mass.
Fun fact: You can also shorten the last 2 lines of code by printing our function, for example:
finalMass = change(2)
print(finalMass)
=>
print(change(2))
Hope it helps! 😊 (even though I'm 2 years late lol)
So, when you return "Awesome", you basicly replace the script with "Awesome" ?
From what i understand, Functions can be used normally if they called by their normal name, when returning, it does whats written in return
does he still answer questions in these? so local restricts the variable/function for use within the script or code its placed in right, so does the a=2 variable without local, can other scripts access that since its not local within the script..
2nd question is on the example with hi and awesome, 6:15, why was hi still printed even tho the hi function wasn't called, all he did was set the function as a variable and print the variable so the print("hi") within the function should not have executed without being called right ?
But if u use this while instancing can u do
Return chickennuggets
And it would return the part as the name chicken nuggets?
In the way I understood it clearly: the return statement does indicate that the function has completed its task, its primary purpose is to provide a mechanism for passing results back to the caller and controlling the flow of the function execution.
I feel like the more videos I get into the more quiet his voice is..
ikr
lol
for those who did't understand. when you use the varible that was = to the function. if you then do something like this:
local function hi( )
print("hi")
return "awsome"
end
local hi_function = hi( )
print(hi_function)
hi_function would be = to the returned value. which in this case was "awsome". so when i printed hi_function it printed awsome cuse thats the return
wait why cant i just use this code
local function hi()
print("hi")
print("awesome")
end
hi()
doesn't it do the same thing and shorter code??
Yes it does! and for printing it will work just fine. But I was just using printing as an example. I guess printing was kind of a bad example but Returning is useful when you need values from functions. Just think of it like that. It doesn't always have to be printed.
ooh ty!
returning is useful for lets say.. math.
local function Double(numbertodouble)
return numbertodouble *2
end
--i want to double 2, lets run it through the function!
local numberiwanttodouble = 2
local answer = Double(numberiwanttodouble)
print(answer)
I tested it, it works and print's all variables. Since hi was identified the local function was to run both prints meaning both were printed.
thank you so much!!!! maybe 5 years later but im alwawys so happy when i understand something
this is how many people watching are kids
1
@@hahayes5280 yeah
Lil bro
@@hahayes52809 now
Howdy
correct me if im wrong but i think return is to make yourself aware that the output of the function is from a variable.
if you run the function regularly, the Awesome wont show so you know its being run regularly.
if you run the function through the variable, the Awesome will show so you know its being run through a variable.
say you got an apple from your front door but you want to know who its from. there are two apple givers and you told the company that gives apples to attach an extra letter to the apple if it is from apple giver B.
If you don't put "local", does the function apply to all of the scripts or just the script that you put the function in?
Thanks!
All of the scripts.
so local in a function when you were explaining is basically like one town knows about this thing and the other does not but when you remove local its not just it that town anymore its not local anymore so the other functions or towns know about it. you made it very easy to understand tysm
Test2: what the heck is a
me: you just said what that has, an A in it.
*sarcasm and yes my English is bad*
wat
wht
Suppose to be a joke?
Lol
wdym I don’t unserstand
So the return basically transforms your function a value that your function will become if it becomes a variable.
eg;
local function lol()
print("hi")
return "hi"
end
Then you have to make the function a variable by;
local trump = lol()
then if you print the variable
print(trump)
It would give value you assigned to return.
I still can't understand returning, even after looking at the comments and rewatching this 😞
Returning is basically clearing the whole function and only left (return) a variable.
SO run all of the code I have in the function, and when it's done. return "DONE" and forget all of the values we've calculated /printed anything:
*local function example ()*
*--blah blah*
*--blah blah*
*return "DONE"*
*Local Helper = example ()*
*print (Helper)*
It's gonna print "DONE" because thats the only thing that was left in the function after it got cleared out. and then we made the *local Helper* be equal to the string "DONE"
@@Marciunus16 So it basically deletes everything else that's in a function...? I don't know why I'd want to do that. I know there's probably some niche it fulfills but I have zero idea on what that would be since all of the tutorials I've been viewing for the past 2 years only consist of people messing around with simple variables and print statements instead of showing ways you can REALISTICALLY use them in the studio's 3D environment.
@@SuperBenBoy5886Clear/delete is not the same. Every time a function is 'activated' it can learn new things again by reading lines,
But using return we can remember and use a specific value IN EVERYWHERE IN OUR CODE.
For example:
Local function Calculate ()
Local a = 4
Local b = 5
Local x = a*b
Return x
End
Local helper = Calculate ()
Print helper
What will be the output of helper?
20 because the function calculates and return x once it's completes. A and b are cleared no longer store memory of our pc and x = 20 value is saved because of return. Hope you understand tell me if I made any errors😅
@@Marciunus16 so the "a" and "b" values no longer exist? I think I understand how it works, but my problem still stands in that I don't know how to utilize this in Roblox's 3d environment.
@@SuperBenBoy5886 Exactly they don't exist until the line of code is read again. These small numbers are not even close to take up lots of storage but when you are making a big game (outside roblox) functions matter as the basics.
It's not that hard to use.
I'm not even good at programmig yet I use functions all the time.
It just stores our code and we can recall it again anytime.
i attempted to learn vscript before this and it gave some nice base knowledge of return and other things
Guys, what is the use of scope in scripting?
Niceeee when i was watching alvinblox returning video, i was like wtf im confused but when i watch your vid, i instantly know everything wow ty
i need to watch all parts Beacuse started Making horror and I think ,"I have idea Lets make powerbox will turning off, on lights next think: No beacuse I don't know how to script I now Learned some script 😀^o^
This is still useful in 2023. I currently am a developer for tons of other syntaxes, so things made more sense to me, but still, this tutorial series is very helpful
whats your user on mineland
2:03
This guy calls himself an idiot
Lmao
I needed more help for scripting i will watch ALL of your scripting tutorials for now
Clarification for scope, if local is in an indent or something like that it shows only for that but if it is not indent or in indent it will show to everyone.
I was so confused with that part, why the second function suddenly know what "a" equal to after he delete the local part, my dumb ass thought it know what a=2 is because the second function memorize it from previous run
Turns out it know a=2 because its not local anymore