|
| 16 Jan 2015 09:08 PM |
So a while back on SH I somehow got involved with a thing called a nilverse. I decided to attempt to recreate it, but better, this is the code:
Nilverse = {}
function RemoveFromNilverse(i) for ii,v in pairs(Nilverse) do if v.Object == i then Nilverse[ii] = nil break end end end
function AddToNilverse(i) local NilObject = {Object = i} NilObject.Retrieve = function() NilObject.Object.Parent = NilObject.OldParent RemoveFromNilverse(NilObject.Object) end NilObject.Reparent = function(t, par) NilObject.Object.Parent = par RemoveFromNilverse(NilObject.Object) end NilObject.Destroy = function() NilObject.Object:Destroy() RemoveFromNilverse(NilObject.Object) end table.insert(Nilverse, NilObject) end
function AddCheck(i) i.Changed:connect(function(prop) if i.Parent == nil then AddToNilverse(i) elseif i.Parent ~= nil then RemoveFromNilverse(i) end end) end
function Recurse(par, func) func(par) for i,v in pairs(par:GetChildren()) do func(v) return Recurse(v, func) end end
Recurse(game, AddCheck)
wait(5) workspace.Part.Parent = nil print(#Nilverse) wait(1) Nilverse[1]:Retrieve() wait(5) workspace.Part.Parent = nil wait(1) Nilverse[1]:Reparent(game.Lighting) wait(5) game.Lighting.Part.Parent = nil wait(1) Nilverse[1]:Destroy() wait(1) Nilverse[1]:Retrieve()
The last bit is basically tests. It successfully nils the part, but then #Nilverse is empty. 0.
Which means [1]:Retrieve() obviously failed.
How can I actually get this to work? Why is it not being added into the Nilverse? |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 16 Jan 2015 09:13 PM |
| whats the whole thing supposed to do |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:14 PM |
| Create a Nilverse. Did you not see that movie? |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Jan 2015 09:17 PM |
| Nilverse is a table which contains every object that has been niled (.Parent = nil), to allow for retrieving them super easily. The functions it allows are pretty self explanatory. Retrieve() will retrieve the object. Reparent() will retrieve it but set to a new parent. Destroy() will ultimately destroy it from the Nilverse. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:20 PM |
| You two (eLuminate, 128GB) are missing out. You should see that one. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 16 Jan 2015 09:24 PM |
local nilverse = {} setmetatable(nilverse, {__mode="k"}) -- allow instances to get GCed game.DescendantRemoving:connect(function(descendant) nilverse[descendant] = true end) game.DescendantAdded:connect(function(descendant) nilverse[descendant] = nil end) |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:27 PM |
| @ser If I'm incorrect, please do tell me, but would that A) Not run for instances already ingame (not added?) and B) would that not end up calling for Part:Destroy() also? |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 16 Jan 2015 09:29 PM |
| If you just set its parent to nil but keep a reference to it the object stays in memory and can therefore be brought back by simply setting its parent back into the game. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 16 Jan 2015 09:30 PM |
> would that not run for instances already ingame (not added?) If an instance is in the data model, then there's no need to add it to the nilverse. It only needs to be added when it is REMOVED which is what the .DescendantRemoving is for.
> would that not end up calling for Part:Destroy() also? game.DescendantRemoving fires for Instance:Destroy() as long as the instance is a descendant of the DataModel, so my code works |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:32 PM |
| @Ser could you implement that into my script so that the methods Retrieve, Reparent, and Destroy work? If you do it'll be much appreciated :D |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 16 Jan 2015 09:37 PM |
local nul = {}
local function nullify(instance) nul[instance] = instance.Parent; wait() if (instance.Parent ~= nil) then nul[instance] = nil; end end
local services = { "Workspace"; "Players"; "ServerStorage"; "ServerScriptService"; "ReplicatedStorage"; "Lighting"; --You get the idea add more if you want } --[[We can't do game.DescendantRemoving because that will sometimes error from locked objects >.<]]
for _, service in next, services do game:GetService(service).DescendantRemoving:connect(nullify) game:GetService(service).DescendantAdded:connect(function(child) nul[child] = nil; end) end
local part = Instance.new("Part", workspace) part.Name = "bobio the part"
for instance, parent in next, nul do print(instance.Name .. " was last seen at " .. parent:GetFullName()) end
part.Parent = nil; for instance, parent in next, nul do print(instance.Name .. " was last seen at " .. parent:GetFullName()) end
part.Parent = nul[part] for instance, parent in next, nul do print(instance.Name .. " was last seen at " .. parent:GetFullName()) end |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:38 PM |
| @128 Where's all the methods? |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 16 Jan 2015 09:39 PM |
If you want to handle RobloxLocked just do:
function isRobloxLocked(instance) return not pcall(function() return instance.Name end) end
And then:
if not isRobloxLocked(descendant) then return end |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 16 Jan 2015 09:46 PM |
| Why do you need methods? Make them yourself its just a normal table |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 09:47 PM |
| I'll fix it up tom. then. I didn't have time tonight. |
|
|
| Report Abuse |
|
|