[SOLVED]How to add numbers inside a text element
-
Im trying to add numbers previewed in a text element
@Text {
id: sum1
x: 137
y: 389
width: 80
height: 20
color: "#eadfdf"
text: "1"
font.pixelSize: 12
}Text {
id: sum2
x: 137
y: 389
width: 80
height: 20
color: "#eadfdf"
text: "1"
font.pixelSize: 12
}Text {
id: answer
x: 137
y: 389
width: 80
height: 20
color: "#eadfdf"
text: sum1.text + sum2.text
font.pixelSize: 12
}@It gave me a wrong answer,
How can i use text elements to hold my numbers and add them alltogether? -
Hack. :P
text: sum1.text1 + sum2.text1
-
ahh sir, can you please explain to me, what does the * sign stands for?
-
It's just multiplication which forces type conversion to number. :)
-
oh so i can use that if the number is declared, what if the number is from an API storage that had its own value?
-
Did some research... You can also use Javascript's parseInt method:
@text: parseInt(sum1.text) + parseInt(sum2.text)@
-
@//if i change the value of sum2 to a number from a API sotrage
Text {
id: sum2
x: 137
y: 389
width: 80
height: 20
color: "#eadfdf"
text: Storage.getSettingScore("settingScore","valueScore")
font.pixelSize: 12
} @ -
WOW, Thank you man, the ParseInt keyword is the key for my formula, THANKS!!!!!!! :D