Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
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.
Develop games in your browser. Powerful, performant & highly capable.
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)
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