#can someone explain this because how in the initialization of "acc" its equal "acc or 1"

1 messages · Page 1 of 1 (latest)

silk abyss
#

(yes i know im not supposed to just send a screenshot like that im sorry)

    acc = acc or 1
    if n == 0 then
        return acc
    else
        return factorial(n-1, n*acc)
    end
end
print(factorial(5))

https://youtu.be/n07w-eabLMw?si=1wV5Va807LNb8-MZ&t=2216 code is from this vid at 36:54

Get The Roblox Scripting Fastlane (Paperback & Hardcover) [Free Sample on Amazon] → https://www.amazon.com/Roblox-Scripting-Fastlane-Coach/dp/B0F2J65QCW/

Discord Community: https://discord.gg/rqe6jEHHwR

0:00 | Intro
1:20 | Your First Script
1:50 | Comments
2:58 | Blocks
3:35 | Variable Identifiers
4:08 | Keywords
4:47 | Global Variables vs L...

▶ Play video
#

if possible can someone explain how it works

silk abyss
#

also this 😔 (how is there 3 values i only know 2, first is index 2nd is value but third??

noble wolf
#

@silk abyss

#

You can use a more complicated method to set variables based on certain conditions

silk abyss
#

a

noble wolf
#

In this script, he says

acc = acc or 1

which means if acc doesn’t have a value and is nil, acc becomes 1

silk abyss
#

OHH

#

wow thank you

noble wolf
#

There’s a similar one

#

It’s not in the example you sent but you can also use “and” in this context

#

acc = boolean and 1

#

If the boolean is true then acc becomes 1, otherwise it skips this line

#

Does anything else in the script confuse you?

silk abyss
#

acc isnt a factorial though ( i think i jus started learning lua yesterday)

#

i meant

#

boolean

noble wolf
#

factorial is the name of the function they are calling

silk abyss
#

yes osrry

#

i meant boolean

noble wolf
#

it’s just another way you can set a variable

silk abyss
silk abyss
noble wolf
#

it shouldn’t crash

silk abyss
#

it did 💔

#

wait ill reopen and try again

noble wolf
#

oh here

silk abyss
#

ok it worked this time but

#

why did it output "key"

noble wolf
#

because you printed the index and not v

silk abyss
#

so 1 2 3 AND key are all indexes

noble wolf
#

well no and yes

silk abyss
#

with "value" as their value

uncut pumiceBOT
#

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

noble wolf
#

no

silk abyss
noble wolf
#

let me show you an example

silk abyss
#

😔

noble wolf
#

you can make your table

silk abyss
#

yes please

noble wolf
#

table = {2,9,1, something = “yes”}

#

the value of index 1 is 2 since it appears first

#

the value of index 2 is 9

#

and the value of index 3 is 1

silk abyss
#

okk

#

wha tbaout "something" and "yes"

noble wolf
#

the index of something just something and its value is yes

uncut pumiceBOT
#

studio** You are now Level 15! **studio

noble wolf
#

i don’t think it has a number but i could be wrong

#

but if you do
print(table.something) you’ll get “yes”

silk abyss
#

so something is an index with location or place in table of "something"

noble wolf
#

yes

silk abyss
#

bro

#

your explanation is genuinely so good i have no idea how you dont have a special role or something

#

im fr

#

thank you so much man

noble wolf
#

thank you

silk abyss
#

is it okay if i add you to ask questions 😋

noble wolf
#

yeah

silk abyss
#

yay

silk abyss
#

how does

#

when it returns factorial(n-1,n*acc) where does it go to

#

or like

#

how does this part do

#

like i know it does 5x4x3x2x1

#

but how

noble wolf
#

the function itself can be an output so in this when you print factorial, it prints the product of the function since the product is what is returned

silk abyss
#

ohh