[Solved] Change the value of an unknown variable

I ran into an unusual problem tonight. I was working on part of my project that requires altering (what I planned to be) the appropriate children of a scene structure by adding the number of completed Products to the applicable ones. I thought it would be easy but I hit a brick wall:

There is no expression builder for the variable name, it just wants me to enter the name of the variable.

I’m not above entering millions of different variable names to cover every possibility, if it’s the only way to get the job done. So if Product = Goldfish change Shop.Goldfish add Goldfish, if Product = Kitten change Shop.Kitten add Kitten etc. But before I subject myself to that I thought I would check if there is a more humane way.

I am not 100% certain what you are looking for, mainly because I am curious what actions are happening beforehand that would cause shop.(xitem) to be added? I guess I am just wondering what the whole scenario is to lead to that point to begin thinking of some ideas … :slight_smile:

The player mouse release on icons of the Product objects, there can be more than one of the same type in a stack. They tween to a Shop. I had intended to do a simple Products collision shop, change value of variable Shop,Product.ObjectName() add Product, delete Product (icon). It doesn’t really matter when though. As soon as the player mouse release them I can change var Shop, Product with number instance currently picked before the tween even finishes if you like that better. Work your magic for me snobunni.

Untested, but have you considered:

image

1 Like

No. But I’m thinking about it now. I will try that, thank you!

I’d use a structure. This uses scene variables but you could use collisions and object variable and for each object events.

1 Like

Thank you very much, you both make this so easy! I’ll get it taken care of tonight.

Ok so I did get this taken care of tonight (I was too tired to work with words last night) and it works perfectly! What I did was carefully observe how you and @MrMen were structuring your expressions by putting what you wanted in the brackets and tried to copy that style into the name of the variable itself.

I called the variable Shop[Products.ObjectName()] and oddly it works, even though it seems like it wouldn’t because there’s not an expression builder there. So on collision with Shop the Products add 1 to their name and actually it creates the structure Shop first and adds their name to it because I haven’t added any variables outside of the ones created by events yet.

So I’m super grateful to you both because this will save me a lot of time. I hope you can imagine the amount of effort and struggle and irritation you have saved me and know I really appreciate it.

Just going to update this in case someone else is trying to do something similar. The first condition shows what was discussed above. The second condition shows updating a text object with the correct quantity of the Product from the structured variable Shop for each text object.

The ShopIcons have an animation name that matches the name of the Product object they represent. The text objects ShopText are assigned that animation name in a variable (Product) in the beginning of scene depending on which ShopIcon they are in collision with. First the text objects compare their own text with the variable found in the child of Shop thats name matches their own variable (Product), then it updates its text if it is not the same.

I could not have figured out how to update the text had it not been for these valuable examples of changing unknown variables provided for me here.

2 Likes