#paste

1 messages · Page 1 of 1 (latest)

void arrow
valid bloom
#

Are there any errors?

harsh ice
valid bloom
#

I ask for clarification, about this current code

harsh ice
#

this line only adds one score

#

instead of 2

void arrow
#

how

valid bloom
#

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

harsh ice
#

yeah I was wondering about that too

#
public void AddScore(int amount)
{
    scoreAmount += amount;
    PlayerPrefs.SetInt("score", scoreAmount);        
}
``` I would change it to this
valid bloom
#

@void arrow Are you certain you executed the right code segment?

void arrow
#

im not sure

harsh ice
#

I think you are running AddScore() when the button is pressed

valid bloom
#

add a Debug.Log to both the AddScore function, and below the +=2 line

harsh ice
#

but that function only adds one

void arrow
#

i know thats why i wanted to access the void in another script

harsh ice
#

what do you mean by 'the void'

void arrow
#

like void AddPoint()

harsh ice
#

Ok ok, I think I get what you need

valid bloom
#
obj.GetComponent<ScoreSystem>().AddScore();
obj.GetComponent<ScoreSystem>().scoreAmount += 1;
harsh ice
#
public void AddScore(int amount)
{
    scoreAmount += amount;
    PlayerPrefs.SetInt("score", scoreAmount);        
}
```change the addscore to this
void arrow
#

okay

harsh ice
#
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

void arrow
#

now it doesnt work at all

harsh ice
#

semicolon?

valid bloom
#

post the script as it is now

void arrow
#

or wait nvm

#

yes thank you it worked

#

i just need to see if i can change it through another script

valid bloom
#

Good stuff

void arrow
#

well no i cant change it through another script

#

but i can change it through the inspector

harsh ice
#

Why can't you change it with another script?

void arrow
#

idk

#

obj.GetComponent<ScoreSystem>().AddScore(2) doesnt work

harsh ice
#

forget semicolon?

void arrow
#

added it

#

already

harsh ice
#

hmm

void arrow
#

no errors

harsh ice
#

but you did change the function to my version

void arrow
#

yes

#

in the scoresystem

#

to this

#

public void AddScore(int amount)
{
scoreAmount += amount;
PlayerPrefs.SetInt("score", scoreAmount);
}

harsh ice
#

I have no idea why it isn't working

#

Is there even a line anywhere that adds one to the score?

void arrow
#

yes

harsh ice
#

where

void arrow
#

score.text = $"{scoreAmount} Clicks";
SavePrefs();

#

and then on the addscore i just attach it to the onclick event

harsh ice
#

So the addscore is connected to the event?

void arrow
#

yes

#

to the onclick event

harsh ice
#

Have you changed the value to 2

#

There

void arrow
#

in which script

#

oh in the scoresystem

harsh ice
#

no here

void arrow
#

no i havent

harsh ice
#

there should be a value field there

void arrow
#

yes i put it to 1

#

and it does 1 click per ye click

harsh ice
#

Yeah

#

that's it

#

change it there

void arrow
#

yes but i want to keep it at 1

#

when i buy a item it changes to 2

harsh ice
#

Aha that's what you want

void arrow
#

yes

harsh ice
#

I'll write something

#

hang on a ibt

#

bit

void arrow
#

okay thank you so much

harsh ice
#

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

void arrow
#

yes

#

theres some errors in both

#

ill fix them

harsh ice
harsh ice
void arrow
#

yes but i fixed in scoresystem

#

small errors

#

no biggie

#

what was the obj again

harsh ice
#

missed a semicolon yeah

harsh ice
void arrow
#

and this scoreText = GetComponent<Text>();

harsh ice
#

that gets the score text ui element

void arrow
#

yes but u wrote score only

#

its no biggie

harsh ice
#

i changed it to scoreText to separate the actual score and the ui element

void arrow
#

yes

harsh ice
#

did it work?

void arrow
#

well when i purchase the item it works

#

but when its normal it doesnt

harsh ice
#

right, the scoreAmount field is set to 0 by default

void arrow
#

yeah how do i change it

harsh ice
#

you can change it in the inspector

void arrow
#

ok lets see

#

it justs multiplies everything with 2 when i click

harsh ice
#

multiply?

#

that's weird

void arrow
#

yea i know

harsh ice
#

oh i made another mistake

void arrow
#

where

#

oh yeah

harsh ice
#

In the Update() function, change {scoreAmount} to {score}

#

and in AddScore() change the first scoreAmount to score

void arrow
#

done lets see

harsh ice
#

sorry for all the mistakes

#

I wrote it outside my IDE

#

which was a mistake

void arrow
#

its fine

#

im lucky your even writing this for me

harsh ice
#

I found another error

#

in LoadPrefs(), change scoreAmount to score

void arrow
#

done

harsh ice
#

Is it working now?

void arrow
#

foudn another error

#

at buybuttons

#

scoreSystem.scoreAmount = 2;

#

fixed it

#

it was += 2

#

before

harsh ice
#

ah

#

I thought you wanted +2

void arrow
#

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 +=

harsh ice
#

but if you add other upgrades

#

it will still set to 2 instead of stacking

void arrow
#

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

harsh ice
#

it's still going to set to 2, yes

void arrow
#

rlly?

harsh ice
#

no matter what the previous value was

#

change it to += 1 if you want to add one

void arrow
#

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?

harsh ice
#

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

void arrow
#

yes they have similar functionality

#

the whole game is about clicking xd

harsh ice
#

Isn't every game about that 🤔

#

jk jk

void arrow
#

well when you say it like that

#

🤔

harsh ice
#

For my own game, which is a card game, I am using scriptableobjects that have different values like attack, cost e.t.c.

void arrow
#

nice are you going to publish it?

harsh ice
#

i dont think so

#

I'm basically remaking a board game

#

that's not mine

void arrow
#

true true

harsh ice
#

I'd probably get sued

void arrow
#

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;

harsh ice
#

should work

void arrow
#

okay

harsh ice
#

here's a screenshot of the game

#

I know my pixel art sucks ok 😭

void arrow
#

nooooooo

#

it does not

#

i want to pixel art like that

harsh ice
#

no you want better

void arrow
#

dang you have potential to be big

void arrow
harsh ice
#

think so?

void arrow
#

do you know a game called growtopia?

#

you have better pixel art than them

#

and they are successful

harsh ice
#

yeahh

#

but good pixel art helps

void arrow
#

yes it really does

#

how do you pixel art?

harsh ice
#

photoshop

void arrow
#

i do it in photopea basically photoshop but online

#

what pixels do you have

#

width and height

harsh ice
#

most sprites in this game are 32x32

void arrow
#

okay

#

i really need to learn how to pixel art

harsh ice
#

art is not the most important part tbh

void arrow
#

well it is

harsh ice
#

focus on game design first I'd say

void arrow
#

yes game design

#

but art is really important

#

if its ugly nobody will play it

harsh ice
#

better than sucky game design

void arrow
#

do you want to see what my old character looked like?

harsh ice
#

then its not even fun

void arrow
#

ill send in dm