Discuss Scratch

bongolol
Scratcher
6 posts

Cookie Clicker Type Game

Im trying to code a type of golden cookies system in my game but idk how to make it so they just appear randomly
PhiPhenomenon
Scratcher
500+ posts

Cookie Clicker Type Game

Here's some base code that you can use:
hideforeverwaitpickrandom30to60secsgotorandom positionshowwaituntilmousedown?andtouchingmouse-pointer?hidechangecookiesby1000
The golden cookie appears 30 to 60 seconds at a time. Then it waits until the player clicks it and awards a certain number of cookies.

Last edited by PhiPhenomenon (Jan. 4, 2024 23:39:00)

EDawg2011
Scratcher
1000+ posts

Cookie Clicker Type Game

Is this good?

whenclickedforeverwaitpickrandom60to240secsshowsetrandomtopickrandom-100to100gotox:randomy:180glide3secstox:randomy:-180hide
PhiPhenomenon
Scratcher
500+ posts

Cookie Clicker Type Game

EDawg2011 wrote:

Is this good?

whenclickedforeverwaitpickrandom60to240secsshowsetrandomtopickrandom-100to100gotox:randomy:180glide3secstox:randomy:-180hide
This solution does not detect if the golden cookie has been clicked, nor does it add cookies to the total count.
p-p-p-p-p-p-p-p-p-p-
Scratcher
1000+ posts

Cookie Clicker Type Game

PhiPhenomenon wrote:

This solution does not detect if the golden cookie has been clicked, nor does it add cookies to the total count.
The method you provided actually also does not detect is the golden cookie has been clicked - it detects whether the mouse was down and touching it. Therefor, if a player had their mouse down somewhere, and the cookie fell on it, it would be triggered, even though the mouse did not actually click the cookie.

EDawg2011 wrote:

Is this good?

whenclickedforeverwaitpickrandom60to240secsshowsetrandomtopickrandom-100to100gotox:randomy:180glide3secstox:randomy:-180hide
This also does not help because now, the user can click the cookie multiple times.
a truly perfect script for a golden cookie would be something like this:
whenclickedforeverhidewaitpickrandomxtoysecsgotorandom positionsetclicked?to0 Preferably a variable set to "This sprite only", to reduce clutter, but it does not matter.broadcaststart animationresettimershowwaituntiltimer>10orclicked=1 waits 10 seconds to be clicked before hiding whenthisspriteclickedsetclicked?to1performgoldencookieactionherewhenIreceivestart animationrepeatuntiltimer>10orclicked=1performanimationhere
At least, that's how I would approach the problem.

Last edited by p-p-p-p-p-p-p-p-p-p- (Jan. 5, 2024 00:09:56)

PhiPhenomenon
Scratcher
500+ posts

Cookie Clicker Type Game

p-p-p-p-p-p-p-p-p-p- wrote:

The method you provided actually also does not detect is the golden cookie has been clicked - it detects whether the mouse was down and touching it. Therefor, if a player had their mouse down somewhere, and the cookie fell on it, it would be triggered, even though the mouse did not actually click the cookie.
That issue is relatively minor due to the low chance of that happening. Anyway, it can be easily fixed by adding a single block:
hideforeverwaitpickrandom30to60secsgotorandom positionshowwaituntilnotmousedown?andtouchingmouse-pointer?waituntilmousedown?andtouchingmouse-pointer?hidechangecookiesby1000
p-p-p-p-p-p-p-p-p-p-
Scratcher
1000+ posts

Cookie Clicker Type Game

PhiPhenomenon wrote:

p-p-p-p-p-p-p-p-p-p- wrote:

The method you provided actually also does not detect is the golden cookie has been clicked - it detects whether the mouse was down and touching it. Therefor, if a player had their mouse down somewhere, and the cookie fell on it, it would be triggered, even though the mouse did not actually click the cookie.
That issue is relatively minor due to the low chance of that happening. Anyway, it can be easily fixed by adding a single block:
hideforeverwaitpickrandom30to60secsgotorandom positionshowwaituntilnotmousedown?andtouchingmouse-pointer?waituntilmousedown?andtouchingmouse-pointer?hidechangecookiesby1000
That still has the same problem. The reason I know this is because I coded SWEATFit, which is a very complicated project with a lot of different assets, and one of the things I tried doing was adding buttons like this. But you can swipe them.
I edited my original post with a foolproof solution, with no edge cases.
bongolol
Scratcher
6 posts

Cookie Clicker Type Game

Thank you so much everyone! All this really helped!

Powered by DjangoBB