0 Favourites

How do I get the digits of a value from global variable.

  • I need to get them separetly to insert the number in the Variables Digit1, Digit2 and Digit3. However, I have no clue how to do that.

    Could someone enlighten me?

  • if you have a

    global number MyNumber = 123456[/code:3vjecb8n]
    
    For any digit n (counting from 0) from the right the formula would be:[code:3vjecb8n]floor(MyNumber/10^n)%10[/code:3vjecb8n]
    
    for example:[code:3vjecb8n]floor(MyNumber/10^0)%10  -> 6
    floor(MyNumber/10^1)%10  -> 5
    floor(MyNumber/10^2)%10  -> 4
    ... etc[/code:3vjecb8n]
  • Yann

    Could you please, explain me what these operators does(^, %)?I just know what floor expression does. I'm looking at the tutorials but I couldn't understand.

    Thank you for your attention.

  • ^ is the exponent operator

    10^0 = 1
    10^1 = 10
    10^2 = 100
    etc...[/code:nisj0wkv]now in the formula, the / 10^n just set the digit you want to be the first digit.
    
    % is the modulo operator
    It's formal definition would be that it's the remainder of the euclidean division of two numbers
    for example: [code:nisj0wkv]5 : 3 = 1 with remainder 2[/code:nisj0wkv]
    If you don't like this explanation you can also look at how it behaves according to different input to get a feel for it (after all we're not mathematicians)
    for example:[code:nisj0wkv]0%3 = 0
    1%3 = 1
    2%3 = 2
    3%3 = 0
    4%3 = 1
    5%3 = 2
    6%3 = 0
    etc.
    (see how things cycle?)[/code:nisj0wkv]now in the formula, the % 10  just gives you the first digit of any number
  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Yann

    I got it. Man, I love you. That's so cool!

    Now i'm going to see how I'll put this into my event sheet.

    Yes, I'm not a mathematician, I'm a grafic designer with an old passion to make my own game.

    Thank you a lot, man. I'm very grateful.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,130
karshinkoff's avatar
karshinkoff
Unread hot topic
102 6,400
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
56 4,727
MPPlantOfficial's avatar
MPPlantOfficial