#paste
1 messages · Page 1 of 1 (latest)
Are there any errors?
Look in #💻┃code-beginner
I ask for clarification, about this current code
how
I think there is a misunderstanding there
if that line is run, it will definitely increase the value by 2, unless some other code is changing it after
I see there is a AddScore() function which adds just 1
yeah I was wondering about that too
public void AddScore(int amount)
{
scoreAmount += amount;
PlayerPrefs.SetInt("score", scoreAmount);
}
``` I would change it to this
@void arrow Are you certain you executed the right code segment?
im not sure
I think you are running AddScore() when the button is pressed
add a Debug.Log to both the AddScore function, and below the +=2 line
but that function only adds one
i know thats why i wanted to access the void in another script
what do you mean by 'the void'
like void AddPoint()
Ok ok, I think I get what you need
obj.GetComponent<ScoreSystem>().AddScore();
obj.GetComponent<ScoreSystem>().scoreAmount += 1;
public void AddScore(int amount)
{
scoreAmount += amount;
PlayerPrefs.SetInt("score", scoreAmount);
}
```change the addscore to this
okay
obj.GetComponent<ScoreSystem>().AddScore(2)
```And then do this
instead of the obj.GetComponent<ScoreSystem>().scoreAmount += 1;
so now you can use the AddScore function to add score
just pass the amount of score
now it doesnt work at all
semicolon?
post the script as it is now
or wait nvm
yes thank you it worked
i just need to see if i can change it through another script
Good stuff
well no i cant change it through another script
but i can change it through the inspector
Why can't you change it with another script?
forget semicolon?
hmm
no errors
but you did change the function to my version
yes
in the scoresystem
to this
public void AddScore(int amount)
{
scoreAmount += amount;
PlayerPrefs.SetInt("score", scoreAmount);
}
I have no idea why it isn't working
Is there even a line anywhere that adds one to the score?
yes
where
score.text = $"{scoreAmount} Clicks";
SavePrefs();
and then on the addscore i just attach it to the onclick event
So the addscore is connected to the event?
no here
no i havent
there should be a value field there
Aha that's what you want
yes
okay thank you so much
Ok here's the rewritten BuyButton class
I just made it a bit more compact
And this is the second one
Now we have a field called score, which stores the score
And then another field called scoreAmount, which is the amount you score each time AddScore() is called
made a mistake in BuyButton
hang on
in scoresystem too?
missed a semicolon yeah
it was the scoresystem gameobject
and this scoreText = GetComponent<Text>();
that gets the score text ui element
i changed it to scoreText to separate the actual score and the ui element
yes
did it work?
right, the scoreAmount field is set to 0 by default
yeah how do i change it
you can change it in the inspector
yea i know
oh i made another mistake
In the Update() function, change {scoreAmount} to {score}
and in AddScore() change the first scoreAmount to score
done lets see
done
Is it working now?
foudn another error
at buybuttons
scoreSystem.scoreAmount = 2;
fixed it
it was += 2
before
yes it is
you wrote that the amount the scoreamount is how much it adds
so if its = 2
it adds 2 every click
no need for +=
will it?
ill just rewrite it
not the script
but when the other items come
ill just copy this script
and change the values and names
it's still going to set to 2, yes
rlly?
wait lemme change it back and see
when i do += 2 it does 3 per click
lemme try 1
yes thankyou it works
but when i put other items how should i do there?
if they have very similar functionality, I would change the script to have a public field that decides how much scoreAmount the upgrade is going to give, and then using that script for everything
For upgrades with different functionality (like spawning different gameobjects, particles e.t.c.) i would look into scriptableobjects
For my own game, which is a card game, I am using scriptableobjects that have different values like attack, cost e.t.c.
nice are you going to publish it?
true true
I'd probably get sued
btw how do i subtract the score when i purchase some item
i think its in buybuttons
PurchasedButton.SetActive(true);
and then it should be score - 50;
scoreSystem.score -= AMOUNT;
should work
okay
no you want better
dang you have potential to be big
i really dont
think so?
do you know a game called growtopia?
you have better pixel art than them
and they are successful
photoshop
i do it in photopea basically photoshop but online
what pixels do you have
width and height
most sprites in this game are 32x32
art is not the most important part tbh
well it is
focus on game design first I'd say
better than sucky game design
do you want to see what my old character looked like?
then its not even fun
ill send in dm