A Roblox module designed to simulate a Type Writer effect on a TextLabel Instance.
- Set your own interval at which the characters are typed
- Play a custom sound for each individual TypeWriter object
local TypeWriter = require(script.Parent.TypeWriter);
type TypeWriter = TypeWriter.TypeWriter;
local writer: TypeWriter = TypeWriter.new(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
);
To begin writing with the TypeWriter it's as simple as calling :Write().
-- This will begin writing the content into the TargetElement.
writer:Write();
If you wish to implement a skip button for an npc dialogue or similar purposes,
you can writer:Skip()
the TypeWriter causing the effect to end displaying all content at once.
There are 2 methods of skipping the TypeWriter:
writer:Skip();
writer:SkipSync();
You can externally stop the TypeWriter for any reasons.
It follows the similar conventions of writer:Skip()
:
writer:Stop();
writer:StopSync();
The sole purpose of the synchronous variants is for cases where you need to stop the TypeWriter to change
the content like in writer:SetContent()
and you want to write the new content
straight away after the TypeWriter's thread has been fully suspended.
writer:Write();
writer:StopSync(); -- This method yields until the TypeWriter is ready for re-processing.
writer:Write(); -- Meaning this Write can be called immediately after.
HOWEVER
writer:Write();
writer:Stop();
writer:Write();
See the problem is that the TypeWriter's thread wouldn't of been haulted by the next writer:Write()
leading to the original thread not being suspended ignoring your writer:Write()
call.
The reason that the sync variant is not default is because this is really only an issue when your immediately trying to write upon a skip or stop.
Realistically, if you were to run the time from the skip/stop + writer.TypeInterval
it would be safe to do this without yielding to begin with.
NOTE:
This could change in the future possibly.
writer:Write();
-- This internally calls writer:StopSync() allowing you to change the content and re-run the TypeWriter.
writer:SetContent("The new content to write through the TypeWriter");
writer:Write();
writer.Finished:
This event is fired when the TypeWriter has finished writing it's content.writer.Skipped:
This event is fired when the TypeWriter was skipped.writer.Stopped:
This event is fired when the TypeWriter has been stopped externally.
If you want to use types for the events you can use my exported type: TypeWriter.GoodSignal