The function Effect_NextOpenSlot returns a byte, but if the maximum amount of effect on screen has been reached, it returns -1, causing an overflow error.
Code:
Private Function Effect_NextOpenSlot() As Byte
Dim EffectIndex As Byte
'Find The Next Open Effect Slot
Do
EffectIndex = EffectIndex + 1 'Check The Next Slot
If EffectIndex > NumEffects Then 'Dont Go Over Maximum Amount
Effect_NextOpenSlot = -1
Exit Function
End If
Loop While Effect(EffectIndex).Used = True 'Check Next If Effect Is In Use
'Return the next open slot
Effect_NextOpenSlot = EffectIndex
End Function
And in the spells subs there is a handler for the -1 value, but the variable is declared as byte:
Code:
Dim EffectIndex As Byte
Dim LoopC As Long
'Get the next open effect slot
EffectIndex = Effect_NextOpenSlot
If EffectIndex = -1 Then Exit Function