Combine variables to reference a variable

Hi!

I am making a voxel game. (think minecraft) Currently I’m calling it It’s Like Minecraft But It’s Not (Minecraft), or ILMBIN for short.

For the block selection, I am calling the block textures bID + a number (bID0 for example) I have a system where a q press decriments a variable called currentselect. an e press increments the same variable. This is used in the following variable called currentblock. This variable goes like this:

var currentselect = 0;
var currentblock = "bID" + currentselect;

In my head this adds up to bID0, which is a block texture. then when you place a block it’s texture should be bID0, but instead it makes the scene freeze.

Any ideas on how to fix?

Playground: https://playground.babylonjs.com/#D1Z1VL#6

You have a function that does not exist ‘updatePosition’.

That’s probably what’s causing your problem.

function lockChangeAlert() {
    if (document.pointerLockElement === canvas ||
        document.mozPointerLockElement === canvas) {
        console.log('The pointer lock status is now locked');
        document.addEventListener("mousemove", updatePosition, false);
    } else {
        console.log('The pointer lock status is now unlocked');  
        document.removeEventListener("mousemove", updatePosition, false);
    }
}

I’m not sure if that’s the issue. It hasn’t caused me any problems, but thanks for pointing it out. It might cause problems in the future. :slight_smile:

block.material = currentblock; is affecting the string to the material. I you want to do this you need to store your materials in a dictinary and access by name or you could use an array and simply access by index.

1 Like

what? :confused:

I’ll need some help with this one. I like to say I’m fluent in js, but I’m not (really).

https://playground.babylonjs.com/#D1Z1VL#9

1 Like

Thanks! I didn’t know you could do that! :smile: