Hello everyone,
I’m currently learning KSP (Kontakt Script Processor) and trying to build my own Kontakt plugin from scratch.I’m completely new to programming, so I’ve been learning step by step with the help of AI tools and documentation.
However, I keep getting an error every time I run my script — specifically at the line that contains:
ksp
declare $outVel := limit($velocity + 20, 1, 127)
I’ve tried adjusting the syntax and even checked official references, but the error still occurs.If anyone familiar with KSP could take a look, I’d really appreciate your advice.
Below is my full current script:
on init
message("--- Cabbage Cut Foley Engine Initialized ---")
declare const $GRP_L1_ATTACK := 0
declare const $GRP_L2_TEAR := 1
declare const $GRP_L3_SPEED := 2
declare const $GRP_L4_BOARD := 3
declare const $GRP_L5_RELEASE := 4
declare const $MAX_KNOB_VALUE := 1000000
declare const $PITCH_RANGE_MC := 100
make_perfview
set_ui_height_px(200)
declare ui_knob $LayerGain1 (0, 629000, 1)
declare ui_knob $LayerGain2 (0, 629000, 1)
declare ui_knob $LayerGain3 (0, 629000, 1)
declare ui_knob $LayerGain4 (0, 629000, 1)
declare ui_knob $CutSpeed (0, 1000000, 10000)
declare ui_knob $Force (0, 1000000, 10000)
declare ui_knob $RandomPitch (0, 100, 1)
set_knob_label($LayerGain1, "L1 Attack")
set_knob_label($LayerGain2, "L2 Tear")
set_knob_label($LayerGain3, "L3 Speed")
set_knob_label($LayerGain4, "L4 Board")
set_knob_label($CutSpeed, "Cut Speed")
set_knob_label($Force, "Force")
set_knob_label($RandomPitch, "Pitch Rand (%)")
move_control_px($LayerGain1, 20, 30)
move_control_px($LayerGain2, 100, 30)
move_control_px($LayerGain3, 180, 30)
move_control_px($LayerGain4, 260, 30)
move_control_px($CutSpeed, 380, 30)
move_control_px($Force, 460, 30)
move_control_px($RandomPitch, 540, 30)
$LayerGain1 := get_engine_par($ENGINE_PAR_VOLUME, $GRP_L1_ATTACK, -1, -1)
$LayerGain2 := get_engine_par($ENGINE_PAR_VOLUME, $GRP_L2_TEAR, -1, -1)
$LayerGain3 := get_engine_par($ENGINE_PAR_VOLUME, $GRP_L3_SPEED, -1, -1)
$LayerGain4 := get_engine_par($ENGINE_PAR_VOLUME, $GRP_L4_BOARD, -1, -1)
set_knob_defval($CutSpeed, 500000)
set_knob_defval($Force, 500000)
set_knob_defval($RandomPitch, 20)
make_persistent($LayerGain1)
make_persistent($LayerGain2)
make_persistent($LayerGain3)
make_persistent($LayerGain4)
make_persistent($CutSpeed)
make_persistent($Force)
make_persistent($RandomPitch)
call update_ui_labels
end on
function update_ui_labels
set_knob_label($LayerGain1, get_engine_par_disp($ENGINE_PAR_VOLUME, $GRP_L1_ATTACK, -1, -1) & " dB")
set_knob_label($LayerGain2, get_engine_par_disp($ENGINE_PAR_VOLUME, $GRP_L2_TEAR, -1, -1) & " dB")
set_knob_label($LayerGain3, get_engine_par_disp($ENGINE_PAR_VOLUME, $GRP_L3_SPEED, -1, -1) & " dB")
set_knob_label($LayerGain4, get_engine_par_disp($ENGINE_PAR_VOLUME, $GRP_L4_BOARD, -1, -1) & " dB")
end function
on ui_control ($LayerGain1)
set_engine_par($ENGINE_PAR_VOLUME, $LayerGain1, $GRP_L1_ATTACK, -1, -1)
call update_ui_labels
end on
on ui_control ($LayerGain2)
set_engine_par($ENGINE_PAR_VOLUME, $LayerGain2, $GRP_L2_TEAR, -1, -1)
call update_ui_labels
end on
on ui_control ($LayerGain3)
set_engine_par($ENGINE_PAR_VOLUME, $LayerGain3, $GRP_L3_SPEED, -1, -1)
call update_ui_labels
end on
on ui_control ($LayerGain4)
set_engine_par($ENGINE_PAR_VOLUME, $LayerGain4, $GRP_L4_BOARD, -1, -1)
call update_ui_labels
end on
on ui_control ($CutSpeed)
set_knob_label($CutSpeed, int(real($CutSpeed) * 0.0001) & " %")
end on
on ui_control ($Force)
set_knob_label($Force, int(real($Force) * 0.0001) & " %")
end on
on ui_control ($RandomPitch)
set_knob_label($RandomPitch, int(real($RandomPitch) * 1.0) & " %")
end on
on persistence_changed
call update_ui_labels
end on
on note
declare polyphonic $event_id_self := $EVENT_IDdeclare polyphonic $rnd_tunedeclare polyphonic $base_waitdeclare polyphonic $velocitydeclare polyphonic $cut_speed_ksp
$velocity := $EVENT_VELOCITY
$cut_speed_ksp := 1000 - int(real($CutSpeed) * 0.001)
$base_wait := 10000 + (1000 * $cut_speed_ksp / 10)
$rnd_tune := (random(-$PITCH_RANGE_MC, $PITCH_RANGE_MC+1) * $RandomPitch)
change_tune($event_id_self, $rnd_tune, 1)
play_note($EVENT_NOTE, $velocity, 0, 0)
wait($base_wait - ($velocity * 300))
play_note($EVENT_NOTE, $velocity, 0, $GRP_L2_TEAR)
wait(10000 + ($base_wait / 2) - ($velocity * 100))
if ($velocity > 64)
declare $outVel := limit($velocity + 20, 1, 127)
set_event_par($event_id_self, $EVENT_PAR_GROUP, $GRP_L3_SPEED)
play_note($EVENT_NOTE, $outVel, 0)
end if
wait($base_wait * 2 - ($velocity * 500))
play_note($EVENT_NOTE, $velocity, 0, $GRP_L4_BOARD)
end on
on release
declare $release_vel := get_event_par($EVENT_ID, $EVENT_PAR_REL_VELOCITY)
declare $release_id := play_note($EVENT_NOTE, $release_vel, 0, $GRP_L5_RELEASE)
fade_out($release_id, 100000, 1)
end on