hello
i wanna know if there is a way to tell the game
“hey look the player have reached the fps cap
i want you to run this function as long as the cpu and gpu are not busy”
also something like
“hello system i want to add this varible and this varible is not important
if you want to delete it and replace it with something more important feel free to do it”
would be cool if you can make something like a custom particles system or anything that is not important to not affect the performance
i want to know if what im asking for is something that already exists or im asking for something new at coding because i never saw something about it before
tl;dr:
1: i want something to tell the game to run something as long as it wont effect the performance
2: i want something to tell the game that a specific data is not important and can be replaced if the memory is full
As far as I know, there is no built-in method of doing this.
You could detect when the FPS approximately reaches the FPS cap, then run the desired function — and of course stop it when it’s not close to the cap anymore.
The issue is that the user’s FPS cap setting is not exposed, so you’d have to just use 60.
You can just remove all references to the variable or set the variable to nil, then the variable’s used memory will be free.
Then of course just make a new variable.
With a bit of work you can get these going pretty smooth and for what they are doing about as optimized as the concept can get. You can tweak it a bit by how you build it also.
A lot of what you’re saying here is about good programming practices, including timing and cleanup.
.Stepped:Wait() is a go-to command for timing, along with task.wait(), especially for control and/or synchronization. This also helps performance when done correctly.
In programming all variables are references, meaning they refer (direct) to a value in memory.
That’s also why there is only one table here, not two:
local table1 = {1, 2, 3}
local table2 = table1 -- Same table, not another one!
The LuaU (Roblox’s programming language) garbage collector frees up memory by erasing non-referenced values.
local table1 = {1, 2, 3}
local table2 = table1
-- Both are references, so we need to remove both to truly delete the table.
table1 = nil -- You might think 'table2' is now nil, but it's actually the table!
table2 = nil -- That was the last reference. The table no longer exists in memory.
It’s just about removing the references, then the memory will be freed up automatically.
Here are some more examples:
local variable = 1
variable = nil -- Free memory.
local function hi(variable)
variable = nil -- Doesn't free memory.
end
local number = 1
hi(number)
local function hi(variable)
variable = nil -- Free memory.
end
hi(1)
Once you’ve freed up memory, you can create a new variable, technically replacing the old variable.
not like that
I mean something like
table=
{particle,particle,particle,particle,particle}
now memory is full
we dont need these particles
table becomes
{particle,particle}
and the particles are now replaced with the more important data
you know how your device treats deleted files?
it deletes the pointer to the file but not the file itself
when getting a new file the pc will put the new data in the deleted file’s place
i want that part where you can let the system replace the deleted file data without losing the varible
kinda like how you will treat the stuff in your room if you no longer have a space for them
you would remove the useless stuff from the room to leave a space for the important stuff
You’d have to use metatables, which isn’t a good solution especially if you’re looking for performance.
Can you explain why exactly you need this type of behaviour?
collecting it for feature project
i might work on a custom particles system
maybe the particles will effect the performance so i think it would be ideal to just let the game delete some of the particles to make space for more important stuff for the game like a character without making the game crash for the player since particles are not important and can be removed
its just the system not knowing that they are not important and can be replaced with something else like physics or a game assest