maid
Cleaning up: a maid holds what has to go together (the connections a part of a script made, its things, its tasks) and cleans it all up in one call, so nothing is left listening by mistake.
maid.newfunction
maid.new(): maidA new maid: give it what has to be cleaned up together (connections, functions, things, tasks...), and clean cleans it all at once: local events = maid.new(), events:give(scored:connect(f)), then events:clean().
Gives: maid.
maid:givefunction
m:give(what: connection or function or thing or shader or task or maid or sound or table, name: string or nil): anyGives the maid something to clean up later: a connection (stopped), a function (called), a thing (destroyed), a shader (destroyed), a task (stopped), a looped sound (stopped), another maid (cleaned) or a table with a destroy function (called). Gives it back: local c = m:give(door.touched:connect(f)). Given under a name that is taken, what had the name is cleaned first.
| Value | Type | |
|---|---|---|
what | connection or function or thing or shader or task or maid or sound or table | |
name | string or nil | May be left out. |
Gives: any.
maid:giveForfunction
m:giveFor(what: connection or function or thing or shader or task or maid or sound or table, seconds: number, name: string or nil): anyGives the maid something as give does, and it is cleaned up by itself after that many seconds, while the script carries on. Gives it back: m:giveFor(things.new(cat.Kind.decoration), 5). If it is cleaned or taken out before then, nothing more happens to it.
| Value | Type | |
|---|---|---|
what | connection or function or thing or shader or task or maid or sound or table | |
seconds | number | |
name | string or nil | May be left out. |
Gives: any.
maid:cleanfunction
m:clean(...: string)Cleans up everything the maid holds, the last given first, and empties it: it can be given more after. With names, only what was given under them: m:clean("music").
| Value | Type | |
|---|---|---|
... | string |
maid:keepfunction
m:keep(...: string)Cleans up everything the maid holds except what was given under these names, the last given first: m:keep("music"). What is kept stays in the maid. With no names, nothing is kept.
| Value | Type | |
|---|---|---|
... | string |
maid:cleanAfterfunction
m:cleanAfter(seconds: number): taskCleans the maid after that many seconds, as clean does, while the script carries on. It is not destroyed: it can be given more after. Gives the task: task.cancel stops it.
| Value | Type | |
|---|---|---|
seconds | number |
Gives: task.
maid:takefunction
m:take(...: string): anyTakes what was given under a name out of the maid without cleaning it, and gives it back. With no name: everything, as a list.
| Value | Type | |
|---|---|---|
... | string |
Gives: any.
maid:getfunction
m:get(name: string): anyWhat was given under a name (nil: nothing). It stays in the maid.
| Value | Type | |
|---|---|---|
name | string |
Gives: any.
maid:allfunction
m:all(): tableA list of everything the maid holds, in the order it was given.
Gives: table.
maid:cleanWhenGonefunction
m:cleanWhenGone(thing: thing): connectionCleans the maid up when the thing goes for good (destroyed, or its time up). Tied to several things, it is cleaned when the first one goes. Cleaning unties it.
| Value | Type | |
|---|---|---|
thing | thing |
Gives: connection.
maid:destroyfunction
m:destroy()Cleans everything up, and the maid is done: giving it more is a mistake (as for a thing after thing:destroy).
maid:destroyAfterfunction
m:destroyAfter(seconds: number): taskDestroys the maid after that many seconds, as destroy does, while the script carries on. Gives the task: task.cancel stops it.
| Value | Type | |
|---|---|---|
seconds | number |
Gives: task.
maid.cleanedfunction
m.cleaned: eventAn event that happens each time the maid has cleaned something up: once for each clean, keep, cleanAfter or cleanWhenGone, for a give that takes a name from something, when giveFor times come, and in destroy. Not when there was nothing to clean.
maid.destroyedfunction
m.destroyed: eventAn event that happens once, when the maid is destroyed (destroy or destroyAfter), after its last cleaned. Then both events are over: what was connected to them is disconnected.