Hey there stranger!

Sign up to get access.

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

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 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
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 of cookies per second, end.
00:30 And we can do things like, uhm, click this cookie and it will add one here. It is a drawing that has a script assigned to it.
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.
00:53 Ah, what we're doing, we can't actually just put in a number here. If we click create, we can see that the, count is actually saved not in the cell but in a user property.
01:05 Uhm, once we can buy a cursor, what it does is it sets up a trigger that will trigger every minute to create, uhm, six cookies so that we get 0.1 cookies per second.
01:19 And we can set up a number of these, ah, triggers. They're all individual. And again, we can get to 18.
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
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.
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.
02:08 In the description here on BetterSheets, I will put one, this link to the sheet where you can get the, where you can get the sheet and copy it for yourself and play for yourself if you want.
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.
02:25 But we got to the point where we were building the farm and it was fairly straightforward at that point of how to do it, how to create these sort of automations.
02:33 Uhm, and that's about an hour long video. But in this setup, we, in the function setup, we need to, uh, get people to get to that setup.
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.
02:57 So there is an on edit function here. But if I, I'll show you this issue. If I make a copy.
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 here.
03:19 It's going to, actually I think it hasn't set up the Apps Script yet. Let's see, there's not even a menu here, there it is, there's a menu.
03:31 And it's gonna give us a number error. So what this means is that, actually I'm gonna move this to trash.
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.
03:55 So what that means is we probably can do user property. Here. User properties. If, uhm, I want to get a count.
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.
04:28 So basically, We're going to do what we want. But only if there is an actual count here. Let me format.
04:39 So if there is no count, I want to set this range with, hey, set it up. Make sure to click set up.
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?
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.
05:27 We've got to let it load the Apps Script. So let's may take a moment. We will know the Apps Script has loaded when, uhm, there's the clicker here, or the menu here.
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 a three dot set value, uhm, zero cookies per second.
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.
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 too.
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.
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.
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.
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.
07:46 I'm gonna open Apps Script just in case. So, Oh, we have it set up. Maybe we can also, actually, on open, maybe we can run.
08:00 This as well. So if somebody tries to do that, uhm, count.
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.
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.
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.
09:02 Click set up in cookie clicker menu. Once we set it up. Authorization required. That'll be fine.
09:12 Allow. Shouldn't this A2 be set? Hmm. Hmm. Hmm.
09:44 Set up. Hmm. Or set up and start? Hmm. Cause it needs that authorization first. Alright, that's a bit of a difficult thing to deal with, but it needs set up twice.
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.
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.
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 that's going to trigger every minute, and then it will click a certain number of times, which click, clicking the cookie means it will 
10:52 literally click a cookie and add a cookie. Uh, if we see buy cursor, we are choosing the trigger cursor click, and we're make, making it run every minute.
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.
11:14 We have grandma. We can actually put all these functions together. there. Farm. There. So we have a grandma, a cursor, and a Thank you.
11:32 Farm. And it will run this, uhm, actually I'm going to rename this cursor. So cursor click. This is just cursor.
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.
11:54 And we're also using proper, user properties as I mentioned. We've seen these user properties which is really cool. So what What is all this?
12:02 What allows us to do is, is to save data, text to the spreadsheet without having to put it in a cell.
12:11 So if I click this cookie, it's going to take this number 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.
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.
12:27 Someone can just write in here, two thousand five hundred and sixty-five or two million. So we're saving the number to user property so that we sort of hold it in memory without allowing the user to edit that very easily.
12:45 It's quite hard. You have to do it through Apps Script. So someone who's not technical, ah, will, uhm, not be able to access it.
12:52 Uhm, we, each time we buy something, we'll subtract the number of cookies to, so for cursor we need. We need to get, use 18.
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.
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.
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.
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.
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.
13:58 up, you got to do it twice because you have to do authorization first. Then setup. Uhm, it's just a little weird, but then it works.
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.
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.
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.
14:34 It's pretty cool. I mean, you're able to use user properties and trigger builder. Go check out the YouTube live. We go through it piece by piece.
14:43 Bye.