#Can someone explain me the OR operator and the difference between local and not local variables?
250 messages · Page 1 of 1 (latest)
im following this btw, if u know a better way tell me pls xd
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
** You are now Level 1! **
yeah i dont understand it
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'
how come it be?
uhh
first of all
instance_1,instance_2 =
Instance.new('BasePart',workspace),Instance.new('BasePart',workspace)
what exactly u cannot understand in this line?
im going to say what i understand that, instance_1 is a new basepart in workspace right?
discord ruins lol
yup
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
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
and instance_2's new name will be visible to everyone on the server, basically
if you execute this
it wont make a part or will it
ya
it will
it will make 2 separate parts with different names
ah god i have to go
sry
the thing you did here how is it named
okay no problem
the name (variables etc) thats what i mean
the code
ok
uh
u cannot understand variables?
** You are now Level 3! **
is a variable
is this a variable as well or what
you can write it in a different way
i just like to do it like that
you might do it like that tho:
instance_1 = Instance.new('BasePart',workspace)
instance_2 = Instance.new('BasePart',workspace)
ohh
this is very incorrect!
** You are now Level 2! **
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
i made it simple, bezje terminov
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
hm right
a mistake
@frigid oriole
not the name
i should have made it a property like transparency or smth
nope
from my experience it works with other properties like color, transparency
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
used no know what they do yes
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!
roblox even warns not to use globals
-- 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
I'm still right in a specific way. Guess my style doesn't fit
and I can use x inside the do
do
local x = 10
end
x = 20 --> This will error!
x is nil and undefined
the global scope is
is the global scope
no it won't
do is an inner scope
it will just not work as expected
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
that would be the do scope
not the global scope
Uh
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)
again, it's literally the reach/area a variab, constant, function will be recognized as whatever you declared it
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
just replace scope with visibility and it's explained
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
yeah that works! Visible is a good word to use, even though it's tenically reach
now this is were it gets fuzzy, because hahaha...
why do you put do and end there tho
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
no i dont mean that
If so,
local x
do
x = 10
end
local y = x
print (y)
Tell meeee
i mean why dont you just put ```
local x = 10
local y = x
print(y)
please use a code block 😅
because then you don't deal with scopes 🙂
I'm on mobile
your question was related to scopes
here everything is visible and readily available to use
because there's just one scope, the global one
will this work tho
will it print 10
it will
this wont
okay
OHHHHHH
Yah
i understand this now
👍
but i still dont understand what part of this is the scope 😅
okay, let me use comments
Never heard anyone say scope ngl
me too
-- 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)
The best I can explain it, which "CluelessDev" may be able to better explain it, is that the scope is an area of code. For example
if x do --start of scope
print(x)
end --end of scope
ye
The scipt within itself is also a scope
correct was literally goona do that hahahaha, you read my mind 😆
correct, the global scope
okay now i get it
cause everything declared there is visible for sub-scopes
mhm
because that's something you just learn and then just naturally understand, if that makes sense?
if x do --start of scope 1
print(x)
end --end of scope 1
if x do --start of scope 2
print(x)
end --end of scope 2
``` but this is correct as well tho?
No cuz you're the first to say scope
cause that's the term, scope
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.
scope is the area of reach/visiblity of an item(functions, constants, variables)
^^
using global variables is not needed tho right?
never
yeah
not gonna explain this
but when you use global variables
do
x = 10
end
y = x
print(y) --> 10
does work
Knew it without any scopes, where did u even get that anyways?
simply because you did not used local
alright tysm
the variable became global
i gtg now tho
alright
college
and again
that's the literal term
Godspeed.
what is a scope programming
^
google that
Wdym
It is an expression of wishing good luck to one starting a journey.
👍
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?
** You are now Level 4! **
@copper pollen
the latter is a global function
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
I've honestly never really seen a function done like myFunction = function() before
then
local function MyFunction()
print("Hello World!")
end
MyFunction()
?
yeah I do that
lol
yes, perfect
i know that its a local function
unnecessarily anonymous
also what exactly is this
meh, I like it
that's wayyyy advanced
like don't worry about that
at all
how do i get to it when i need it tho
you're like 1-2 months away from giving that a use
don't worry, you'll know by then
lol
more like a year at this pace
^
wana hear something fun? That was literally me, I did not actually understood that until about a year in
i use studio since 2018 but i was stupid and always used free models and open sourced scripts
he has no concept of self
everything can be done without it anyway
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
Don't think I've really used self in my entire time of programming
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.