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
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!)
Code:
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!)
Last edited by a moderator: