Quick question.

For questions about using Classic.

Post » Thu Dec 16, 2010 7:39 am

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





http://www.mediafire.com/?8cgeuk8riec9c1k
B
2
G
2
Posts: 22
Reputation: 694

Post » Thu Dec 16, 2010 9:16 am

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.
B
72
S
15
G
4
Posts: 311
Reputation: 11,609

Post » Thu Dec 16, 2010 11:42 am

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

[code:3lqo2a3s]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]
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

Post » Thu Dec 16, 2010 6:33 pm

Thanks! Pulling the 100 and 10000 out of the integer parenthesis worked.

I knew it was something simple. :p
B
2
G
2
Posts: 22
Reputation: 694


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests