Console Game scenes equivalent
I usually use Unity for C# because I'm not very fluent in it. I'm trying to learn by making a very basic idle game, and want to add a new feature. I'd like a second scene i can open up when I use left arrow, which completely clears the console and writes the new screen. I also want updates on that page to be saved and to be able to change when they aren't loaded. I've talked to a close friend who's really good with C# and they suggested using arrays, but I don't understand how I could use them. Lmk if you want my code I can send it
94 Replies
I considered using a new one of these (idk what they're called), but idk what type of array to use to be able to have those as values, if I knew how to do that I think I could do the rest myself


u mean classes?
if you dont know what that is please learn c#
Ik what they are, I didn’t know what they were called
I thought classes were the things that they were inside of lol
you could store a copy of them and iteract with the
*them
in an array
How would you store a copy?
Alr I’ll give that a try when I get home, thank you so much
ok I forgot
but
like this?
so how would I configure the new screen and stuff?
tsk why is mine not coloured
I can’t figure this out
BlazeBin - uayzhdtxkghv
A tool for sharing your source code with the world!
@FusedQyou
the issue is nothing is printing anymore and the code around it is idk because idk what the issue could be or where it's fromSo is
UpdateMainConsole
the method that does the printing?yes
Debugging 101, the first thing you do is check if the method is called at all
So you place a breakpoint at the start of the method, and see if it pauses on it
If that doesn't happen, place them above the method close to where it's called
Specifically line 91, you see
if (jobPoints > 0)
in the Update method. Place a breakpoint down in there, see if it breaksthe code just ended
it didn't pause
Specifically there you can hover over
jobPoints
and see what the value is. The method executes when it's higher than 0 and it probably won't be that
If that breakpoint isn't called, it is possible that Update is not calledpause
back up
But then I see the method is
async void
. Why are you using an async void method?UpdateMainConsole didn't pause
Who told you that is a good idea?
my friend who is literally teaching me everything I know about c#
If
Update
throws an exception now, it is silently ignored and your program will end without an errorhe just wrote it and I never questioned it
Your friend is a dumbass
Never use async void
Respectfully, I don't know the man
But async void is a very bad habit
I put it at the (if jobPoints >0) part and the code just ended again
Let's fix this async void method first
In C# we have the async Task pattern for asynchronous programming
ok let's fix the completely unrelated problem first, cool
wow that sounds a lot ruder than I intended
If you're going to be snarky I'm not going to help you
;-;
This could very well be the issue
Do you know what asynchronous programming is?
I know it runs asynchronously from the rest of the code
Yes, and possible in a background thread
That's why you can run it infinitely and add delays
In C# there's a state machien that it builds in that adds proper async support, but you have to use that right pattern
What you have now is a basic method that is just run in the background and forgotten about
ok
The issue is that if it breaks, just nothing happends and any errors are then left confusing you why the program doesn't work
so to fix that do I just remove the void part?
1 sec
Yes, anything
async
that from which you don't intend to return anything should be async Task
. Using async void
is a recipe for disaster
This is a somewhat simple way to make a background task
ok I changed it and it is still very much broken
It's still bad, but at least it will not break the code unexpectetly
oh you did something
ok
can you like
explain it
By returning a
Task
C# can properly introduce a state machine that can be awaited and returns exceptionsTask-based asynchronous programming - .NET
In this article, learn about task-based asynchronous programming through the Task Parallel Library (TPL) in .NET.
Read this
the name debug does not exist in the current context
Add the namespace
oh
yeah that makes sense
add the thing that makes it work ;-;
ok it instantly ended again
I assume that isn't ideal
Generally for things like this you should create a proper system that makes these background tasks.
Another way is this:
I personally like this because it removes the whole async void part
This makes the task, and it basically adds a delegate that is code to invoke when it ends
what does try and catch do
Then you await the result, that is the task you returned, much like you awaited the UpdateAsync before, and any exceptions are then thrown
and why greater than or equal to sign?
Exceptions and Exception Handling - C#
Learn about exceptions and exception handling. These C# features help deal with unexpected or exceptional situations that happen when a program is running.
Lambda expressions - Lambda expressions and anonymous functions - C...
C# lambda expressions that are used to create anonymous functions and expression bodied members.
I can't believe I'm getting homework 😭
alr do I need to read this now?
or can it wait
It can wait, you can also just use the first bit of code
This one
What it does there is it runs the code in the background, and if it throws an exception it calls
Debug.Fail
and your code will pause much like a breakpointoK
oo I see
it instantly ended with no debugs or errors or anything
So the writing still didn't work
ye ;-;
Well now check
UpgradeMenu
which calls the updateor the game loop tbh
That method is never called anywhere
nono
that's for later
not done with that yet
Go back to
UpdateMainConsole
, and you see it's called in MainMenu
as well
Just like Updatethe update is called elsewhere
So where is
MainMenu
called?
Place a breakpoint in thereMainMenu is the main class where my code is
See if it's called
like if I have anywhere?
because I do not
So the code doesn't run
And therefore the text is never drawn
;-;
Problem solved, run the method
shouldn't it just run the code?
where do I put it? that's my main thing so idk where I'd put MainMenu();
Your main thing is
Main
on line 8
That's that run by C# conventionMain() and command-line arguments - C#
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
All you did was make a new instance of
Game
, and that's itoh
I never new what that was for
do I make that with curly brackets and put the line in there?
That's why I mentioned you should check out the very basics first
Your main method should make an instance of
Game
, and then call MainMenu
However, it will still end instantly
It runs it, the method ends, the program endstsk idk why my friend put all this complicated crap in
There's plenty of things that are quesitonable in this code
Why the fuck are you using BigInteger
oh we were fucking around with stupidly high numbers and he told me to just leave it as that ;-;
Well, the best way to fix is is by making the Update method the main thing that runs the application
anyways it works but updates rly slowly
First of all, you should readd the basic Program class and put the main method in there
This is very messy, having it in here
Make a file
Program.cs
and put this in here
that's the current file's name
Then rename it to
Game
It has the Game class
Single purpose per file, this is the game classuh ok so I renamed it and now it won't load
nvm I did it
Because C# by default tries to find the Main method in the Program class
Can also be changed but there's no reason to
ok done I think
So what you want to do is just have the async
Task
Update method, and in the Main method you want to start a new game but then await the Update method
This way it will constantly run
This thing
Should be called by the Update method as a side thingwait so put that into update method?
Just call a method that does this
Ideally your Update method does nothing but call methods for other things
So even the stuff in the method currently should be in a separate method
That keeps it clean
wait I'm confused wdym
where do I put that?
sorry I'm just not understanding rn
nvm I gotta go out
I'll come back after a while
cya
Scriptbin - Share Your Code Easily
Use Scriptbin to share your code with others quickly and easily.
Like this
Single loop calls other stuff
Added tics so you can call things per second, like that points method
And
running
so when you put it to false
the game ends
Look at this when you get backVery nice very nice
I’ll do that soon
Can’t right now tho