Split numbers into single digit value holders

Discussion and feedback on Construct 2

Post » Sun Jun 18, 2017 2:11 pm

For example 36 would be split into a 3 in the tens place and a 6 is the ones place. Is there anyway simple to do this? I figured out how to do it with while loops and stuff but I'm wondering if there's an easier way to do it
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Mon Jun 19, 2017 11:20 am

You can divide it by 10 and then save it as integer to get the first digit(10). Then you can divide it again by 10 using modulo division to get the second digit(6). If the number is bigger then you can increase the division to get the other digits to 100, 1000, 10000 etc.
Like my work? Fallow me on social media, and see my games on the arcade.
B
7
S
5
G
9
Posts: 298
Reputation: 5,357

Post » Mon Jun 19, 2017 5:41 pm

Let´s do it the easy way: tokenat!

tokenat(str(number), 0, "")

The number has to be converted to a string with 'str(1234)'
If you have variable lenghts of numbers you probably want to make use of tokencount and loopindex.

See: https://www.scirra.com/manual/126/system-expressions
B
15
S
3
Posts: 62
Reputation: 989


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests