You can create a user-defined array with the same value as $legalmoves, edit that array, then use setsystem to change the value of $legalmoves to your edited array. Alternately, you can use push to add each legal move you want to keep to a new array, then use setsystem to assign this new array to legalmoves. Here's an example I did in the Pre-Game code just to test it:
// Assign usual legal moves to White Pawns
for f range a h:
set from join #f 2;
set to1 join #f 3;
set to2 join #f 4;
setlegal #from #to1;
setlegal #from #to2;
next;
// Keep all legal moves except the e Pawn's double move
set lglmvs ();
for v $legalmoves:
if != #v "P e2-e4":
push lglmvs #v;
endif;
next;
setsystem legalmoves #lglmvs;
You can create a user-defined array with the same value as $legalmoves, edit that array, then use setsystem to change the value of $legalmoves to your edited array. Alternately, you can use push to add each legal move you want to keep to a new array, then use setsystem to assign this new array to legalmoves. Here's an example I did in the Pre-Game code just to test it: