Coding A Cookie Clicker like App?

Discussion in 'iOS Programming' started by antrovira, May 16, 2015.

  1. antrovira, May 16, 2015
    Last edited by a moderator: May 18, 2015

    antrovira macrumors newbie

    May 16, 2015
    ok, so my problem is that I'm attempting to put to use some of the things i've learned in this Xcode tutorial to use. I'm trying to make a cookie clicker clone sort of, with the basic functionality that it will keep track of how many times you click the button. so what I have so far is I've gotten the label to change based on how many times I click the button. Now I have 2 problems, but this is my first time posting here, so i will only address one issue at a time. My first issue is getting the app to have upgrades. but I have the issue, that I'm not sure how to go about making and upgrade, even as simple as doubling the cookies per click. here is my code:import UIKit

    class ViewController: UIViewController {
        var numberofclicks = 1
        @IBOutlet var score: UILabel!
        @IBAction func clicks() {
            score.text = "\(numberofclicks++)"
    func viewDidLoad() {

    there is a button, which is connected to the IBAction, and a label, which is connected to the outlet. I want to add a third button that would add an upgrade. Now i'm not quite sure, as I said, how I would go about adding an upgrade. I want to make it so that the cookies double per click, but I'm not sure, do I need to make numberofclicks++ into a variable somehow so I can double it later on? and how would i connect one button to the other button so that when i click the upgrade button it changes the code of the other button so that it subtracts from the score and then makes it lets say, 2 cookies per click instead of 1? any ideas? (I'm not sure if I'm allowed to add two topics so ignore this if I'm not allowed to, but how do i also get the game to save score after closing it? nobody would want to play a game that doesn't save your score and you have to restart every single time. remember this is just for a project for myself, and I'm a beginner so try to explain things clearly please!) :)
  2. VolceOntra, May 16, 2015
    Last edited by a moderator: May 18, 2015

    VolceOntra macrumors 6502


    Apr 25, 2007
    I'm not totally sure what you are trying to do... But if you are trying to double the number you could just multiply your variable by 2.

    You can as many as variables and use booleans to see if they upgrade is in place or not... Hope that helps. Feel free to pm me.
  3. antrovira, May 16, 2015
    Last edited by a moderator: May 18, 2015

    antrovira thread starter macrumors newbie

    May 16, 2015
    in kinda new here, but Ok, so I have an idea. However I still have one question, where I wrote in my code "\(numberofclicks++)" when I set a variable with two plus signs next to each other, this stands for something, but I forgot what? It stands for like the variable = the variable plus itself or something like that, could you help me here?
  4. Punkjumper macrumors member

    Jan 12, 2013
    You answered your own question. Instead of using ++ to increment your variable create another variable to hold the incrementation value. It could be a positive or negative number. Your third button could set the incrementation value.

    For saving read up on persistence. There are tons of great articles out there and many ways to go about it.
  5. mds1256 macrumors regular

    Apr 9, 2011
    It first returns the original number of the variable and then increments it by 1.

Share This Page