#Can someone explain me the OR operator and the difference between local and not local variables?

250 messages · Page 1 of 1 (latest)

frigid oriole
#

title says it all

#

im following this btw, if u know a better way tell me pls xd

deft trellis
#
local name_1 = 'i am visible to a specific client who executed this script'
name_2 = 'i am visible to everyone'

instance_1,instance_2 = Instance.new('BasePart',workspace),Instance.new('BasePart',workspace)

instance_1.Name = name_1
instance_2.Name = name_2
#

instance_1's new name will be visible to a specific user who executed dat

#

instance-2's new name will be visible to everyone no matter who is the executor

tall jacinthBOT
#

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

frigid oriole
#

yeah i dont understand it

deft trellis
#
randomNum = math.random(1,3)

msg_1 = 'hello'
msg_2 = 'goodbye'
if randomNum == 1 or randomNum == 2 then
   print(msg_1)
else
   print(msg_2)
end

if the random number will happen to be 1 or 2, it will print out 'hello'
else = 'goodbye'

deft trellis
frigid oriole
#

uhh

#

first of all

#
instance_1,instance_2 = 
Instance.new('BasePart',workspace),Instance.new('BasePart',workspace)
deft trellis
#

what exactly u cannot understand in this line?

frigid oriole
#

im going to say what i understand that, instance_1 is a new basepart in workspace right?

deft trellis
#

discord ruins lol

deft trellis
#

instance_2 is the same

#

but if you execute that code somewhere (from server) - instance_1's new name will be visible only to you

frigid oriole
#

the name of the instance_1 will be visible to a specific user who executed the script but instance_2 will be visible no matter who is the executor

deft trellis
#

and instance_2's new name will be visible to everyone on the server, basically

frigid oriole
#

OHHH

#

i understand it now, but when they execute what? because as far i understand

frigid oriole
#

it wont make a part or will it

deft trellis
#

ya

#

it will

#

it will make 2 separate parts with different names

#

ah god i have to go

#

sry

frigid oriole
frigid oriole
frigid oriole
deft trellis
frigid oriole
#

ok

deft trellis
#

u cannot understand variables?

frigid oriole
#

no thats not my point

#
local etst = 2
tall jacinthBOT
#

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

frigid oriole
deft trellis
#

ya that is right

#

it is

frigid oriole
deft trellis
#

you can write it in a different way

deft trellis
#

you might do it like that tho:

instance_1 = Instance.new('BasePart',workspace)
instance_2 = Instance.new('BasePart',workspace)
frigid oriole
#

ohh

deft trellis
#

what exactly?

#

it works exactly how it does

tall jacinthBOT
#

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

pure bloom
#
x = 10
local y = 20

in the global scope of the script are pretty much the same thing, aside from the goody of being foward delcared

#
do 
  x = 10
end

x = 20

is where the difference lies

deft trellis
#

i made it simple, bezje terminov

pure bloom
#

a simply incorrect way

#
local name_1 = 'i am visible to a specific client who executed this script'
name_2 = 'i am visible to everyone'

these are effectively the same 🙂

#

in visibility

deft trellis
#

hm right

#

a mistake

#

@frigid oriole
not the name

#

i should have made it a property like transparency or smth

pure bloom
#

@frigid oriole ever heard of scope?

#

any idea what that is?

frigid oriole
#

nope

deft trellis
#

from my experience it works with other properties like color, transparency

pure bloom
#

okay, scope is literally what is sounds like

#

the "reach"

#

so let's do a simple excersice

#

ever used if statements

#

or any statement like while loops

#

repeat loops

#

maybe for loop

frigid oriole
#

used no know what they do yes

pure bloom
#

hmmmm, okay then in this case

#

do not sweat it

#

understand how to use statements first, at the very least if statements

#

and then come back to this question

#

in the meant time

#

use local for all variables

#

but as a mini explanation, again it's the reach of the variable!

toxic ocean
#

roblox even warns not to use globals

pure bloom
#
-- this is the global scope of the script
local x = 10

do 
  x = 10
end

see the do statement, it will open a scope

#

thing of scope like chests

#

they can grab anything from outside the chest

#

but what's outside cannot grab what's inside

#

in fact it's like a black hole 😂

#

now look at this @frigid oriole notice I decared X in the global scope

deft trellis
#

I'm still right in a specific way. Guess my style doesn't fit

pure bloom
#

and I can use x inside the do

#
do 
  local x = 10
end
x = 20 --> This will error!
#

x is nil and undefined

frigid oriole
pure bloom
#

the script

#

literally the script

#

in blank

frigid oriole
#
do
x = 20
end
#

?

pure bloom
#

is the global scope

pure bloom
#

do is an inner scope

toxic ocean
#

it will just not work as expected

pure bloom
#

in vanilla lua I'm 90% sure it would so I operate under that, in a typed language it would so better get used to that reality

#

but yeah I guess you're right

pure bloom
#

not the global scope

deft trellis
#

Uh

frigid oriole
#

what

#

is a scope again?

deft trellis
#

Isn't it easier to explain in a simpler way is he is new to luau?

#

It is fine but since he is just starting (as we can see)

pure bloom
#

again a bit "ugh" if you don't know statements 😅

#

cause statements open scopes

#

hence why I said to maybe leave this question for later when you actually start dealing with scopes

#

but if anything do this excersice in luau

#

in a script in workpsace

toxic ocean
#

just replace scope with visibility and it's explained

pure bloom
#
do 
  local x = 10
end

local y = x
print(y) --> will print nil cause x is not visible in the global scope X it's inside the Do scope!

@frigid oriole

pure bloom
#

now this is were it gets fuzzy, because hahaha...

frigid oriole
pure bloom
#

to close the do statement

#

do it's a statement

#

like if

#

or while

#
if condition then
  -- code
end
#

closes the statement, and the scope

frigid oriole
#

no i dont mean that

deft trellis
#

Tell meeee

frigid oriole
#

i mean why dont you just put ```
local x = 10

local y = x
print(y)

pure bloom
#

please use a code block 😅

deft trellis
#

I came

#

Can't*

pure bloom
deft trellis
#

I'm on mobile

pure bloom
#

your question was related to scopes

pure bloom
#

because there's just one scope, the global one

frigid oriole
#

will it print 10

frigid oriole
#

okay

pure bloom
#

due to what I mentioned with scopes

#

x is not visible to y

frigid oriole
#

OHHHHHH

pure bloom
#

because it's inside the do statement scope

#

same goes for any statement

deft trellis
#

Yah

deft trellis
#

👍

frigid oriole
pure bloom
#
 
if true then
  local x = 10
end

local y = x
print(y) --> nil
#

same deal

pure bloom
deft trellis
frigid oriole
#

me too

pure bloom
#
-- this is an empty script
#
--this is the global scope of the script

local x = 10
local y = x
local z = 25

print(x, y, z)
copper pollen
frigid oriole
#

ye

copper pollen
pure bloom
pure bloom
pure bloom
#

cause everything declared there is visible for sub-scopes

copper pollen
#

mhm

pure bloom
frigid oriole
pure bloom
#

Spot on!

#

exactly

deft trellis
pure bloom
#

cause that's the term, scope

copper pollen
# copper pollen mhm

Also, not sure if CluelessDev done explained this, but it's probably best if you get in to the habit of using local variables more unless you plan to use it out of scope.

pure bloom
#

scope is the area of reach/visiblity of an item(functions, constants, variables)

frigid oriole
#

using global variables is not needed tho right?

pure bloom
#

yeah

#

not gonna explain this

#

but when you use global variables

#
do
  x = 10
end
y = x
print(y) --> 10
#

does work

deft trellis
#

Knew it without any scopes, where did u even get that anyways?

pure bloom
#

simply because you did not used local

frigid oriole
#

alright tysm

pure bloom
#

the variable became global

frigid oriole
#

i gtg now tho

pure bloom
#

alright

pure bloom
#

and again

#

that's the literal term

copper pollen
pure bloom
deft trellis
#

Nah

#

I don't use 'scope'

#

Just code.

frigid oriole
copper pollen
frigid oriole
#

👍

frigid oriole
#
local MyFunction = function()
    print("Hello World!")
end

MyFunction()

is the same with

function MyFunction()
    print("Hello World!")
end

MyFunction()

right?

#

sorry for ping @pure bloom

#

also what should i do local function... or just function?

tall jacinthBOT
#

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

frigid oriole
#

@copper pollen

pure bloom
#

which again, like a global variable gives you the benefit of foward declaration

#

those you do use but not in this context

#

i.e you would not use that in a script.

#

for example

#

but that's advanced

#

andale, but still you would not declared it like that

#

you would index it to the module table

#

so slight diff thre

copper pollen
frigid oriole
frigid oriole
#

i know that its a local function

frigid oriole
#

also what exactly is this

pure bloom
#

meh, I like it

pure bloom
#

like don't worry about that

#

at all

frigid oriole
pure bloom
#

you're like 1-2 months away from giving that a use

pure bloom
#

lol

toxic ocean
#

more like a year at this pace

pure bloom
#

^

pure bloom
frigid oriole
#

i use studio since 2018 but i was stupid and always used free models and open sourced scripts

pure bloom
#

he has no concept of self

toxic ocean
#

everything can be done without it anyway

pure bloom
#

I no longer use self either

#

unless I'm coding like a back-end service

#

which is rare now-adays

#

Yeah, I just use it as a short hand

#

cause passing the service as a parameter is gey

#

imagine having to do this ```lua
MyService.SomeMethod(MyService)

#

ew

#

yeah! and internal registries

#

yeah quite a bit

copper pollen
#

Don't think I've really used self in my entire time of programming

toxic ocean
#

it's important for oop

copper pollen
# toxic ocean it's important for oop

Yeah no I don't think I've done a whole lot of OOP. I've used Python a lot more, and don't really use functions a lot other for whenever I am going to end up with code that's recursive.