#who can help me to understand what is **return** in coding, thanks

1 messages · Page 1 of 1 (latest)

upper canyon
#
local function hello ()
    print(`hi`)
    return `awesome`
end

local hotdog = hello()
print(hotdog)```
tight rapidsBOT
#

studio** You are now Level 1! **studio

upper canyon
#

hello guys and i need help

#

i need to understand what is return meaning in scripting

#

im watching theDevKing tutorials and i dont understand function repeat

hot ravine
#

hi

#

return basically ends the code and anything next to it will run whenever it ends

upper canyon
#

ahhh

#

maybe i get it

#

@hot ravine

#

if my code looks like this

local function hello ()
    print(`hi`)
    return `awesome`
end

local hotdog = hello()
print(hotdog)```
#

why i need to write at the end local hotdog = hello()

hot ravine
#

wha

upper canyon
#

why i cant just write hello()

#

instead of local hotdog = hello()

hot ravine
#

what

upper canyon
#
local function hello ()
    print(`hi`)
    return `awesome`
end

local hotdog = hello()
print(hotdog)```
#

whis is what i wrote

hot ravine
#

what about it

upper canyon
#
local function hello ()
    print(`hi`)
    return `awesome`
end

hello()```
hot ravine
#

ok

upper canyon
#

why cant i just write this

hot ravine
#

uh

#

what

upper canyon
#

do you good at script?

hot ravine
#

yes

upper canyon
#

so look

#

when my code looks like this

#

it prints hi and awesome

#

but why it doesnt write awesome

tight rapidsBOT
#

studio** You are now Level 2! **studio

hot ravine
#

ok

#

i explained it wrong

#

let me reexplain

upper canyon
#

do you understand what i mean?

hot ravine
#
local function getNumber()
  local number = math.random(10)
  return number
end

print(getNumber())
#

returning awesome basically sets the value of the function to 'awesome'

#

ig

worldly reefBOT
#
Program Output
8

hot ravine
#

see

#

it sets the functions value to the random number

upper canyon
#

yee

hot ravine
#

thats the explanation

upper canyon
#

but

#

why we cant jusy

#

wait i will recode it

#

oh wait

#

im more confuesd

#

confused

hot ravine
#

what

upper canyon
#

so wait what is return doing

#

how it works

hot ravine
#

😭

round talon
#

and stops code from running

hot ravine
#

it can either restart the code OR set value of smt

#

depending how you use it

#

thats the simplest explanation i can give

#

🙏

upper canyon
#

im so dump i cant understand it like second day

round talon
upper canyon
#

thats hardest one i think

#

yes

round talon
#

u execute a function and it runs it right?

#

by execute i mean call or whatever u name it

upper canyon
#

ok

round talon
#

ye so

hot ravine
#

and returning

round talon
#

do u know how functions work?

hot ravine
#

returns a value

round talon
#

like how to call it

upper canyon
#

local function?

round talon
#

do you know how to call a function?

#

like make it execute code inside it

upper canyon
#

aaahh

#

yes

round talon
#

so you do ffunctionname()

#

ok so

upper canyon
#

local function sss()

end

sss()

round talon
#

yea yea

upper canyon
#

im know base i have learned it last week

#

and now im learning what i dont understand

round talon
#

return inside function, will stop the code (the function) running, and return a specific value (defined by you, or nil)

#

if you do

#

local test = sss()

#

and the sss function has a return

#

the test will be set to whatever the return returns

upper canyon
#

oh wait wait wai maybe i get it little

#

tell me more about it

round talon
#

if u have a function

local function sss()
print("HI")
return true
print("HI AGAIN")
end

and do

local test = sss()

the function will normally be executed, but test will be set to true (as there is return true)

#

and u will only see "HI" not "HI AGAIN" as return STOPS rest of code from working (inside the function)

upper canyon
hot ravine
#

nice one @round talon

round talon
hot ravine
#

it wont work bc you put print after return

#

and return stops the function

#

😭

round talon
#

thought it woulld still work just not show

#

mb

round talon
#

but work tho

upper canyon
#

im still confused

#

did i that dunp?

#

dump

hot ravine
#

what

round talon
#

wanted to show, that it wont work but its erroring

upper canyon
hot ravine
#

yes!

upper canyon
#

Hi

#

it prints hi

hot ravine
#

bc youre calling the function

round talon
#

and test is being set to true

hot ravine
#

and not printing the function

#

yhes

#

wkizi youre so smart

round talon
#

i gave bad ish example

#

shut the fuck up

hot ravine
round talon
upper canyon
#

im trying to understand

#

and when

#

why it prints

#

Hi

#

true

round talon
#

bc

#

like i said

#

doing local test = sss()

#

will execute the sss function

#

and set the variable test to whatever it returns, in this case it returns true

hot ravine
#

😭

#

what if

#

while false do

#

🙏

upper canyon
#

oh fuck

#

i tried

#

to do

round talon
#

bro is breaking the universe

upper canyon
#

but i still dont understand btw

round talon
#

ye so no dont do that

round talon
hot ravine
#

@loud hamlet

round talon
#

what do u not understand

#

-_-

hot ravine
#

js send the damn message

#

😭

round talon
upper canyon
#

who is this guy

loud hamlet
#
local function sss()
   local Number = math.random(1,10)

  return Number
end

local test = sss()

print(test)

Try this

upper canyon
#

prodev2015?

loud hamlet
hot ravine
#

😭

loud hamlet
hot ravine
#

and its the same example as wkizi's showing

loud hamlet
hot ravine
#

CONFUSEDKID

upper canyon
#

🖕

round talon
#

@upper canyon what do u not understand

#

once again

hot ravine
#

returning in a function sets the value of the function to whatever you return

upper canyon
#

i dont understand what i dont understand

hot ravine
#

WHAt do you not FUCKING FUNDERSATND

upper canyon
#

but i dont understand something

hot ravine
#

what is it

round talon
hot ravine
#

what do you understand

loud hamlet
#

I cant with this thread

hot ravine
round talon
#

how did we take 179 (now 180) messages to explain what return is

#

and fail

#

😭

hot ravine
#

bc this kid is sped

upper canyon
#

okay so

#

wait

loud hamlet
#

just read the creator documentation page at this point

#

if there even is one

hot ravine
#

last time

upper canyon
#

i tried to find it

tight rapidsBOT
#

studio** You are now Level 3! **studio

upper canyon
#

eee lvl 3😎

hot ravine
#

a return sets the value of a function to whatever

#

😭

loud hamlet
#

Also they said they'd give me Scripter 1 but they just closed my ticket and didnt give me scripter 1

round talon
# upper canyon okay so

if u do
local test = sss()

what will happend is

  1. sss function will be EXECUTED
  2. test will be set to WHATEVER the function returns (example. if function has return true, test will be set to true)
hot ravine
#

how does your s1 app get denied

loud hamlet
#

They literally said that I was elligible for it

hot ravine
#

then why dont you have it

#

!?

round talon
#

s1 will get u bullied more then s0

#

ngl

loud hamlet
upper canyon
#

so

#
local function sss()
    local Number = math.random(1,10)

    return Number
end

local test = sss()

print(test)```
round talon
upper canyon
#

why we need to write at the end

local test = sss()

print(test)```
hot ravine
#

YOU IDIOT

autumn hedge
#

lmao wtf

hot ravine
#

😭

round talon
hot ravine
#

widawwy

round talon
#

@hot ravine i think u need to take catnip i mean sealnip

#

or whatever its called

#

frfr

hot ravine
loud hamlet
#

Yall this has been going on for so long I forgot what return does

autumn hedge
#

what the fuck is a "coding"????

#

my brain???? what???

round talon
hot ravine
#

im genuinely losing braincells from ts

upper canyon
#

oh

#

wait!!

#

wait!!!

round talon
#

did he get it

#

omg

upper canyon
#

i still dont get it

round talon
#

nvm

upper canyon
#

nah do you really think i get it

round talon
loud hamlet
upper canyon
#

okay wait

#

when we do a game

#

for what we use return

round talon
#

to see if something was sucess for example

upper canyon
#

can you write example

round talon
round talon
#

no

loud hamlet
#

Is this kid trolling

round talon
#

the random number example was fine

#

it could be used

upper canyon
#

nah im not trolling

#

maybe its more confused for me because i speak other language

round talon
#

u speak english

#

u can

upper canyon
#

wait stop confusing me

round talon
#

understand it

autumn hedge
#

what language DO you speak

round talon
#

!!!! we spent over 250 messages explaining what return does!

hot ravine
#
local function returnValue (value)
  print('hello')

  value = math.random(10)
  return value
end

print(returnValue()) -- printing this will print the value of the value variable we made within the function.
returnValue() -- running the function will print hello and and not print the value made within the function cause were not printing the function.
round talon
#

can we get it to sub 300?!

hot ravine
#

peep ts

loud hamlet
worldly reefBOT
#
Program Output
function: 0x55a46eab3df0
hello

hot ravine
#

oops

round talon
#

OK

round talon
#

HERE IT IS

worldly reefBOT
#
Program Output
function: 0x5641cd564df0
hello

upper canyon
hot ravine
#

eh what ever

round talon
#

i mean function

hot ravine
#

i forgot ()

worldly reefBOT
#
Critical error:

You are sending requests too fast!

worldly reefBOT
#
Critical error:

You are sending requests too fast!

#
Program Output
hello
4
hello

upper canyon
#

guys

#

my dog is dying

round talon
#

so are our brains

#

talking in this

loud hamlet
tight rapidsBOT
#

studio** You are now Level 5! **studio

hot ravine
#

read this

#

now

upper canyon
upper canyon
round talon
upper canyon
#

okay okay sorry

#

im reading

round talon
#

the arm looks uhh

#

like u are not old enough to leggaly use discord

upper canyon
round talon
#

u either lying or that arm aint yours (on pic)

upper canyon
round talon
hot ravine
#

thats not him

#

😭

#

itsa girl not a guy

upper canyon
#

its a girl

hot ravine
#

yea

loud hamlet
hot ravine
#

the arm is a girls arm

#

not his arm

upper canyon
#

its my sister

round talon
#

how dare u

round talon
hot ravine
#

dumbas

round talon
#

thought it was yours

hot ravine
#

dumbass

upper canyon
#

shut up

hexed knot
#

What is going on here

upper canyon
#

and lets talk about repeat

upper canyon
#

okay

round talon
hot ravine
round talon
#

(we going for sub 500 messages)

hot ravine
#

yes

round talon
hot ravine
#

when

round talon
#

and u were printing function

#

not function()

loud hamlet
round talon
hot ravine
#

i swear if blud still doesnt understand it

upper canyon
#

wait please

#

i understand it a bit after u tell me

round talon
#

uga booga, uga booga, @upper canyon , return is like your cat coming back with mouse in its teeth
the mouse is the returned thing

and in code , u set what the return should be

upper canyon
#

now all i need

#

to know it surely

#

wait

loud hamlet
upper canyon
#

no

hot ravine
#

bro

#

what do you NOT UNDERSTAND

hexed knot
#
function add(num1, num2)
return (num1 + num2)
end
local result = add(1, 2)
print(result) -- 3
loud hamlet
upper canyon
loud hamlet
upper canyon
round talon
#

‼️ ‼️ WE PASSED 350 MESSAGES EXPLAINING RETURN! ‼️ ‼️

upper canyon
worldly reefBOT
#
Program Output
3

hexed knot
#

I'm stupid

upper canyon
tight rapidsBOT
#

studio** You are now Level 4! **studio

hexed knot
#

But yeah that's basically that

round talon
loud hamlet
#

yuh

#

@upper canyon

#

Please

#

just

#

understand

#

It isnt that hard

round talon
#
function catgo()
local mouse = "mouse that was running a minute ago"
return mouse
end

local hello = catgo()
print(hello)
loud hamlet
#

It really isnt

#

At this point just give up on your scripting career

round talon
loud hamlet
#

Give up on game development

upper canyon
#

will not

hot ravine
#

CONFUSED KID

#

HOLY FUCK

#

PLEASE

#

UNDERSTAND TS

#

I CANT

#

😭

upper canyon
#

wait wait

#

will understand

loud hamlet
#

How can you be this confused

hexed knot
#

I'm giving up, I'm putting @upper canyon for adoption

hexed knot
loud hamlet
#

Im putting him down

#

Some random guy just DMed me asking me to play his shitty roblox game

hallow orchid
upper canyon
#

?

hot ravine
#

no

tranquil kite
#

ngl I am no scripter, but even I don't know what return does

hot ravine
#

bro

round talon
worldly reefBOT
#
Program Output
mouse that was running a minute ago

round talon
#

see

hot ravine
loud hamlet
#

Yall he's starting to understand

upper canyon
hot ravine
#

hold

loud hamlet
#

Also we passed 400 messages

willow glade
#

omg are u still confused?

hot ravine
#
local function test()
  print("Hi")
  return true
end

print(test())
test()
upper canyon
#

not that much yet

#

wait look

hot ravine
round talon
# upper canyon wait there is no diff ?

well, diffrence in output between

local test = catgo()
print(test)

and just print(catgo())

Is none, its same

but in first example u just have a variable set to it

upper canyon
#

its not diff?

#

there is no diff yes?

#

i need to know it

#

tell me

loud hamlet
#

@upper canyon You're the reason theres a "Do not drink" label on bleach

upper canyon
#

yes or

hexed knot
# tranquil kite ngl I am no scripter, but even I don't know what return does

In LuaU, return is a special word used in functions. When a function finishes its job, it can use return to send back a result. For example, if you have a function that adds two numbers, using return lets you get the answer back so you can use it later. This helps keep things organized and makes it easier to do more with your code! So, whenever you see a return, think of it as a way for the function to say, "Here’s what I found!".

round talon
# upper canyon its not diff?

if u print the catgo()

vs
if you set variable test to catgo()
and print test

There is NO diffrence IN OUTPUT
but in 2nd example, you have a variable set to that, where in first u dont have a variable

hexed knot
upper canyon
#

i fucking get it

round talon
#

LETS GOOOOOO

loud hamlet
#

FINALLY

round talon
#

@hot ravine WE DID IT

hot ravine
#

YES

hexed knot
#

👏👏👏👏👏👏👏👏👏👏

hot ravine
#

time to leave this dumbass thread

loud hamlet
#

It only took yall 425 messages to do it

round talon
#

it took ONLY 425 MESSAGES

#

!!!!!!

upper canyon
#

but what is

for i,v do```
#

nah im joking guys

round talon
#

nvm i quit

upper canyon
#

i will create other theme for it

round talon
upper canyon
#

so guys last one give me some tiny tasks that i can do with return

loud hamlet
#

No

#

Im leaving

upper canyon
#

🖕

loud hamlet
#

Dont talk to me ever again

upper canyon
#

@loud hamlet😏

red kite
upper canyon
#

thanks

#

finally i get it

red kite
#

👍

#

what

#

wait 😭

#

no that is not what return does

round talon
red kite
#

i think i confused u

hexed knot
#

It can also be used to stop a function from continuing by returning nothing, for example if it can't find the Player you can do: if not Player then return end

round talon
#

and like we said earier, return stops rest of code from running

#

so this will output nothing, and stop code from running

red kite
#

return, returns a value from a function for example

local function returnbanana()
 local banana = "banana"
  return banana

print(returnbanana())
round talon
#

reutrn

upper canyon
#

thanks

hexed knot
#

Np

red kite
hexed knot
#

Now get outta here

hexed knot
red kite
#

oke :p

tight rapidsBOT
#

studio** You are now Level 1! **studio

red kite
#

HOORAY

upper canyon
#

@round talon

#

am i cook?

round talon
#

interesting naming of function

#

but it should work

upper canyon
#

yes it isss

round talon
#

do u get it?

upper canyon
#

its cook

upper canyon
#

but i understand what it doing

round talon
#

and yes its 50/50

round talon
# upper canyon its cook

well no, your function name is not cook, i tried to say your function name and i got timedout for a minute (thats why i took a minute to respond)

upper canyon
#

aaaa

#

lol

round talon
#

the name of your function is uhhh ye

upper canyon
#

you mean?

round talon
#

how the hell did bro not get automodded

upper canyon
#

🤔

round talon
#

anyways u know what that means or no

upper canyon
#

yes

#

thanks

round talon
#

alr lol

#

so change the name