Author Topic: display variables in labels?  (Read 5988 times)

amaranth

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
display variables in labels?
« on: July 05, 2012, 07:58:19 PM »
Anyone know how I would do the following? I'd like to display the following type of string in a label:

Mix [ingredient 1], [ingredient 2], and [ingredient 3] in a [container type] and stir with a spoon [amt] times.

Should I be using something other than a label for this? I saw the option to change text color, but I'm not sure how to do anything more advanced. Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: display variables in labels?
« Reply #1 on: July 05, 2012, 08:17:01 PM »
You have to do it before assigning the text value of the label.

dlewis

  • Guest
Re: display variables in labels?
« Reply #2 on: July 05, 2012, 09:59:13 PM »
Use string.format and you'll be set

psudo code
  1. label.text = string.format("Mix {0}, {1}, and {2} in a {3} and stir with a spoon {4} times.", ingredient1.ToString(), ingredient2.ToString(), ingredient3.ToString(), containerType.ToString(), armt.ToString());

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: display variables in labels?
« Reply #3 on: July 05, 2012, 11:18:39 PM »
No need to ToString() any of that btw.

dlewis

  • Guest
Re: display variables in labels?
« Reply #4 on: July 06, 2012, 01:12:52 AM »
haha you're right. I remember when I was writing that I didn't have any ToString and then I thought "What am I doing!?" and added them in. I hate it when I lose track of what I'm doing.