How do I use variables this way?

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Ok, I'll look into dictionaries, thanks!

    EDIT: Are dictionaries global? If I switch layouts, will it remember the values I gave them?

  • 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?

  • -> 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.

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)