Well, I’m not sure if “Storyboard” is a good name for it, but we all have seen those linear story games such as Camping and Breakout. The players get to a location, then an event happens and so on. To make things a bit simpler, I’ve created this module: Storyboard Module
If you don’t want to download the module, then here is the source code:
-- Storyboard module by auseless_Scout
-- Credit isn't needed, would be appreaciated though
local storyBoard = {}
storyBoard.__index = storyBoard
function storyBoard.new(debugoption)
local self = setmetatable({}, storyBoard)
self.Board = {}
self.OnEvent = Instance.new("BindableEvent")
self.paused = false
self.stopped = false
if debugoption == true then
self.debug = true
else
self.debug = false
end
return self
end
function storyBoard:addEvent(requirementFunc, outcomeFunc, waitTime, eventName)
table.insert(self.Board, {["Requirement"] = requirementFunc, ["Outcome"] = outcomeFunc, ["Time"] = waitTime, ["Name"] = eventName})
end
function storyBoard:addWait(waitTime, eventName)
table.insert(self.Board, {["Time"] = waitTime, ["Name"] = eventName})
end
function storyBoard:pause()
self.paused = true
end
function storyBoard:unPause()
self.paused = false
end
function storyBoard:stop()
self.stopped = true
end
function storyBoard:delete()
self = nil
end
function storyBoard:run()
for i, event in ipairs(self.Board) do
if self.stopped then return end
if self.paused then
repeat task.wait() until self.paused == false
end
self.OnEvent:Fire(i, event["Name"])
if event["Name"] and self.debug then
print(event["Name"].. " has been reached")
end
local check
local resultType
if event["Requirement"] then
if event["Name"] and self.debug then
print(event["Name"].. " Requirement has been reached")
end
check, resultType = event["Requirement"](i)
if check ~= true then
repeat
check = event["Requirement"](i)
task.wait()
until check == true
end
end
if event["Time"] then
if event["Name"] and self.debug then
print(event["Name"].. " Wait Time")
end
task.wait(event["Time"])
end
if event["Outcome"] then
if event["Name"] and self.debug then
print(event["Name"].. " Outcome has began")
end
event["Outcome"](resultType, i)
if event["Name"] and self.debug then
print(event["Name"].. " Outcome has ended")
end
end
end
end
function storyBoard:deferRun()
task.defer(function()
self:run()
end)
end
function storyBoard:spawnRun()
task.spawn(function()
self:run()
end)
end
return storyBoard
The module itself isn’t that complex, but it might be useful in making simple story games.
How to install:
- Get Module,
- Place in ReplicatedStorage (or ServerStorage, doesn’t matter unless you wan’t the client to access it as well, in which you’d use ReplicatedStorage),
- Require the module and you’re set .
How to create a storyboard object:
- Create a storyboard.
As seen in this image, we’re creating a storyboard object. This function has a parameter for debugging, as setting it to true will print out information useful for debugging.
How to use:
(All parameters are optional to allow for full creativity, hence leaving some as nil will not result in an error).
- There are three functions that the storyboard object can perform. The first one is addEvent()
This function allows for the creation of an event. The requirement function is a function that you can create to include a requirement that must be met in order for the outcome function to occur. As a result, the requirement function MUST return true or false. It can also return a second variable called resultType which allows for multiple pathways (If A is met, we get “good ending”, if B is met, “we get bad ending” etc.) The only parameter for this function is the index of the event, which is useful for debug purposes. The second parameter, outcome function, is the outcome that will occur if a requirement is met. This could involve spawning in an enemy that you have to fight off. There are two parameters, the first being the resultType as mentioned, and the second being the index of the event for debug purposes. The waitTime is a wait time that is option for those who want a delay before the outcome will occur. Essentially it’s a task.wait() that occurs after the requirement is met but before the outcome occurs. The last parameter is the eventName which is useful for debugging as it allows you to know which event is currently running. - The second function is addWait()
This allows for a wait between events. The first parameter is the length of the wait, while the second one, eventName, is for debugging. - The third function is run()
This will run all the events.
The order that the events occur is from the order they are created. Lets look at this example:
local storyboardModule = require(script.Parent.StoryboardModule)
local storyboard = storyboardModule.new()
storyboard:addEvent(function()
if game.Lighting.ClockTime >= 15 then
return true
else
return false
end
end, function()
print("ClockTime is larger than 15")
end, 1.5, "Event1")
storyboard:addWait(3, "Event2")
storyboard:addEvent(function()
if game.Lighting.ClockTime >= 20 then
return true
else
return false
end
end, function()
print("ClockTime is larger than 20")
end, 1.5, "Event3")
storyboard:run()
In this example, the storyboard will begin with Event1, then it will go through the 3 second wait that Event2 offers, then it will finish with Event3. This example is quite simple and I tried to create a quick demo. Here is the place: Storyboard-Module-House demo. In this demo, the first event will require you to enter the house, followed by a short delay, and then you will be faced with two options. You can wait for 30 seconds and accept the bad ending (death), or you can jump 5 times and you’ll receive the good ending (“good ending” gets printed out in the console). You can check the code in the place. (Keep in mind that the demo is simple and to fully utilize this module, you’ll need to have a good chunk of knowledge in scripting.
Oh yea, and to have GUIs pop up due to events, you can just use a remote event that fires to the clients.
I might add more functions. I’m thinking of making a simple Dialogue System that will go well together for this.