How do I use variables this way?

Get help using Construct 2

Post » Sat Dec 13, 2014 7:17 am

So basically I need some code that when the player touches an item, it figures out what stats that item affects and what values to give it. I have instance variables for each item representing the stat and it's value, but I need a more efficient way to apply those to the character. The roadmap for the code is

1. Get the name and value of the variables in the instance
2. Apply the values to the stats of the appropriate name to the character

I don't see a way to just find a variable based on name, it's all selected by a dropdown menu, am I missing something? If I could choose which variable to edit by name I can make the name a check for whatever stat I need to change something like
pseudo code
->in player, set variable "ItemsFamily.Variables[0].Name" to "ItemsFamily.Variables[0]"
Any way to do this?
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Dec 13, 2014 2:28 pm

One option would be to use Dictionary for the stats. Then you could call them by name. Also you can add it as container if needed.
B
34
S
9
G
3
Posts: 517
Reputation: 5,246

Post » Sat Dec 13, 2014 8:17 pm

Ok, I'll look into dictionaries, thanks!
EDIT: Are dictionaries global? If I switch layouts, will it remember the values I gave them?
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Dec 13, 2014 8:59 pm

Ok so I tried dictionaries, and the setup I have looks like this

-> on collision with PassiveItems (PassiveItems is a family)
->Set key "PassiveItems.Stat" to "Dictionary.Get(PassiveItems.Stat) + PassiveItems.Value"

It doesn't work. If I manually type in the name of the stat and the value, it works fine, but for some reason when I ask it to look for it like this, it does nothing. Anyone know why?
B
5
S
1
Posts: 59
Reputation: 497

Post » Sat Dec 13, 2014 9:47 pm

ChefSeth wrote:-> on collision with PassiveItems (PassiveItems is a family)
->Set key "PassiveItems.Stat" to "Dictionary.Get(PassiveItems.Stat) + PassiveItems.Value"

Are you actually leaving the double quotes around your expressions? If this is the case, try removing the double quotes and see if it works. Putting anything in double quotes is going to give you a string containing what's inside the double quotes -- this means if you have an expression in double quotes, it won't be evaluated.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Sat Dec 13, 2014 9:50 pm

No Im not actually leaving double quotes on lol that was just to distinguish them from the rest of it

EDIT: I figured out what was wrong, the values I was trying to access were being overridden by the family's default value so it came out blank, I got it fixed though. Thanks for everyone's help!
B
5
S
1
Posts: 59
Reputation: 497


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 45 guests