SCORE CARD Calculations

@fuerte.francis
I’ve tried that but it gives me the following errors:

  1. Consecutive declarations on a line must be separated by ‘;’
  2. Expected ‘(’ in argument list of function declaration
  3. Expected ‘{’ in body of function declaration
  4. Expected “func” keyword in instance method declaration
  5. Expected declaration
    Invalid redeclaration of 'tm1Score()

and I have NO CLUE what all these mean my friend (lol)

then just put

tm1Score.text = “((num1+num2))”

inside your ibaction (t1TriesButton)

Mark @FoundationSW,
Any further suggestions mate…?
I’m currently working through your earlier comments and would appreciate any assistance please

Hi,

Have you gone through Chris’ Fundamentals course on YouTube or the CodeWithChris site? I would REALLY recommend that you look into that first before you attempt to code your project.

It seems Francis answered you question about how to sum the two variables, if you want the sum when the app loads, place his line of code in the viewDidLoad, and if you want it updated each time you tap on one of the buttons, just place his line of cade as the last line in the button @IBAction.

In terms of the errors you received, I want to again encourage you to check out the fundamentals course so you can understand how Swift code and your complier in Xcode work together.

Blessings,
—Mark

Mark @FoundationSW

I have been through the Tutorials, plus several others, over the past week

Being New, i sort of understand What you refer to, but seems more WHERE to put the code that’s the issue, so I’m working on Trial-&-Error at this point.

I’m not sure if this CODE is ONE Section, or what part of (if any) needs to be under the VC (above override), or at the Button i’m trying to action (t1Score), at the individual Buttons (t1Tries/t1Conv) and/or the bottom.

I will continue to work through the issue, greatly appreciate the support, and keep you updated

Thanks :+1::+1:

Mark @FoundationSW
Im stuck on this error :frowning:
whereaever I try and load "t1Tries.Label.text, i get - “Cannot use instance member ‘t1TriesLabel’ within property initializer; property initializers run before ‘self’ is available”

its probably not added correctly (the connection/outlet)… check if the circle thing beside the line numbers are shaded, if its shaded then it means the connection is correct, if not then there was something wrong with the connection and you need to check your outlets

@fuerte.francis

The Individual Sections are all working correctly (individually), and “shaded”

These/Each “Section” has a “Plus Button”
@IBAction func t1TriesPlus(_ sender: UIButton) {
num1+=1; t1TriesLabel.text = “(num1)” }

As well as a “Minus Button”
@IBAction func t1TriesPlus(_ sender: UIButton) {
num1+=1; t1TriesLabel.text = “(num1)” }

With and Associated UILABEL
@IBOutlet weak var t1TriesLabel: UILabel!
var num1 = 0

These individual “sections” (5 in total) works fine and adds as required.

Seperate to this is a “Total Score” UILabel, which is the issue and where I want to sum the totals of all the sections…
@IBOutlet weak var tm1Score: UILabel!

THIS IS WHERE IM STUCK :weary:

is this shaded? if its not then check your outlets on your storyboard

Yes it is @fuerte.francis

check an organize your code, make sure there are no double declarations including same named functions.

once that is sorted out then just try to set your tm1Score again to

tm1Score.text = String(num1+num2)

Francis @fuerte.francis
As much as I appreciate all the advise my friend, you seem to be stuck on One Action, which I have tried more than once, while Not Reading my Updates nor addressing my questions.
Thanks anyway, but (1) I do not have double declarations and (2) have checked that all Outlets & Buttons are working (WHICH IS NOT THE ISSUE)

(3) tm1Score.text = String(num1+num2) give me errors (mentioned above) and does not work, so unless you have another suggestion, I accept you don’t know either :+1:

Ok so as you can see from the attached playground pic, if you are getting errors where you are trying to assign tm1Score.text, then there is something wrong with your declarations as the provided code works. From some of the errors you have pasted it seems to me that your declarations are all over the place.

Think about it. You are currently setting your labels using the code label.text = “(num1)” which is the same as label.text = String(num1). The inference is that you are asking swift to cast from integer to string. This is obviously working correctly as you have said. So then if your code where you are trying to set your total score is not working ie totalScore.text = String(num1 + num2), then you have a declaration issue. You should go back over your code. For instance try setting your total score label to any old string like “Hello World”. If that doesn’t work then you know you have an issue with your declaration of the IBOutlet.

The issue has been sorted with Code through a 3rd Party,
Thank for the advice

Well what was the solution? We would also like to know.

Richard @dracosveen

No problem, but before we get to the solution I want to touch onto the “problem” as as much as I was inspired by @CodeWithChris, this forum was rough on my experience - I have Never Coded before, this was my first attempt, and my aim was just to create an App for myself, but will agree that I did not start with anything simple…

As much as All the Advise was probably good, as a Raw Rookie I did not understand most of it, although to be fair I did not work through your suggestions as I was busy with someone else. MORE THAN ONCE I asked more WHERE to put the Code as to What the Code Should be, and the advise was blunt and completely unrelated, with the exception to Mark @FoundationSW. #RantOver

THE SOLUTION:

  1. Under the ViewController:
    let TRIES = 5
    var t1Tries = 0

  2. The Rest of my Code, as was, followed with resFreshScores() in each (+/-) button.

Fairly simple once I knew where what was going.

Regards

What you need to understand is that “where to put the code” is not a relevant critique as we did not have access to you complete project therefore showing you where to put the code is difficult.

Secondly if you are not going to work through not only the playground code I provided or the github solution I provided, then I feel you don’t have a leg to stand on.

But that is neither here nor there. My question is, have you learnt what your problem was and do you understand the solution or have you just copied and pasted something…if you didn’t learn anything then your experience is just going to get rougher.

Thanks Richard @dracosveen, noted
As mentioned, I did not use your advise and the #Rant was not aimed at anyone, rather a a suggestion to read the POST and Reply relevant to the “Whole Post”, its not just about the code…

And yes, I did learn,
Thanks again :+1: