How do I create a buy max option.

Get help using Construct 2

Post » Fri Oct 14, 2016 6:38 pm

I have something that goes

Click on egg to get 1 egg

Buy baby chick for 10 eggs (makes 1 egg per second)

Buy chicken for 100 baby chicks (makes 1 baby chick per second)

Buy pen house for 1000 chickens (makes 1 chicken per second)

and so on...

But very fast I run into a problem where its impossible to spend all my eggs. How would I go about creating a buy max option.
B
3
Posts: 5
Reputation: 185

Post » Fri Oct 14, 2016 6:51 pm

math

...lol

On Buy max button clicked
--Add to "baby chick" floor(eggs/10) (eggs divided by price)
--Subtract from "eggs" floor(eggs/10)*10

Or (if they are sprites not variables)


On Buy max button clicked
-Repeat floor(eggs/10) times
--Create chick
--Subtract 10 from eggs


Floor() simply rounds down. So if you had 95 eggs, floor(eggs/10) would result in 9 (9.5 rounded down)

Edit: Whoops, had some stuff backwards
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Fri Oct 14, 2016 7:04 pm

Edited — had a bunch of mistakes :oops:
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Fri Oct 14, 2016 7:36 pm

Man you make it look easy :p Is there a way I can set it to buy only 10 instead of 10.2454578784?

How long have you been using construct ?
B
3
Posts: 5
Reputation: 185

Post » Fri Oct 14, 2016 7:44 pm

Asmir13 wrote:Man you make it look easy :p Is there a way I can set it to buy only 10 instead of 10.2454578784?

How long have you been using construct ?


My profile says for just over a year—but I think it was a little longer than that. There is a ton I don't know but I just try to answer the questions in areas that I know.

Did you use the floor()? Because floor(10.2454578784) = 10

round() - rounds to nearest integer
floor() - rounds down
ceil() - rounds up

Once you start learning the commonly used expressions and such it will start to snowball. These are a couple pages to visit often:

https://www.scirra.com/manual/126/system-expressions
https://www.scirra.com/tutorials/77/nat ... onstruct-2

Then whenever you use something new to you visit the page in the manual so you know the conditions, actions, and expressions. Things that seem complicated may already be built in—you just have to know what is available
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925


Return to How do I....?

Who is online

Users browsing this forum: dop2000, FacuLNF, Lordshiva1948 and 58 guests