Not sure if this in the right section or not but I do have a genuine question. How you you subtract a dictionary’s value? I’ve looked everywhere and couldn’t find anything. If I could get some answers that would be great. Thanks!
Are you talking about a dictionary set up like this:
local dict = {
Value = 5
}
if so, you can do:
dict.Value -= 1
and you can subtract an item in the dictionary.
Like this
Local tablethingy = {[1] = ["sss" ] = "ddd", ["sss" ] = "ddd", ["sss" ] = "ddd"}
im trying to subtract the first value [1]
When you say subtract, do you mean literally subject a number or remove the item completely?
Note that you can’t edit a key within a dictionary, instead you would have to add a new one.
Ah ok I think I might have an idea then thanks!
local dictionary = {[1] = "13"}
print(tonumber(dictionary[1]) - 5) -- 8
Is this what you mean by subtract a dictionary’s value?
yea something like that but in pairs so it would subtract every value in the table
local dictionary = {[1] = "13", [2] = "14", [3] = "15"}
for key, value in pairs(dictionary) do
tonumber(value) -= 5
print(value)
end
local dictionary = {[1] = "13", [2] = "15", [3] = "18"}
for i, v in pairs(dictionary) do
print(tonumber(v) - 5)
end
can you show which lines you are getting the errors from?
Here do this:
local dictionary = {[1] = "13", [2] = "14", [3] = "15"}
for key, value in pairs(dictionary) do
value -= 5
print(value)
end
This subtracts the values without erroring
It returns an error “attempt to perform arithmetic (sub) on table and number”
Can you share your code, because it doesn’t error for me
Ok sure I’m just gonna send the whole script if that’s ok
local TweenService = game:GetService("TweenService")
local NotificationsInQueue = {}
local ActiveNotifications = 0
local NotificationLimit = 3
local ActiveTime = 6
--local ActiveNotificationNum = #ActiveNotifications
local NotificationBox = script.Parent.Storage:WaitForChild("NotificationBox")
local NotificationSounds = script.Parent:WaitForChild("GUISounds")
local function Check() return end
local function PushNotification(Label, Text, Sound)
NotificationsInQueue[1] = nil
for _,i in pairs(NotificationsInQueue) do
i -= 1
end
for _,i in pairs(script.Parent.Holder:GetChildren()) do
if i:IsA("Frame") then
i:TweenPosition(UDim2.new(0,0, i.Position.Y.Scale - .300, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad,.2)
end
end
local Clone = NotificationBox:Clone()
ActiveNotifications = ActiveNotifications + 1
task.wait(.6)
Clone.Text.Text = Text
Clone.Label.Text = Label
Clone.Parent = script.Parent.Holder
Clone:TweenPosition(UDim2.new(0,0, Clone.Position.Y.Scale, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad,.2)
if Sound == "None" then
NotificationSounds.none:Play()
elseif Sound == "Error" then
NotificationSounds.error:Play()
elseif Sound == "Blop" then
NotificationSounds.blop:Play()
end
task.spawn(function()
task.wait(ActiveTime)
Clone:TweenPosition(UDim2.new(1,0, Clone.Position.Y.Scale, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad,.3)
task.wait(1)
ActiveNotifications = ActiveNotifications - 1
Clone:Destroy()
end)
end
local function Insert(Label, Text, Sound)
print("yea")
table.insert(NotificationsInQueue,{["Label"] = Label; ["Text"] = Text; ["Sound"] = Sound})
print("yea")
end
local function Update()
if ActiveNotifications < NotificationLimit and #NotificationsInQueue > 0 and NotificationsInQueue[1] ~= Check() then
print(NotificationsInQueue)
PushNotification(NotificationsInQueue[1].Label, NotificationsInQueue[1].Text, NotificationsInQueue[1].Sound)
end
end
task.wait(5)
Insert("Notification","chill bro","None")
task.wait(.1)
Insert("Notification","chill bro","None")
task.wait(.1)
Insert("Notification","chill bro","None")
task.wait(.1)
Insert("Notification","chill bro","None")
task.wait(.1)
Insert("Notification","chill bro","None")
while task.wait(.7) do
Update()
end
here is where the part is if you need it
Actually that is not where the problem is, and there are a number of problems and you would need to probably redo the script. You can’t use []
and should use {}
when creating nested tables. When you switch it you would also have to switch out many other things.
Tables with numbers as keys are actually called arrays, dictionaries are keys with strings.