Hi there i have a variable that is a number and i was wondering if i could set multiple text objects to different values in the variable.
For example is the variable is 156 would it be possible to set one text object to the 1 (hundreds value) another to the 5 (tens value) and the last one to the 6... all of the same variable.
you can make it a string (str(var)) and use the mid function to get a specific character
or
calculate the value with math: h=int(var/100), t=int((var-h*100)/10), s=var-h*100-t*10 (in this order)
Develop games in your browser. Powerful, performant & highly capable.
A general mechanism with the mid() expression.
http://www.blackhornettechnologies.com/Construct2Stuff/IntToTextN.capx
tokenat("text", index, separator)
text="1,5,6"
int(tokenat("text", 0, ",")&tokenat("text", 1, ",")&tokenat("text", 2, ","))
One more method! Math based, use modulo (%).
x=156
a=floor(x%10) = 6
b=floor((x%100)/10) = 5
c=floor((x%1000)/100) = 1
But still first method mercury mentioned is probably most straightforward.
mid(str(x),0,1)=1
mid(str(x),1,1)=5
mid(str(x),2,1)=6