Adding items to a list via scripting


I’m trying to add a cuboid I create in scripting to a list, so I can go through that list later and delete them all when certain conditions are met. Only thing is, I don’t seem to be able to grasp how lists work in typescript. I know how to do it in coblocks, but it’s not possible to go that route since I’m creating the cuboids via RayCasting. (thanks to the minecraft scripting cospace i’m building upon from TechLeapNZ :slight_smile: ) Could anybody help me or push me in the right direction?

this is what i got so far but it keeps giving me errors in the console.

Hi @Daan_Hobbel,

It looks like you’re creating a new array every time the onKeyDown handler is triggered, so that means every block will be assigned to a new array. You can try moving the array outside of the onKeyDown handler to only use one array for all cuboids (see code example below)

const myArray = new Array<Cuboid>()

Input.onKeyDown(() => {
     * ... (same as your Cuboid creation logic)
}, "yourTriggerKey")

Feel free to share the space in which you encounter your scripting issue so we can take a closer look and see if there are any other problems :slight_smile:

Thank you, managed to fix it by putting the creation of the array outside of the triggerevent like you said :slight_smile:

1 Like