
▲ 1 r/devblogs
Let's make a game! 514: Do we retreat? (Twine Sugarcube)
youtube.comu/apeloverage — 3 days ago

When someone promotes their game by saying, "Your decisions have meaningful outcomes!"
That's a description of the format: you make choices, and then see the results of those choices.
It's like saying, "It's a platform game, but you control the main character's movement!"
I have some Javascript, inside a <<script>><</script>>.
I keep getting the following message:
>Error: <<script>>: bad evaluation: Unexpected token '{'
I think the error is in the following lines:
let w=6;
if (svars.pattern[svars.arpeggio][1]==4) {
let w=4;
} elseif (svars.pattern[svars.arpeggio][1]==6) {
let w=3;
}
but I can't work out what's wrong.
$pattern is an array in the main program, and $arpeggio is a single variable in the main program.
EDITED TO ADD: Here's the entire script.
<<script>>
const svars = State.variables;
let file = new Midi.File();
let track = new Midi.Track();
file.addTrack(track);
track.setTimeSignature(svars.pattern[svars.arpeggio][1], svars.pattern[svars.arpeggio][2]);
track.setTempo(40);
/*
Write the arpeggio part once.
*/
let track1 = new Midi.Track();
file.addTrack(track1);
for (let z=1; z<=svars.bars; z++) {
w=6;
if (svars.pattern[svars.arpeggio][1]==4) {
w=4;
} elseif (svars.pattern[svars.arpeggio][1]==6) {
w=3;
}
for (let x=1; x<=4; x++) {
for (let y=1; y<=w; y++) {
if (svars.pattern[svars.arpeggio][y]==5) {
track1.addNote(0, svars.chord_pitch[z][1]+12, 32);
} else {
track1.addNote(0, svars.chord_pitch[z][svars.pattern[svars.arpeggio][y]], 32);
}
}
}
}
let data = file.toBytes();
let datarr = new Uint8Array(data.length);
for(let i = 0; i < data.length; i++) {
datarr[i] = data[i].codePointAt();
}
let blob = new Blob([datarr], { type: "application/octet-stream" });
saveAs(blob, "music.midi");
<</script>>