Skip to content

Commit 4c53672

Browse files
Use type checks instead of assert
Closes #1
1 parent d389c85 commit 4c53672

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

RhythmService.lua

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ local RhythmService = {
1111
local Song = {Sound = nil, Keys = {}, KeyPosition = 1, StopwatchEvent = nil};
1212
local Events = {};
1313

14-
function RhythmService:SetSound(sound, keepKeys, startStopwatchOnPlay)
15-
assert(sound and sound:IsA("Sound"), "A sound instance must be the first argument");
16-
assert(not keepKeys or typeof(keepKeys) == "boolean", "keepKeys must be a boolean or nil");
17-
assert(not startStopwatchOnPlay or typeof(startStopwatchOnPlay) == "boolean", "startStopwatchOnPlay must be a boolean or nil");
18-
14+
function RhythmService:SetSound(sound: Sound, keepKeys: boolean?, startStopwatchOnPlay: boolean?)
1915
-- Set sound and remove keys if necessary
2016
Song.Sound = sound;
2117
if not keepKeys then
@@ -31,10 +27,8 @@ function RhythmService:SetSound(sound, keepKeys, startStopwatchOnPlay)
3127
end;
3228
end;
3329

34-
function RhythmService:AddKey(timePosition, index)
30+
function RhythmService:AddKey(timePosition: number, index: number?)
3531
assert(Song.Sound, "A sound instance must be defined before adding a key");
36-
assert(timePosition and tonumber(timePosition), "A time position must be given to add a key");
37-
assert(not index or tonumber(index), "index must be a number or nil");
3832

3933
-- Add key
4034
local Key = {timePosition, 1};
@@ -45,9 +39,7 @@ function RhythmService:AddKey(timePosition, index)
4539
end;
4640
end;
4741

48-
function RhythmService:SetKeys(keys)
49-
assert(not keys or typeof(keys) == "table", "keys must be a table or nil")
50-
42+
function RhythmService:SetKeys(keys: {number}?)
5143
-- Set keys
5244
Song.Keys = {};
5345
if keys then
@@ -57,8 +49,7 @@ function RhythmService:SetKeys(keys)
5749
end;
5850
end;
5951

60-
function RhythmService:RemoveKey(index)
61-
assert(not index or tonumber(index), "index must be a number");
52+
function RhythmService:RemoveKey(index: number)
6253
table.remove(Song.Keys, index);
6354
end;
6455

@@ -87,11 +78,7 @@ function RhythmService:CheckRhythm()
8778
return Result;
8879
end;
8980

90-
function RhythmService:ToggleKey(disable, index, keepPosition)
91-
assert(not disable or typeof(disable) == "boolean", "disable must be a boolean or nil");
92-
assert(not index or tonumber(index), "Index must be a number or nil");
93-
assert(not keepPosition or typeof(disable) == "boolean", "Index must be a number or nil");
94-
81+
function RhythmService:ToggleKey(disable: boolean?, index: number?, keepPosition: number?)
9582
-- Toggle key and shift position
9683
Song.Keys[Song.KeyPosition or index][2] = (disable and 0) or 1;
9784
if not keepPosition and #Song.Keys >= Song.KeyPosition + 1 then

0 commit comments

Comments
 (0)