How do I find an easier way..?

0 favourites
• 7 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
• I'm making a game with a till that you might use in a shop

The till will work out how much change the customer is due and then displays both the number and pictures of the coins that they should receive

I am wondering if there is an easier way to calculate what coins are due rather than 100's of if statements saying:

IF change=1 then create object 1pSprite on layer 0

IF change=2 then create object 2pSprite on layer 0

IF change=3 then create object 1pSprite & 2pSprite on layer 0

IF change=4 then create object 2pSprite & 2pSprite on layer 0

IF change=5 then create object 5pSprite on layer 0

etc...

I have attached a basic capx attempt that will hopefully explain what i mean a little better...

https://www.dropbox.com/s/3mdjl8l0bh6b1jw/visual_change_calc.capx?dl=0

Many thanks

• Some ways of doing it:

1. Have all images as frames of a single sprite and set the frame to changeAmount - 1 (0 for 1, 1 for 2, etc).

2. Load external images and name the files according to the amount of change (1.png, 2.png, etc) then load changeAmount & ".png"

Hope this helps. Cheers!

• Hey Bruno,

However I don't think i've explained myself properly...

The amount of change that a person could receive could potentially be any number between 0.01 (1 pence) and 49.99 (change from a £50 note when buying something for 1pence)

Each number would be represented by a different sprite eg (25pence change would be represented by a sprite of a 20pence and a 5pence) or (60pence change would be represented by a sprite of a 50pence and a 10pence)

So i'm trying to find if there is an easier way of setting this up without having to create an IF statement for every possible combination of change?

• Check this. Not the most elegant way of doing it, but works. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

https://www.dropbox.com/s/nc9kepbrvi0rh ... .capx?dl=1

Cheers!

• Thank you so much Bruno That is a very clever solution that has saved me loads of time!

• Hey mattdaly!

Here's a more elegant solution, using a recursive function... And a lot less events! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

https://www.dropbox.com/s/7i30bij6toxu1 ... .capx?dl=1

Cheers!

• Try Construct 3

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

Construct 3 users don't see these ads
• Wow brunopalermo that's brilliant!

Thanks again...

Matt

• 7 posts