Having problems scripting a goal into a text element

I am working on a game idea of my own design, but am having problems getting a goal that is generated in my DieRoll script to go into my text element on my canvas using a script I have dubbed GoalDisplay. The following code only gives me one error that I can’t seem to get past. I have been banging my head on this for a couple of days and am looking for any ideas to help with this. The error I get is a CS1525 error with says that it is looking for a ‘.’ . I am baffled by this. PLEASE HELP!!! Here is the script for GoalDisplay. Thanx!!!

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class GoalDisplay : MonoBehaviour {

public Text gDisplay;

void Start () {
Display(int goalTotal);
}

void Update () {}
void Display(int goalTotal) {

Text gDisplay = GetComponent();
gDisplay.text = DieRoll.goalTotal.ToString();
}
}

Your Start method is calling the Display method but at the same time it is also defining the input argument type of goalTotal which it shouldn’t.

Fixed:

void Start () {
Display(goalTotal);
}
1 Like

please use [code ][/code ] tags when pasting code into the forums, really helps with readability. There is a sticky on them at the top of the scripting forum.

errors have line numbers, please include them, just copy the entire error from the console. Alongside the code tags which also give line numbers we’ll be able to help more readily.

public Text gDisplay;

this is a variable declaration, once done you don’t need to do it again

Text gDisplay = GetComponent<Text>();
// should be
gDisplay = GetComponent<Text>();
// note the lack of type, so it's an assignment, not a declaration

(there are a few cases where you might want to use a local variable of the same name in a different scope, but lets avoid that to start with :smile:)

When you call a function, you don’t need to include the types

Display(int goalTotal);
// should be
Display(goalTotal);
1 Like

Both of you helped get me straightened out. This part is working great…thanx!!!