How can I combine 2 or more scripts

Hi guys!
What would be the right way to combine 2 scripts?

  1. metronome

// Script to display bar and beat numbers in a widget label and LEDs
Var
bar,beat : Integer
position_label,led1,led2,led3,led4 : Widget
bar_s,beat_s,label : String

On BeatChanged(barNumber : Integer, BeatNumber : Integer, tick : Integer) // Called every time the beatNumber increments
// Note that barNumber and tick are not currently implemented

// Calculate bar and beat number
bar := Floor(BeatNumber / 4) + 1
beat := BeatNumber % 4 + 1

// Update widget label
bar_s := bar
beat_s := beat
label := bar_s + "." + beat_s
SetWidgetLabel (position_label, label)

// Update LEDS
If beat == 1 Then SetWidgetValue(led1,1) Else SetWidgetValue(led1,0) End
If beat == 2 Then SetWidgetValue(led2,1) Else SetWidgetValue(led2,0) End
If beat == 3 Then SetWidgetValue(led3,1) Else SetWidgetValue(led3,0) End
If beat == 4 Then SetWidgetValue(led4,1) Else SetWidgetValue(led4,0) End

End


  1. Song parts

on BeatChanged(bar : integer, beat : integer, subbeat : integer)
if beat == 0 then
SetVariation(0)
elsif beat == 4 then
SetVariation(1)
elsif beat == 16 then
SetVariation(2)
elsif beat == 22 then
SetVariation(3)
elsif beat == 28 then
EnablePlayhead(false)
end
end

THANKS!

In a rackspace sript the callback “on BeatChanged” can only be defined once.
But you can define a user function and call that from the on BeatChanged.
This way the code will not grow like a Spaghetti Code :wink:

1 Like

Is it possible to get an example?

Take this
No_Spaghetti.gig (3.4 KB)

function SetVar (index : Integer)
 if index == 0 then
  SetVariation(0)
 elsif index == 4 then
  SetVariation(1)
 elsif index == 16 then
  SetVariation(2)
 elsif index == 22 then
  SetVariation(3)
 elsif index == 28 then
  EnablePlayhead(false)
 end
end

on BeatChanged(bar : integer, beat : integer, subbeat : integer)
 SetVar(beat)
end
3 Likes