Hello developers!
I currently have a system that allows a script to interact with a module script using either the addItem of updateItem function. When one of those is used, an item is added to the “items” table in the module script. Although the item is added to the table when playtesting, it does not save to the actual script source code. When an item is added to the table, I would like that new table to essentially overwrite the old one, to have the table be updated and to have that update the code in studio.
I know there are methods such as script.source that can be used in the command line, but that doesn’t seem to work for my use case.
I’m not sure how easy that is to understand. Please ask questions if it’s unclear what I want.
Script
local t = {}
local items = {
{
Id = 1,
Name = "",
Type = "Misc.",
Price = 0,
Image = 123,
},
{
Id = 2,
Name = "",
Type = "Misc.",
Price = 0,
Image = 123,
},
}
t.updateItem = function(nId, nName, nType, nPrice, nImage)
for _, item in pairs(items) do
if item.Id == nId then
print(item.Id)
item.Name = nName
item.Type = nType
item.Price = nPrice
item.Image = nImage
if not item.Name then
item.Name = "nil"
end
if not item.Type then
item.Type = "nil"
end
if not item.Price then
item.Price = 0
end
if not item.Image then
item.Image = 0
end
end
end
print(items)
--return items
end
t.addItem = function(nId, nName, nType, nPrice, nImage)
table.insert(items,nId, {nId,nName,nType,nPrice,nImage})
print(items)
--return items
end
return t