Dictionary to text

0 favourites
  • 5 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • I have a simple item pickup on collision. The item is added to a dictionary. I'm now trying to have a text object "read" that dictionary. That is, adding/removing CurrentKey, CurrentValue and newline for each key. Any help is appreciated!

  • You mean listing all dictionary keys/values in a text object?

    You can do something like this

    Dictionary for each key
    .. Text Append Dictionary.CurrentKey & ": "
    .. Text Append Dictionary.CurrentValue & newline
    
  • Thanks for the reply! Let me be a bit more specific:

    I have a dictionary containing in-game currencies. I'd like to use a text object to show these currencies.

    When adding a new currency to the dictionary, I'd like to add its CurrentKey and CurrentValue to the text object.

    If the text object already has such key, I'd like it to only add its CurrentValue.

    I hope this makes sense, I'm pretty stuck at this and it might be a suboptimal approach. If you have a better method I'm all ears.

    Thanks again.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the reply! Let me be a bit more specific:

    I have a dictionary containing in-game currencies. I'd like to use a text object to show these currencies.

    When adding a new currency to the dictionary, I'd like to add its CurrentKey and CurrentValue to the text object.

    If the text object already has such key, I'd like it to only add its CurrentValue.

    I hope this makes sense, I'm pretty stuck at this and it might be a suboptimal approach. If you have a better method I'm all ears.

    Thanks again.

    Instead of checking the Txt object if has the key you need to keep track of the Printed (Keys & Values), for this, I will just check if the Key exists will be much easier:

    Example:

    On Currency Check:

    --------- Dictionary has Key?

    -----------------If Yes: add the value to the existing value in the dictionary and then clear the Txt to Print all currency (Key & Values) again

    ----------------- Else Key Doesn't Exist: add the new (Key and Value) to the dictionary then Update the Txt object with a new line and print the new (Key & Value)

    This is so to avoid updating every tick the Txt object

  • > Thanks for the reply! Let me be a bit more specific:

    >

    > I have a dictionary containing in-game currencies. I'd like to use a text object to show these currencies.

    >

    > When adding a new currency to the dictionary, I'd like to add its CurrentKey and CurrentValue to the text object.

    > If the text object already has such key, I'd like it to only add its CurrentValue.

    >

    > I hope this makes sense, I'm pretty stuck at this and it might be a suboptimal approach. If you have a better method I'm all ears.

    >

    > Thanks again.

    Instead of checking the Txt object if has the key you need to keep track of the Printed (Keys & Values), for this, I will just check if the Key exists will be much easier:

    Example:

    On Currency Check:

    --------- Dictionary has Key?

    -----------------If Yes: add the value to the existing value in the dictionary and then clear the Txt to Print all currency (Key & Values) again

    ----------------- Else Key Doesn't Exist: add the new (Key and Value) to the dictionary then Update the Txt object with a new line and print the new (Key & Value)

    This is so to avoid updating every tick the Txt object

    Thanks tarek! I figured it out :)

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