I might be going about this the wrong way, but want to access an objects properties through a separate array. My objects looks like this, setup in Javascript for various ingredients. I’ll just list one here to save space.
setup.Milk = {
name: "milk",
cost: 10,
stack: 15,
desc: "Milk, it does the body good.",
};
Then I have an array with just the keys in them, I did this to save memory instead of making an array of objects.
<<set $ingredients = ["Sauces","Spices","Milk","Beans","Cheese","Eggs","Vegetables","Crackers","Pasta","Ham","Chicken","Sirloin","Fish","Butter","Potatoes"]>>
I then want to access the properties of the object using $ingredients. The only way I’ve been able to do it is using the index. For instance, this prints out the description of milk.
<<=setup[$ingredients[2]].desc>>
This does not, and returns a desc undefined.
<<=setup[$ingredients["Milk"]].desc>>
I could probably make a for loop and search when the index matches the name, but seems like it could lead to trouble down the road. Am I going about this wrong?
twine 2.315
sugarcube 2.34