samedi 13 juin 2020

How to run method from string that shares object name

So I have a list of objects that I want to detect in a user input, then execute methods on those objects mentioned. My problem is I can extrapolate the strings equal to the object.name property, but I can't find a way to take that string and turn it into the object itself.

for(l = 0; l < Interactable.length; l++) {
                    if(Interactable[l] == o) {
                        var object = Interactable[l];
                        console.log(object);
                        //object.isight();
                    }
                }

So object.isight(); is the method I want to ultimately execute, but I can't figure out how to grab that paricular unit from Interactable[l].

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire