# Money counter

Is there a easy way to make a money counter WITH OUT using python.
For example:

\$12.34 then you collect 5 cents and it added to give you \$12.39

A float displays 6 zeros after the decimal place and an integer dosn’t have decimals. I’ve figured out one way but I would think there is a easier way.

PS. In the middle of learning some basic python but trying to aviod it as this is my first game and I’m trying to keep it as simple as possible.

Cheers

well you could use a simple property to store the value of your money so say when the player gets a message add 5 cents it adds on 5 to the property, im not sure how to do it with decimal points thow.

I would not try and avoid using python. Especially when it can be used to fix something that has you a bit puzzled.

Jump in and fight with the snakes.

you can use a multiple properties for calculation:

“Text” String “” (Output)
“value” Float “0.0” (Input)
“number” Integer “0” (intermediate)
“decimals” Integer “0” (intermediate)

property sensor changed Prop: value (True Pulse)
—> And
-------> Property Actuator Assign Prop:number Value: value
-------> Property Actuator Assign Prop:decimals Value: (value*100)%100
-------> Property Actuator Assign Prop:Text Value: number+"."+decimals

the result to be displayed will be in the string Property Text.

Be aware to have the right Property Types!

Monster

Yes, that would work (If you don’t mind it saying “property” then \$ (or whatever you have it as)

P.s. This is not at all hard to do.

Monster: If I understood correctly I done something simliar. I tried but without success.
a couple of problems If I add 20 cents to 90 cents I get 120 cents(3 decimal places) and it doesnt add one dollar to the dollars. I could work my way around this, but just checking to see if I have it right.

Ive included a blend which has my round about way and monster suggestion(which I couldn’t get to work.)

Cheers.

### Attachments

money counter.blend (562 KB)

I suggest to separate money counting from the display.

These are two different thinks. If you mix them you get complex and hard to read code.
You can separate them by using different objects (recommended), or by using different states (you can have two states active at the same time).
You will see the complex logic will fall into much simpler peaces ;).

• Assigning Value to Value makes not much sense didn’t it? Better assign Value to number (first Property actuator)

• Enter the complete formula in the value field of the second property actuator

• The second actuator should be assign mode. With add you get different results.

• The third property actuator is fine as it is.

• The value in Money.counter.001 does not change. Therefore it does nothing. If you need to display the initial value add an Always sensor (no Pulses) and change the controller to “OR”.

You can add a label or a currency sign just by adding it to the third property actuator or add another one. Example:
------> Property Actuator Assign Prop:Text Value:“label “+Text+” currency units”

Thanks Monster.
Just one problem which is the reason I used my round about way. It displays .01 cents as .1 Any number under 10 cents it displays as a single digit decimal (see picture).

And for some odd reason it skips counting. At .04 cents it loses a cent and then gains it back at .16 cents :eek:

(Value*100)%100 is this line removing decimal places. From my understanding multiply the value by 100 then divide by 100 and displaying the remainder.

Thanks again monster for your help.

### Attachments

good point we need to take the decimals separate

number: Value
decimal1: (Value10)%10
decimal2: (Value
100)%10
Text: number+"."+decimal1+decimal2

Can’t you just use the float value in the property? .160 + .040 = .200? Then when you reach .990+.010 it would just equal 1.000, or 1.00. Or is the extra zero at the end what your trying to avoid?

As far as I know there is no format option in the Python actuator. The default format of float has 6 decimal places. Currencies are usually not expressed with such a precision ;).