Quick question.

This forum is currently in read-only mode.
From the Asset Store
A challenging game that needs quick responses!
  • First of all, this seems like a really basic question. I searched the wiki and the forums, but couldn't find an answer, though I'm sure it's there somewhere. :S

    I'm having trouble with the math. My event looks like this:

    Every tick -> Set variable totalmoney to int(global('Bronze'))+int(global('Silver')*100)+int(global('Gold')*10000)

    The purpose of this is so that the silver and gold coins are worth more than the bronze ones, but no matter what I do, I can't get construct to multiply int(global('Silver') or Gold by anything. It keeps returning the total of the coins instead of the sum of their values. I've tried using int() around the 100 and 10000, I've tried float(), I've even tried making new global variables that are always equal to 100 and 10000 but construct just won't multiply.

    tl;dr: If I put 1 into the "bronze", "silver", and "gold" editbox, I want it to equal 10101, but I can't get it to equal anything other than 3.

    Below are screenshots and the .cap

    <img src="http://i6.photobucket.com/albums/y246/Yank1234/construct1.jpg">

    <img src="http://i6.photobucket.com/albums/y246/Yank1234/construct2-1.jpg">

    http://www.mediafire.com/?8cgeuk8riec9c1k

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • the right way to do it should be "int(value) * 100 + int(value2) * 10 000 + int(val3)". In math, the multiplications are done before the additions. This calculation will first find the result for each member and then add them.

  • Valerien is right, but the order is ok anyway. Your problem was with the multiplications being inside the global variables parenthesis :

    Every tick -> Set variable totalmoney to int(global('Bronze'))+int(global('Silver')*100)+int(global('Gold')*10000)[/code:3lqo2a3s]
    
    Should be  :
    
    [code:3lqo2a3s]int(global('Bronze')) + int(global('Silver')) * 100 + int(global('Gold')) * 10000[/code:3lqo2a3s]
    
    or if you want to really separate everything :
    
    [code:3lqo2a3s]int(global('Bronze')) + (int(global('Silver')) * 100) + (int(global('Gold')) * 10000)[/code:3lqo2a3s]
  • Thanks! Pulling the 100 and 10000 out of the integer parenthesis worked.

    I knew it was something simple. :p

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)