#Lemon Score Manager Thread
1 messages · Page 1 of 1 (latest)
im not a genius like all of you guys so yes
you dont have to be to understand what digis saying lol
I'm not asking you to be a genius. I'm asking you to be able to string words together into a single coherent thought
hes breaking it down for a beginner
By asking you why you have that variable, my intent was to have you look at your code and consider the reasoning behind it being there and wonder if it had to be there at all. I see now this sort of self-reflection is beyond you
So I am now telling you to delete it
ok ima do it
throw in your updated code here too once you finish
Yes. There will be errors at first because we're not done yet
But share them anyway
{
public Score script;
public float moneypersecond;
public float Moneyperupgrades;
void Update()
{
+= moneypersecond * Time.deltaTime;
int integerPart = Mathf.FloorToInt(=);
// add the integer piece to our score.
script.score += integerPart;
// we have consumed that amount from this script
-= integerPart;
}
public void Addscore()
{
if (script.score >= 100)
{
script.score -= 100;
moneypersecond += Moneyperupgrades;
}
}
}``` deleted it
Now finish deleting it did you literally just leave the lines there without the variable in them
delete all of it
Nothing. Delete them
oh ok
public class scorepersec : MonoBehaviour
{
public Score script;
public float moneypersecond;
public float Moneyperupgrades;
void Update()
{
}
public void Addscore()
{
if (script.score >= 100)
{
script.score -= 100;
moneypersecond += Moneyperupgrades;
}
}
}```done
{
public int score;
public Text scoretext;
public Button Upgrade1;
public int Upgradeperclick = 0;
// Start is called before the first frame update
void Start()
{
Button upbtn = Upgrade1.GetComponent<Button>();
upbtn.onClick.AddListener(TaskOnClick);
}
// Update is called once per frame
void Update()
{
scoretext.text = score.ToString();
}
public void Addscore()
{
score += 1 + Upgradeperclick;
}
void TaskOnClick()
{
if (score >= 100)
{
score = score - 100;
Upgradeperclick += 1;
}
}
}```
Okay, first question: Why are you referencing Upgrade1 here
What is the purpose of setting the on click here
no purpose since this button is gone now
Okay so remove it and everything involved with it
{
public int score;
public Text scoretext;
public int Upgradeperclick = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
scoretext.text = score.ToString();
}
public void Addscore()
{
score += 1 + Upgradeperclick;
}
void TaskOnClick()
{
if (score >= 100)
{
score = score - 100;
Upgradeperclick += 1;
}
}
}```
ima reame upgradeperclikc
Thats not what was asked
its the amount of score you get when you click the button
Why
What button
This isn't a button
Why are we talking about buttons
this is your score manager script
Shouldn't be on this script
So that'll be a third script to make down the line but it shouldn't be on this one
This script is solely responsible for tracking score and displaying it
okay
Show it when it's done
{
public int score;
public Text scoretext;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
scoretext.text = score.ToString();
}
}```
Good. Now that all of the pointless things have been removed from both scripts, we can truly begin. First, that score, since it's ticked up per second and you want to have fractional points, should be a float
done
Okay, now, let's go back to the scorepersec. First off, let's rename the variables into things that aren't garbage. Also making moneypersecond private since you won't need to modify this in the inspector.
public Score scoreScript;
public float upgradeValue;
private float moneyPerSecond;
done
Okay, so, post the script as it is just so I can reference it without having to scroll up a bunch
{
public Score scoreScript;
public float upgradeValue;
private float moneyPerSecond;
void Update()
{
}
public void Addscore()
{
if (script.score >= 100)
{
script.score -= 100;
moneypersecond += Moneyperupgrades;
}
}
}```
youre right
lemon as a side note it would be help to put cs in front of the first `` to make it more readable
like so
cs```public class scorepersec : MonoBehaviour
{
public Score scoreScript;
public float upgradeValue;
private float moneyPerSecond;
void Update()
{
}
public void Addscore()
{
if (script.score >= 100)
{
script.score -= 100;
moneyPerSecond += upgradeValue;
}
}
}```
ah
not like this
Now, this script wants to add moneyPerSecond to the scoreScript's score variable over time. Right?
Remember several days a go when I said that you can multiply a value in Update by time.deltaTime to make it in units per second instead of per frame?
yes
So, in update, you should add moneyPerSecond to scoreScript's score, making sure to convert it to units per second with deltaTime. You can post just the one line for this one without having to post the whole script again
is that it cs score += moneyPerSecond * Time.deltaTime;
mb i wrote it in score so i didnt thought i needed script in front
but i put in the right one
i cant get the cs thing right
script.score += moneyPerSecond * Time.deltaTime```
```cs
Code here
```
oh ok
Okay, so, with this, your button is now 100% fully functional. You currently don't have a way to click to add one, but you have the passive income script finished.
I believe all of the compiler errors are sorted, so once you attach this to a button, drag in all the references, it should work
Script doesn't exist
yes i fixed that
Youbnamed it scoreScript
it works
Okay, so all this is working now?
I believe it should be in a functional state but I don't have the compiler in front of me
yes it works but i cant customize the upgradevalues for each buttons
Why not? You should be able to put in whatever amount you want there
yes but it only works when i put the amount in the text that displays the score
I don't know what this means
thats the text that displays my score and theres also all the scripts,and this specific upgradevalue is the one that is used and added to the score each second the buttons also have that but if i customize it it doesnt work bc its not the one that is displayed
Holy run-on sentences batman.
Okay, so, MoneyCount is the script that tracks and displays your score. Why is scorepersec here? It should be on the buttons
its hard to explain
idk how to phrase it
Is it hard to explain because it should be there perhaps
so scorepersec doesnt go on moneycount
i am a 100% beginner in unity and coding in general. but should all those really have their own scripts??? it would probably be way way way easier to just use a GameManager or atleast a MoneyManager and ScoreManager right?
Correct. scorepersec is the script that handles a button that upgrades your passive income
It should be on the button that does that
but now it doesnt work anymore
And why not
Did you set your button to call the function on its own script now?
oh i get it
yh ima do that
one sec
i should do a roudn to int bc it displays decimals
Yes, and you shouldn't store that value anywhere. Just display the score as an int
but how do i do that if my score is a float?
...by rounding it to an int
Like you literally just said
nvm im just dumb
how do i write it to in here cs script.score += moneyPerSecond * Time.deltaTime;
Write what to?
to roundtoint
Why would you round there
Where you're printing it
Don't store the rounded value
oh
all you do is change the thing you're displaying
Yes. Set the text to be the rounded value of score
(RoundToInt(scoretext)).text = score.ToString(); i dont get whats wrong
I don't get what's right
me too ngl
the float i see here is score on the right side
Yes
do i include the ToString
If you need to
One step at a time
Start by rounding your score to an int
Then try to set the text to that
theres an error on an empty line
i think i just did it wrong
i tried many things
am i suposed to state it on another line
Show the error
or in the same line
and the line
scoretext.text = score.ToString();
score = (Mathf.RoundToInt(score));``` i tried this but doesnt seem to work
Read that line by line. Tell me what the top line does, then tell me what the bottom line does
top line displays the score and bottom rounds score to an int?
What specifically does the bottom line do with the rounded value of score
makes it equal to score
Other way around
You are setting score to be the rounded value of score. Essentially throwing the fractional part of score into the garbage forever
Is that what you want
i guess not
So, what do you want to do. In words
display the rounded value of score
Okay, and how, in code, do you display a value?
scoretext.text = score.ToString();
Let's say you want to display the string "foo". What would you write to display "foo"?
text.text = foo.ToString(): tbh im not sure
Not the value of a variable foo, but the literal string "foo"
And let's say you're still using the variable scoretext
honestly idk but ill try scoretext.text = scoretext.ToString(foo)
no wait
Try again
foo doesnt go there
Think about what the line does. What is scoretext.text
maybe scoretext.text += "foo";
Why +=? What made you settle on that notation?
scorextext is a text
Yes, a UI text of some sort. .text is a string variable on it
Somewhere in the script of that component is a line like public string text;
You are setting that variable to a string
So step one. How would you set that variable to "foo"
scoretext.text = "foo";
Yes, exactly. Now, step two. How would you round score to an int and store it as a variable named int x?
(RoundToInt(x))
Wrong. Try again.
That's the same mistake you made earlier. where did you get this idea so I might find the root cause of this misconception and murder it
wait
i gotta round score
int x = (RoundToInt(score)) i feel like i need to put smt before roundtoit but idk what
RoundToInt is a function of a specific library in unity. Do you remember it? If not, you can always find it on Google by searching for the name of the function plus "unity"
int x = (Mathf.RoundToInt(score));
Yes.
So, now you know how to set the variable text to some value, and how to store the value of a rounded score as a variable.
Only problem, text is a string. X is an int. Do you know how to get x as a string?
scoretext.text = (Mathf.RoundToInt(score)).ToString();
Correct! Even skipped a step and got to the final solution!
I was going to have you do it in two lines first then combine them but you put them together ahead of schedule
So now, no matter what score is, it will always display it's value rounded to the nearest int, and you can now completely disengage that part of your program from your brain. You will never again have to think about displaying the text, just change score and it's automatic
Yes, that would be the next step. I'll leave this as homework. Here are some hints:
- It should be a separate script, different from either of the two we worked on.
- It should be on the button object itself and only reference the score script
thanks
digiholic
@glass hollow i have a question
you know yesterday we made a var thats named upgradevalue and it specific to each upgrade,but is it possible to create a place in the score script that tracks the total amount of upgrade value?
because upgradevalue is basically my moneypersecond