Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update variable names #971

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions content/en-us/luau/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ function Queue.new<T>(): Queue<T>
end

-- Check if the queue is empty
function Queue.IsEmpty<T>(self: Queue<T>)
function Queue.isEmpty<T>(self: Queue<T>)
return self._first > self._last
end

-- Add a value to the queue
function Queue.Enqueue<T>(self: Queue<T>, value: T)
function Queue.enqueue<T>(self: Queue<T>, value: T)
local last = self._last + 1
self._last = last
self._queue[last] = value
end

-- Remove a value from the queue
function Queue.Dequeue<T>(self: Queue<T>): T
if self:IsEmpty() then
function Queue.dequeue<T>(self: Queue<T>): T
if self:isEmpty() then
error("Cannot dequeue from empty queue")
end

Expand All @@ -96,27 +96,27 @@ local Queue = require(ReplicatedStorage:WaitForChild("Queue"))
local myQueue = Queue.new()

-- Add some values to the queue
myQueue:Enqueue(5)
myQueue:Enqueue(10)
myQueue:Enqueue(15)
myQueue:enqueue(5)
myQueue:enqueue(10)
myQueue:enqueue(15)

-- myQueue = { 5, 10, 15 }

-- Remove one value from the queue
local first = myQueue:Dequeue()
local first = myQueue:dequeue()
print("The first value added to the queue was", first)

-- myQueue = { 10, 15 }

-- Add more values to the queue
myQueue:Enqueue(20)
myQueue:Enqueue(25)
myQueue:Enqueue(30)
myQueue:enqueue(20)
myQueue:enqueue(25)
myQueue:enqueue(30)

-- myQueue = { 10, 15, 20, 25, 30 }

-- Remove another value from the queue
local second = myQueue:Dequeue()
local second = myQueue:dequeue()
print("The second value added to the queue was", second)

-- myQueue = { 15, 20, 25, 30 }
Expand Down
24 changes: 12 additions & 12 deletions content/en-us/luau/stacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ function Stack.new()
end

-- Check if the stack is empty
function Stack:IsEmpty()
function Stack:isEmpty()
return #self._stack == 0
end

-- Put a new value onto the stack
function Stack:Push(value)
function Stack:push(value)
table.insert(self._stack, value)
end

-- Take a value off the stack
function Stack:Pop()
if self:IsEmpty() then
function Stack:pop()
if self:isEmpty() then
return nil
end

Expand All @@ -57,21 +57,21 @@ local s = Stack.new()

-- Change the stack Resulting stack Output

s:Push(1) -- {1}
s:push(1) -- {1}

s:Push(5) -- {1, 5}
s:push(5) -- {1, 5}

s:Push(10) -- {1, 5, 10}
s:push(10) -- {1, 5, 10}

print(s:Pop()) -- {1, 5} 10
print(s:pop()) -- {1, 5} 10

print(s:Pop()) -- {1} 5
print(s:pop()) -- {1} 5

s:Push(20) -- {1, 20}
s:push(20) -- {1, 20}

print(s:Pop()) -- {1} 20
print(s:pop()) -- {1} 20

print(s:Pop()) -- {} 1
print(s:pop()) -- {} 1
```

<Alert severity="warning">
Expand Down
60 changes: 30 additions & 30 deletions content/en-us/luau/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ To create a dictionary table, define each **key** followed by `=` and the **valu

```lua
local testDictionary = {
FruitName = "Lemon",
FruitColor = "Yellow",
Sour = true
fruitName = "Lemon",
fruitColor = "Yellow",
sour = true
}
```

Expand All @@ -153,7 +153,7 @@ The keys for dictionaries can be numbers, strings, and objects. For example, a k
local part = Instance.new("Part")

local testDictionary = {
PartType = "Block",
partType = "Block",
[part] = true
}
```
Expand All @@ -166,11 +166,11 @@ To read from a dictionary, add a pair of brackets after its reference and specif
local part = Instance.new("Part")

local testDictionary = {
PartType = "Block",
partType = "Block",
[part] = true
}
-- Include quotes for string keys
print(testDictionary["PartType"]) -- Block
print(testDictionary["partType"]) -- Block
-- Omit quotes for non-string keys
print(testDictionary[part]) -- true
```
Expand All @@ -181,19 +181,19 @@ To define or rewrite the value of a new or existing dictionary key, declare the

```lua
local testDictionary = {
FruitName = "Lemon",
Sour = true
fruitName = "Lemon",
sour = true
}

-- Change value of existing keys
testDictionary["FruitName"] = "Cherry"
testDictionary["Sour"] = false
testDictionary["fruitName"] = "Cherry"
testDictionary["sour"] = false

-- Insert new key-value pair
testDictionary["FruitCount"] = 10

print(testDictionary["FruitName"]) -- Cherry
print(testDictionary["Sour"]) -- false
print(testDictionary["fruitName"]) -- Cherry
print(testDictionary["sour"]) -- false
print(testDictionary["FruitCount"]) -- 10
```

Expand All @@ -203,19 +203,19 @@ To iterate over a dictionary, use the global `pairs()` function in a `for` loop:

```lua
local testDictionary = {
FruitName = "Lemon",
FruitColor = "Yellow",
Sour = true
fruitName = "Lemon",
fruitColor = "Yellow",
sour = true
}

for key, value in pairs(testDictionary) do
print(key, value)
end

--[[ Resulting output:
FruitName Lemon
Sour true
FruitColor Yellow
fruitName Lemon
sour true
fruitColor Yellow
]]
```

Expand All @@ -229,19 +229,19 @@ To remove or erase a key-value pair from a dictionary, set its value for a key t

```lua
local testDictionary = {
FruitName = "Lemon",
FruitColor = "Yellow",
Sour = true
fruitName = "Lemon",
fruitColor = "Yellow",
sour = true
}

testDictionary["Sour"] = nil
testDictionary["sour"] = nil

for key, value in pairs(testDictionary) do
print(key, value)
end
--[[ Resulting output:
FruitName Lemon
FruitColor Yellow
fruitName Lemon
fruitColor Yellow
]]
```

Expand Down Expand Up @@ -280,7 +280,7 @@ To copy a table without any nested tables, Luau offers the `Library.table.clone(
local original = {
key = "value",
engine = "Roblox",
playerID = 505306092
playerId = 505306092
}

local clone = table.clone(original)
Expand Down Expand Up @@ -314,7 +314,7 @@ With the function in place, you can make a deep copy as follows:
local original = {
key = "value",
playerInfo = {
playerID = 505306092,
playerId = 505306092,
playerName = "PlayerName"
},
otherInfo = {
Expand All @@ -339,11 +339,11 @@ To freeze a table without any nested tables, Luau offers the `Library.table.free
local target = {
key = "value",
engine = "Roblox",
playerID = 505306092
playerId = 505306092
}

table.freeze(target)
target.playerID = 1 --> attempt to modify a readonly table
target.playerId = 1 --> attempt to modify a readonly table
```

### Deep Freezes
Expand All @@ -370,7 +370,7 @@ With the function in place, you can deep freeze a table as follows:
local target = {
key = "value",
playerInfo = {
playerID = 505306092,
playerId = 505306092,
playerName = "PlayerName"
},
otherInfo = {
Expand All @@ -381,5 +381,5 @@ local target = {
}

deepFreeze(target)
target.playerInfo.playerID = 1 --> attempt to modify a readonly table
target.playerInfo.playerId = 1 --> attempt to modify a readonly table
```
Loading