#What is return and when should i use them

1 messages · Page 1 of 1 (latest)

nocturne elm
#

i just cannot understand very well how return works, even after watching tutorials.

#

like what is return for in these parts? Wouldn’t the script work even without them?

#

thats a simple assign plot on player join system btw

opal oar
#

to return a value from function

#

it is used to get a value from the function

nocturne elm
#

and why does he return nil

mild flint
#

theres no reason to do that

mild flint
#

;compile

local function foo()
  return 1
end

local var = foo()
print(var)
keen iglooBOT
#
Program Output
1

nocturne elm
#

what can this be useful for?

#

like in the script i’ve sent

mild flint
#

lots and lots of things

nocturne elm
#

so i can exercise

bright dirge
#

In few places in code

#

So you just make function that does that

#

And returns the part

#

Or u wanna format numbers to say 100k, 1m, not 100000 or 1000000

#

U just have function that does that and returns formatted

nocturne elm
#

from what i understood

bright dirge
#

Let me check your code

nocturne elm
#

but

#

even in that script i wanted to understand what return does there

#

so i can understand it

mild flint
nocturne elm
mild flint
#

it returns the plot owners

#

here it takes in a plot, and returns that player's plot by looping through all of the plots until it hits a plot with the owner being that player

#

and if it doesn't find it, it returns nil

#

but thats completely useless since that would happen anyway

nocturne elm
#

alright i kinda get it now

#

so by returning the plot

#

the plot will be = to player if i want to use it later in the script

mild flint
#

what

nocturne elm
#

i mean

#

i can do this without returning

mild flint
#

how can you do that

nocturne elm
#

wait

#

i understood what return does now

#

but by returning plot there

#

what i am achiewving

mild flint
#

you get the plot

#

in a script you can use PlotService:GetPlot() to get a plot

nocturne elm
#

mhh okay

#

thanks

#

i get it now still a bit confused but i kinda understand it now

#

ill exercise

mild flint
#

it's about abstraction

#

you make some code, and then you can reuse it later

#

and you don't have to know what the function does inside

#

you can just get the plot using PlotService:GetPlot