How do I use an array to store a string/variable combination?

Not favoritedFavorited Favorited 0 favourites
  • 6 posts
From the Asset Store
Over 2700 files with all the colour combinations from a 15 colours palette!
  • I have a tooltip window that pulls a description from an array depending on which upgrade button the mouse is hovering over. I'd like to combine variables with the text so that different values can be returned however I seem to only be able to return a string.

    For example, if I had two variables, var_damage and var_duration, and wanted the text to say "Fireball does 5 damage over 10 seconds" I'd set the text to something like -

    "Fireball does "&var_damage&" damage over "&var_duration&"seconds"

    However if I store it in an array and use ARRAY.at(x,y) to retrieve it then it comes out looking like the text above and doesn't insert the variable values.

    Is there a way to do store/retrieve this info from an array so it reads correctly?

    Thanks!

  • I've managed this before by using Replace(), check the manual. So if you say "Fireball does %dam% damage" in the array, on the mouseover/set text events you can replace %dam% with the damage variable.

  • I've managed this before by using Replace(), check the manual. So if you say "Fireball does %dam% damage" in the array, on the mouseover/set text events you can replace %dam% with the damage variable.

    That's a good suggestion. It won't really work for how I've set things up though, I'd need to create events for every different description which is what I was trying to avoid. It would be nice if there was a feature to turn a string from an array back into code.

    I'll keep this method in mind for my next game, thanks!

    Edit: I stumbled across stringsub() thanks to your suggestion. Again, it would work the same as your replace method but might be a bit easier to manage. I might give it a go. Thanks again.

  • You only need one action per replaced string (set text to replace it) but not one event per description

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah but it'll get messy with many different descriptions using many different variables. I'd have to add in events that check which description and what variables to substitute for each one.

  • When you said you mouseover the button and pull the description from the array then it should be simple no ? Or how are you reading the array ? If they are global variables it should be easy.

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