cookie clicker store
Hello i am here ones again asking for help. My store buttons need to be dissabled if i don't have te right amount of cookies and enable when i have the right amount or more. I already have a method for isolating the number from the text in my textblock. The problem i have been having is that when i get my store too take away cookies the counting of the cookies just resumes from the last number that was on before the subtraction of the number. example: i have 18 cookies and i pay for the clicker worth 15 cookies. It subtracts and it sais 3 cookies, but when i click on the cookie again it jumps to 19 cookies all of a sudden. Another problem i have been having is the button disabling it doesn't wanna work however hard i try. Can someone help me i really need this to work.
here is the repository link;https://bitbucket.org/pxlrepository/c-project-cookie-clicker/src/master/
I work in a WPF in a .net framework in visual studios
If anyone can help it would be much appreciated
113 Replies
I feel like i am just stupid but idk how i need to do this otherwise
Note, that people usually do not bother searching through an entire repository to help
If you can please use the site below and paste in the relevant code.
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Ah thx sorry
BlazeBin - kxewswlgsfsk
A tool for sharing your source code with the world!
this right?
If that is the code that causes issues, then yes.
it is i also put the code for the buttons
Don't base your entire game logic on the text of the GUI
but store the game data inside of a class.
In your case, it's a double
oh?
The GUI should just respond to events called by the game logic.
Just as an example you can have an event like CookiesChanged
then you can subscribe to that event and update your GUI based on that specific event
As a quick example
So whenever Cookies property value is set, it will set the backing field value
_cookies
to the value and then it will call CookiesChanged event
So the GUI can just subscribe to said event then you have your text ready to go without any issues.i am sorry i am trying to comprehend this its late for me. If i get it right is that i am trying to do too much in one GUI and i should split it up? and need another GUI to keep track of the number of cookies i have?
if i am wrong please bare with me i am feeling like an idiot rn
No.
Do not store / use information about the game in the UI, but in the code underneath the GUI
You at the moment use the text of the GUI to see how many "cookies" you have.
This is what you should not do, use the GUI as a way to store information.
i am sorry for being an idiot
would you mind maybe hop in a call tomorrow so you can instruct me a bit if your up for that i get it if you don"t want to i been at it for 6 hours with no progress.
I do not help by calls, I do however help by text.
In this server
it was worth a shot i am just very green let us say i started programming in september in a university. we just learned about arrays
No problem, programming is a big subject. Especially the do's and don'ts, how to structure the project, and so forth.
Basically, keep the game logic out of the GUI (Graphical User Interface)
school expects us to make full on cookie clicker clone with our limited knowledge we have its just frustrating cause it feels like when i make some kind of progress i take 10 steps back
I know how it feels. Although when I joined the programming course I already had about 7 years of programming experience. But my pals didn't.
yeah to be honest i am feeling i am wasting people time asking for help with stuff i barely comprehend
But that is the way to structure any kind of project, to keep it out of the graphical interface. Keep the code in the backend. The GUI should only respond to events being called by the code in the backend
No you are not!
People that helps here actually likes to help, you are not wasting anyones time!
so the button event are GUI right?
Anything that you see on your screen (window) is GUI
oh
ok so litterly every event i made is GUI
The events are not GUI, they are just events being called by the GUI
such as the button click event
oh
ok
gui is just all the things in my window
like this
You can start like this
$static
In C#, static allows you to have members (classes, methods, etc) that are not tied to any particular instance and are therefore always, globally, accessible. When applying
static
members, take the following considerations:
• If there are to be multiple instances of a class, do not use static
• If you need to track state, do not use static
• If you are going to have multi threaded workflows, do not use static unless you're aware of the caveats
static
is best used for stateless methods, extension methods/classes and in areas where you understand the pros/cons. Read more here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/staticThen you can just do
MyGameData.MyCookies += 1;
Which will increment MyCookies by 1
static meaning it is globally accessible and not tied to any instance, meaning you don't have to call new and pass said instance around.
So you can just do MyClassName.MyStaticVariable
and not
ok and if i make that i should bind MyCookie too my mouse down event?
Subscribe to the click event, yes. and then increment the MyCookies by one.
You won't see anything in the GUI, but it will increment in the back-end.
After that you just have to hook up some code that sees the change and sends back a response to the GUI.
ok so if i get it right i need to make "public static double cookies ( get; set;)"
wrong brackets, but yes.
oh yeah
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/
so like this?
now followup question the code you set here should it be in the same method or no?
You should not do it the way I wrote what you replied to
but this above https://discord.com/channels/143867839282020352/1177729264540459128/1177748113662955641
Buddy
You can start like this
Quoted by
<@203166497198047232> from #cookie clicker store (click here)
React with ❌ to remove this embed.
A static property / field is a good start because you don't have to mess around with passing the instance between everything.
oh fuck i feel stupid i thought public class was the same as public window omg
You can have it anywhere you'd like but I would recommend to dedicate it's own class for it. Somewhere you'll know where it is.
well we never learned about extra files yet we only learned to work with the .xaml file and the .xaml.cs file
so i need to make a public class to do the cookies counting if i am right and to keep track of it?
Yes.
Next step for you is to make an event
Don't worry, this will guide you.
https://learn.microsoft.com/en-us/dotnet/csharp/events-overview
As long as you like to read 😛
like this?
or the get set are place holders?
For now, yes.
ok imma add that then
so that has been added in my code
Next step is to create a backing field, you can do that by creating a field
static double _myCookies;
in the same class as you just created, note that you should not declare it as public as you don't want anyone to access that field but that specific class itself.
MyCookies property only acts as a "middle-man" or a proxy.
GUI -> Button Click -> MyCookies + 1 -> _myCookies -> CookiesChanged -> (callback) OnCookiesChanged -> (GUI) Update GUI textwell i need to bind it too my image mouse down event
so i thing it should be in the mouse down event then?
I see, yes. You need to do that.
You should only increment it in the mouse down (click) event, yes.
ok this is doing my school project so with the mouse event i used this
it needs to resize too so i put that with it too
Now, how do you access the class that you just wrote and it's property?
rn its under my public MainWindow
i feel like i did wrong
Feel free to post code $paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
It's also good to keep the helpers updated in what you are doing by pasting the code from time to time.
a shit i shall show you the whole thing
BlazeBin - yvthqujplsrw
A tool for sharing your source code with the world!
so i have almost 200 lines of code
what you just saw was the resizing method and the mouse down event
Yeah, you do not want it inside of another class in this case, also known as a nested class.
you mean the public class?
Get it out of the class for the window (MainWindow)
ok did that
How do you think you can access the property inside of the newly created class?
so uhm do i need to make another .cs file?
You don't need to, no.
idk then never made a new class before
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static
Read this
Since this happens to be homework I will not tell you, but I will give hints.
its a project worth 60%
so yeah
my question did i place my class wrong
In the previous code snippet, yes.
fuck
do i need to place it above the MainWidow?
If you don't want nested classes, then yes.
which is the purpose of what we are doing rn
Removing the nested classes?
so it doesn't become nested is what i think your getting at right?
Yes.
You can read more about nested types here https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/nested-types
https://paste.mod.gg/cskczzzqtqvc/0 so like this
BlazeBin - cskczzzqtqvc
A tool for sharing your source code with the world!
It is still inside of the class
Also those images won't be displayed for the end-user
in the XAML
since it is a path that only exist on your drive, it will look for the file on the drive, it isn't embedded into the app unless you specify that it is.
i thought i had those images in the assets folder of the project
You do, but you specify the full path
ah i need to change that to assets/name.jpg i presume?
Try it and see
no errors so it worked
so the public class should still be under the namespace yes just out of the mainwindow?
Try to run the app as well
BlazeBin - poojxzmymrtx
A tool for sharing your source code with the world!
Great
You still kept the old class (possible duplicate) :d
wait huh what you mean
oop god i am blind this didn't happen in my visual studio
also for some reason every image show besides the last one
i have everything the same too
That's what I expected
how every picture is in assets
Show me your solution explorer in Visual Studio
here
You need to mark those images as Resource
by going into their properties
ok in properties
From visual studio that is
hmh
mhm
rn in catigorized
Alright, then you should be able to define it's relative path for that specific image.
and it should show up
in full path? or is there an option i aint seeing
or is this the one you meant
no, not full. Relative.
You don't need to set an option
Either way I need to get going, it's 1:30 AM here.
Try your best, read the links I sent previously and the code.
oh your live in CET?
same here
Yes.
i should sleep too haha ^^'
managed too put all files too embedded resource
Make sure they are marked as a
Resource
so defined the relative path as Assets/nameImage.png
and set the build action to resource
https://paste.mod.gg/dgpnqgdwnnlv/1
BlazeBin - dgpnqgdwnnlv
A tool for sharing your source code with the world!
i still don't get the last picture to show but imma look into it
found the damn problem my button wasn't big enough for the image
changed height of the BtnMi too 63
https://paste.mod.gg/cnpeauepgwja/1
BlazeBin - cnpeauepgwja
A tool for sharing your source code with the world!
cleaned up unneeded code in my methods
https://paste.mod.gg/krxhtbssvetb/0
BlazeBin - krxhtbssvetb
A tool for sharing your source code with the world!
BlazeBin - krxhtbssvetb
A tool for sharing your source code with the world!
@Networking is🎄save me pls sorry i tried my best i read over and over i am just to fucking stupid to get it idk what to do
sorry but vague pointers will not further anyhing
dude, don't do this a thousand times
just create a variable and calculate the substring in it
if some did this in my code
i would tell him to change it and pass the culture param, probably
InvariantCulture
also
create a compiled regex instead of using the free regex.match
last but not least put strings like "Cl", "Gr", "Mi", and so on in constants or in their own class or somewhere elseI got it all fixed thx for all the help and learning opportunities