Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/instances/Game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local Workspace = import("./Workspace")

local Game = BaseInstance:extend("DataModel")

function Game:init(instance)
function Game:init(instance, habitat)
AnalyticsService:new().Parent = instance
ContentProvider:new().Parent = instance
CoreGui:new().Parent = instance
Expand All @@ -40,6 +40,8 @@ function Game:init(instance)
UserInputService:new().Parent = instance
VirtualInputManager:new().Parent = instance
Workspace:new().Parent = instance

getmetatable(instance).instance.habitat = habitat
end

function Game.prototype:GetService(serviceName)
Expand Down
15 changes: 3 additions & 12 deletions lib/instances/LocalScript.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
--[[
Serves as just a source container right now.
Currently exactly the same as Script.
]]

local BaseInstance = import("./BaseInstance")
local InstanceProperty = import("../InstanceProperty")
local Script = import("./Script")

local LocalScript = BaseInstance:extend("LocalScript", {
creatable = true,
})

LocalScript.properties.Source = InstanceProperty.normal({
getDefault = function()
return ""
end,
})
local LocalScript = Script:extend("LocalScript")

return LocalScript
35 changes: 35 additions & 0 deletions lib/instances/Script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,41 @@ local Script = BaseInstance:extend("Script", {
creatable = true,
})

function Script:init(instance)
local internal = getmetatable(instance).instance

internal.hasRun = false

instance.AncestryChanged:Connect(function()
if internal.hasRun then
return
end

local game = nil

local now = instance
while now do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this whole loop? If you really can't just use the game global, changing this to now:FindFirstAncestorWhichIsA("DataModel") would make this more readable.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, there is no game global here, since we have no environment.

I forgot that FindFirstAncestorWhichIsA was a function we have, that's the way to go. I'll remove the existing ScreenGui checks and replace them with that too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, FindFirstAncestorWhichIsA isn't actually implemented on lemur. Wouldn't be hard though.

now = now.Parent

if now.ClassName == "DataModel" then
game = now
break
end
end

if game == nil then
return
end

internal.hasRun = true

-- TODO: Correctly handle errors

local co = coroutine.create(loadstring(instance.Source))
getmetatable(game).instance.habitat.taskScheduler:schedule(0, co)
end)
end

Script.properties.Source = InstanceProperty.normal({
getDefault = function()
return ""
Expand Down