Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Built a Cookie Clicker Clone in Google Sheets

About this Tutorial

I built a clone of Cookie Clicker, live on YouTube. Watch the full 1 hour live stream here.

In this video I update it a bit, and show off that it works!! 

Learn how to build trigger builders and use user properties to store data you don't want a user to change (easily)

Video Transcript

<div>00:00 So we've cloned Cookie Clicker inside of a Google Sheet. We can buy Cursor Grandma or Farm. If you are unfamiliar with Cookie Clicker, it is a game where Learn how to filter data using the query where clause in Google Sheets. Opens in new tab you click a cookie and once you get a few cookies you can buy things like a cursor that will automatically click a or a grandma who will automatically<br>00:20 click a cookie one per second. And I recreated this in Google Sheets. So we have a cookie, we have a counter, number Understand how to work with numbers in Google Sheets effectively. Opens in new tab of cookies per second, end.<br>00:30 And we can do things like, uhm, click this cookie and it will add one here.

It is a drawing Discover how to use drawings in Google Sheets for interactive elements. Opens in new tab that has a script assigned to it.<br>00:42 Let's get to 18 and I'll show you. Ah, just bear with me as I click this cookie over and over and over again until we get to 18.<br>00:53 Ah, what we're doing, we can't actually just put in a number Understand how to work with numbers in Google Sheets effectively. Opens in new tab here.

If we click create, we can see that the, count is actually saved not in the cell but in a user property.<br>01:05 Uhm, once we can buy a cursor, what it does is it sets up a trigger Explore how to set up triggers in Google Sheets to automate tasks. Opens in new tab that will trigger Explore how to set up triggers in Google Sheets to automate tasks. Opens in new tab every minute to create, uhm, six cookies so that we get 0.1 cookies per second.<br>01:19 And we can set up a number Understand how to work with numbers in Google Sheets effectively. Opens in new tab of these, ah, triggers. They're all individual. And again, we can get to 18.<br>01:29 And we're going to buy another one. Another cursor that is going to add one to, let's see, here.

Uhm, and in this video, I want to make a few changes and edits and make this a little bit better for someone who's starting out who doesn't necessarily know Cookie Clicker itself and doesn't know to go to<br>01:52 this menu and set up. But what you actually have to do is once you make a copy, you have to set up Cookie Clicker, which will set up your user property.<br>02:01 Let's look at the code a little bit because I think it has a few interesting things.

I did this live on YouTube, by the way.<br>02:08 In the description here on BetterSheets, I will put one, this link to the sheet where Learn how to filter data using the query where clause in Google Sheets. Opens in new tab you can get the, where Learn how to filter data using the query where clause in Google Sheets. Opens in new tab you can get the sheet and copy it for yourself and play for yourself if you want.<br>02:17 Or, uhm, and I will also put the YouTube. It was about an hour long and I got cut off.

My power went out actually while I was recording.<br>02:25 But we got to the point where Learn how to filter data using the query where clause in Google Sheets. Opens in new tab we were building the farm and it was fairly straightforward at that point of how to do it, how to create these sort Find out how to sort data in Google Sheets for better organization. Opens in new tab of automations.<br>02:33 Uhm, and that's about an hour long video. But in this setup, we, in the function Get to know functions in Google Sheets and how to use them. Opens in new tab setup, we need to, uh, get people to get to that setup.<br>02:47 So, what happens is there is an onedit. That's actually really cool. Basically, this on anytime I edit this it will reset it.<br>02:57 So there is an on edit function Get to know functions in Google Sheets and how to use them. Opens in new tab here. But if I, I'll show you this issue.

If I make a copy.<br>03:06 Let's make a copy. And I don't necessarily know, maybe, maybe I'm using this without knowing how to use it. Uhm, and I'm just gonna enter a number Understand how to work with numbers in Google Sheets effectively. Opens in new tab here.<br>03:19 It's going to, actually I think it hasn't set up the Apps Script Dive into Google Apps Script to enhance your Sheets functionality. Opens in new tab yet. Let's see, there's not even a menu here, there it is, there's a menu.<br>03:31 And it's gonna give us a number Understand how to work with numbers in Google Sheets effectively. Opens in new tab error Learn about common errors in Google Sheets and how to fix them. Opens in new tab . So what this means is that, actually I'm gonna move this to trash.<br>03:39 What it means is that, uhm, we need on this unedit to check if we've done the setup yet.

And if not, we should prompt the person to, uhm, and go and set it up.<br>03:55 So what that means is we probably can do user property. Here. User properties Understand user properties in Google Sheets for data storage. Opens in new tab . If, uhm, I want to get a count.<br>04:15 So I'll actually put this up here. That should work there. If no count, then do something else. We're going to do what we want to do.<br>04:28 So basically, We're going to do what we want. But only if there is an actual count here. Let me format Master formatting techniques to make your Google Sheets visually appealing. Opens in new tab .<br>04:39 So if there is no count, I want to set this range Learn about ranges in Google Sheets and how to manipulate them. Opens in new tab with, hey, set it up.

Make sure to click set up.<br>04:54 in set up clicker in cookie clicker menu in cookie clicker menu. There. So now, if I don't, now it'll work, right?<br>05:15 If I do this, it will still work. It is still working. But if I make a copy, I'll make a copy and And let's see if it works.<br>05:27 We've got to let it load the Apps Script Dive into Google Apps Script to enhance your Sheets functionality. Opens in new tab . So let's may take a moment.

We will know the Apps Script Dive into Google Apps Script to enhance your Sheets functionality. Opens in new tab has loaded when, uhm, there's the clicker here, or the menu here.<br>05:41 Oh, and we should probably reset the, uhm, second thing, this cookies per second as well so if it's not get range Learn about ranges in Google Sheets and how to manipulate them. Opens in new tab a three dot set value, uhm, zero cookies per second.<br>06:11 Capitalize. Let's save that. Okay, so now we have this. It looks like the menu has been loaded, but it says forty-three and point two.<br>06:23 It will, it will probably reset everything so most people, it, click it, it'll say one.

But let's say I try to change this I'm like oh, this number Understand how to work with numbers in Google Sheets effectively. Opens in new tab too.<br>06:35 Ah, we need to widen this, make sure. Or, we can just make this click set up. Just say click, click set up in cookie clicker menu.<br>06:52 In cookie clicker Menu. 1, 2, 3, 4, 5, 6, 7, 8, that's 9 words! Click set up. So, let's just say click set up in cookie clicker menu and let's make sure that it actually says that.<br>07:10 Set up. Set up. Cookie clicker menu. Perfect.

Save that refresh and let's trash this so now because I have set it up before, it doesn't say that yet.<br>07:36 And the only way I can do this is, hey, file, make a copy. Let's try this again. Let's see if it works.<br>07:46 I'm gonna open Apps Script Dive into Google Apps Script to enhance your Sheets functionality. Opens in new tab just in case. So, Oh, we have it set up. Maybe we can also, actually, on open, maybe we can run.<br>08:00 This as well. So if somebody tries to do that, uhm, count.<br>08:14 So let's add this. If count to on open. And let's see if that works.

So it'll create the menu, and then if the count doesn't exist, uhm, else, it will it'll do nothing.<br>08:33 So if the count doesn't exist, it will do these resets. That might be cool. That might be better than making sure that the user actually edits.<br>08:43 Let's see. Edit. Hmm. It's not doing it. Hmm. There it is. Okay. It just was, it just was slow. I don't I guess.<br>09:02 Click set up in cookie clicker menu. Once we set it up. Authorization required Understand when authorization is required in Google Sheets. Opens in new tab . That'll be fine.<br>09:12 Allow. Shouldn't this A2 be set? Hmm. Hmm. Hmm.<br>09:44 Set up. Hmm. Or set up and start? Hmm.

Cause it needs that authorization Explore the authorization process for Google Sheets functionalities. Opens in new tab first. Alright, that's a bit of a difficult thing to deal with, but it needs set up twice.<br>09:59 Okay, Maybe we just say that. Click set up twice. That's gonna be weird. Okay, cause authorize, you gotta authorize it first and then do it.<br>10:18 Alright, well that's weird, but this is what it's doing. We are adding these as we go. If we, we can now buy a grandma, uhm, and it's gonna re, minus 100 from here, but it'll add now one cookie per second.<br>10:31 What it's actually doing is very interesting.

You can go in and read the code, but we are building triggers. So every time we buy something, we're creating a trigger Explore how to set up triggers in Google Sheets to automate tasks. Opens in new tab that's going to trigger Explore how to set up triggers in Google Sheets to automate tasks. Opens in new tab every minute, and then it will click a certain number Understand how to work with numbers in Google Sheets effectively. Opens in new tab of times, which click, clicking the cookie means it will&nbsp;<br>10:52 literally click a cookie and add a cookie. Uh, if we see buy cursor, we are choosing the trigger Explore how to set up triggers in Google Sheets to automate tasks. Opens in new tab cursor click, and we're make, making it run every minute.<br>11:07 So let's look at cursor click. Literally it's going to click a cookie six times. Farm is going to click a cookie 480 times.<br>11:14 We have grandma.

We can actually put all these functions Get familiar with various functions available in Google Sheets. Opens in new tab together. there. Farm. There. So we have a grandma, a cursor, and a Thank you.<br>11:32 Farm. And it will run this, uhm, actually I'm going to rename this cursor. So cursor click. This is just cursor.<br>11:43 That'll be more specific. That'll be easier to know. Uhm, we can run the setup. And it'll delete all those triggers that exist.<br>11:54 And we're also using proper, user properties Understand user properties in Google Sheets for data storage. Opens in new tab as I mentioned. We've seen these user properties Understand user properties in Google Sheets for data storage. Opens in new tab which is really cool.

So what What is all this?<br>12:02 What allows us to do is, is to save data Learn how to manage and analyze data in Google Sheets. Opens in new tab , text to the spreadsheet Discover the basics of spreadsheets and how to use them effectively. Opens in new tab without having to put it in a cell.<br>12:11 So if I click this cookie, it's going to take this number Understand how to work with numbers in Google Sheets effectively. Opens in new tab and add one. That's what I did to start it off with. And that's what you'll see in the video if you watch the YouTube live video.<br>12:19 Uhm, I have a link here to it if you want to see it. The very first thing we do is like, this is very unsafe.<br>12:27 Someone can just write in here, two thousand five hundred and sixty-five or two million.

So we're saving the number Understand how to work with numbers in Google Sheets effectively. Opens in new tab to user property so that we sort Find out how to sort data in Google Sheets for better organization. Opens in new tab of hold it in memory without allowing the user to edit that very easily.<br>12:45 It's quite hard. You have to do it through Apps Script Dive into Google Apps Script to enhance your Sheets functionality. Opens in new tab . So someone who's not technical, ah, will, uhm, not be able to access it.<br>12:52 Uhm, we, each time we buy something, we'll subtract the number Understand how to work with numbers in Google Sheets effectively. Opens in new tab of cookies to, so for cursor we need.

We need to get, use 18.<br>13:04 Uhm, if the count is less than zero, like if we try to buy it and it's less than zero, it just won't buy.<br>13:14 You don't have enough, it'll give you this message you don't have enough cookies to buy, uhm, a cursor. So, let's make sure.<br>13:27 Oh, I think I think I didn't update the farm, that's. The farm won by a farm. Now it's updated. Alright, so we've updated it since the end of the live stream.<br>13:41 It's a little bit better and this is for BetaSheet members.

I hope you will be able to go and play Cookie Clicker and let me know if you have any questions.<br>13:50 Feel free to read the script. Uh, you can copy the sheet, try it yourself, open it up, click Cookie Clicker menu, setup.<br>13:58 up, you got to do it twice because you have to do authorization Explore the authorization process for Google Sheets functionalities. Opens in new tab first. Then setup.

Uhm, it's just a little weird, but then it works.<br>14:08 You can click 18 times and buy a cursor, come back, you know, maybe a few minutes later, or keep clicking, buy a grandma, get it going.<br>14:18 I think in the video on YouTube I did a really, a lot, and it was going pretty fast. A few hundred every few moments.<br>14:26 All right, this is Cookie Clicker in a Google Sheet. And yeah, we made a pretty rudimentary cookie. A rudimentary version of it, but it works.<br>14:34 It's pretty cool. I mean, you're able to use user properties Understand user properties in Google Sheets for data storage. Opens in new tab and trigger Explore how to set up triggers in Google Sheets to automate tasks. Opens in new tab builder. Go check out the YouTube live.

We go through it piece by piece.<br>14:43 Bye.</div>