❔ ✅ How am I making errors?
so I'm pretty sure that i'm correct but here are the pics:
392 Replies
Is this top level script?
The class needs to go at the bottom
class wizard ?
im a beginner..
You don't write your own main any more
Put the class at the bottom of the file
can u show me an example pls?
SORRY I KNOW I SUCK LMAO
I just started 5 days ago
lol
I'm on mobile, can't really type out so much
Put your class at the bottom of the page. Delete the line with static void main
in general C# code needs to be inside classes and methods.
as was mentioned you are mixing a class with top level statements. if you do that, the class has to be defined at the bottom of the file because that is just how top level statements were designed to work. so you need to move
below all your other code
and if you are going to have
static void Main(...) {...
then it needs to be inside a classWhat about those?
those are called "fields"
they are defined inside of classes
as you have done
oh alright..
Now i get it, Thanks!
by the way
why for people it types using system;
namespace and static void main..
but for me it doesnt????
using ...;
at the top of a file is called a "using directive" when you want to use a member that is inside another namespace, you either need to fully qualify the member or you need to add a using directive at the top of the file that will effect all code in that file
there is a feature called "implicit usings" that was added in a recent version of C# that will automatically pull in some of the most common using directives
you can disable "implicit usings" in your .csproj
file if you don't like it@zacharypatten can I ask a question?
you only got one question and that was it
good job...
jk ask your question
What does this mean
Name {get; set;}
that is a "property"
Private and public
"private" and "public" are "access modifiers"
What’s the difference
Access Modifiers - C# Programming Guide
All types and type members in C# have an accessibility level which controls whether they can be used from other code. Review this list of access modifiers.
the documentation is your friend.
"private" means you can only access it from inside the current class
"public" means you can access it from anywhere
ZP
@zacharypatten
how to fix this?
you make sure all top level statements come before any type definitions
the error is pretty self explanatory
never mind
yeah
im so dumb lma0o
lmao
well what do u expect im still a beginner started since 5 days
just don't ignore the errors. C# has excellent errors that will often tell you what the problem is
compare C# errors to C errors and C errors will make you cry cause they aren't helpful for shit
C++ errors are pain
brackeys courses are so freaking helpful
but they're not that simple
yet very simple
idk if that makes sense
but
.
youtube videos are the worst way to learn how to code
you learn how to follow directions
not problem solve
just my opinion 😉
no I just learn how it works
lol
@zacharypatten
name
and favouritespell
are fields of wizard
you have to access them from an instance of a wizard
"name"->"wizard01.name"ohhh
tysm
now good?
well your code will compile now
Are you using Visual Studio Code?
If you are a beginner you should really use Visual Studio
not Visual Studio Code
whats the difference?
im using code
Visual Studio is a fully featured IDE and Visual Studio Code is more of a text editor in comparison
whats an IDE ;-;
google is your friend
alr
oh
.
instantly
oh thats cool
oh god
not again
im getting a red line on console.readke
readkey*
..
take your time
learn from your mistakes
so you don't make them again
ok thats a simple error
ik what to do
.
ZP thanks for ur help
if i struggled with anything can I dm u?
no wonder why help channel exist
I would rather keep discussions on this discord server, but you may "@" me if you wish
....
alr
you cannot put top level statements after a type or namespace declaraction
class wizard { ... }
is a type declaration
you are declaring a "class" type that you are calling "wizard"
Console.ReadKey();
needs to come before class wizard { ... }
if you want it run as a top level statement with the other code
---
generally in C# you should only ever declare one class per file
you are declaring two classes in this file
and that is clearly causing you issues
so if it were me... I would make a new file wizard.cs
and define class wizard
in that file
also I would start using Visual Studio instead of VSCwell I googled VS but I only see VSC
Visual Studio
Download Visual Studio Tools - Install Free for Windows, Mac, Linux
Download Visual Studio IDE or VS Code for free. Try out Visual Studio Professional or Enterprise editions on Windows, Mac.
But those are saved in
@zacharypatten
I don't know what you are asking, but you need to learn how classes work
fax
you can use classes that are defined in other files
and I also dont know whats return
I know but i like idk when to use it
you use it when you want to
.
makes no sense lamo
lmao
wrap your head around how methods work and what the call stack is and it'll make perfect sense
"return" means that you're "returning" to the caller of the method
good reminder
I forgot methods again
my memory sucks
what are you trying to make? you seem to be stumbling around trying to learn C#, but you will struggle to learn just from dabbling alone. try to have a goal in mind like "I want to make rock-paper-scissors" then you know what you want and you can try to achieve that by tinkering and learning C#
its like a fish memory
lmao
good advice
a little bit of goal can go a long way
1 thing
I cant memorize anything
my memory suck
you don't need a good memory to code
you need good problem solving skills
I forgot methods 2 times
wdym
I mean... you kinda do... but it's not really a memory thing, it's a practice thing
no one remembers every single syntax nuance in C# or every method in the base class library
we are constantly googling, reading documentation, reading compiler errors, etc.
so you will never know everything you need to know
it just won't happen
you need to learn how to problem solve
m kinda good at that, only if there was my own language in VS
..
C# is an extremely easy language to learn compared to nearly every other language imo
well it depends
for exmaple, if ur not interested in F#, but u still want to learn it.. it will become hard and boring cuz ur not even interested in it..
well if you are not interested in learning C#... why are you?
im
im interested in learning it
but
im just giving an example
C# is fun.
Do you have a plan for how you want your game to work?
im going back to the "try to have a goal" comment. focus on your game and what you want it to do
Kinda yes,
But im not confident that my game will actually be famous and yk
I just want to be a dev..
and i dont rly know it works,
but I want to be a dev in a big company. thats just my goal.
take it slow. you have a long way to go. not that you can't achieve that, but you still have a lot to learn. I'm talking about your current game you are making in the console here
you are making a wizard and printing some output, but what else do you want your game to do?
Oh, if that's the case.. Then I just want to make a wizard that casts spells on other objects.. its pretty simple
and it destroys objects
well you have a wizard, but you don't have anything else currently. how about you start adding stuff?
and are you trying to make like a turn based RPG? or just a basic visual novel without any decisions for the player to make?
right now, you jsut output text tot he player. the player doesn't get to make any decisions
No, I meant like the player could move the wizard and casts spells..
okay, you want movement
Yeah.
I can link some examples that have movement. would you liek some examples?
sure
https://github.com/ZacharyPatten/ZacharyPatten/blob/main/Articles/2022-04-07.md look at #8 in this link
uhh.. that looks pretty complicated
lol
also, there is a github repository with console game examples:
https://github.com/dotnet/dotnet-console-games
There are several games with WASD movement:
- Snake
- Role Playing Game
- Console Monsters
- Gravity
There are games with movement that is handled via commands like "up", "down", "left", and "right":
- Wunpus World
There are games with limited movement like you can only flap your wings or steer left and right:
- Flappy Bird
- Drive
and other games have other forms of movements as well like your current cursor locations
did you try the code for yourself?
like copypaste?
yeah
no
how about you try it
wait
how do I use VS
i only know VSC
did you download VS yet?
YES
yes
*
I installed it
with C#
now what do i do?
make a new C# console project
looks sick
it should open to the launcher
on or off?
up to you
what does it even mean LMAO i suck at english
jk
im good at english
i didn't understand statements
thats all.
oh
ZP
i have a baby bird to feed every 2-3 hours
so at anytime
u might see me just not responding
im just handfeeding em
.
have fun... everyone on this server is generally multitasking 😛
I'm playing Indiana Jones and the Emporer's Tomb atm...
it kinda sucks...
but trying to get hype for new movie
it didnt generate top level statements..
bruh
.
well uh
honestly VSC gui is much better
than this
tbh
bruh you jsut opened it for the first time... you shouldn't judge stuff when you have no experience 😛 give it a bit of time
lol
anw
so
um
thats all now I start?
so how about you try running your code? you can do so with the green triangle at the top
yours probably says "ConsoleApp1" unless you put in a custom name, which is fine if you did
oh its working
cool
nice
but now how do I make my OWN wasd game?
or movement
whatever
well look at what the code is doing. it is using
Console.ReadKey(true)
to read the keys that the user is pressing
if the user pressed "W" or the "UpArrow" it will move the player's position up by subtracting from the player's Y coordivate
cause in this case the top left is coordinate 0, 0thats quite hard to understand for beginners..
breakpoints are your friend
aaaaaaaaaaaand what is a breakpoint
..
Debugger.Break()
it's a point where you break
.
I.E. pause
you pause the program at specific points in code
so you can inspect what's going on
like look at the values of certain variables in the middle of the program running
see the red dot to the left of the code? that is a breakpoint. while your code is running, if it reaches that line of code with the red dot it will stop and you want look at what the code is doing
and you can step through the code while it is running line-by-line with the F11 key
maybe programming isnt for me..
i never understand anything in it lmao
that's normal
you can't expect to become a programmer over the course of an hour or two. it takes time
becoming a programmer usually means re-learning how to think
there's a significant barrier to entry
but all it takes to get past it is practice
ZP how tf do u expect me to understand all of this?
ask questions
read each line of code. what is the first line of code you don't understand?
1 sec gotta do smthing
ima leave WASD later
not a bad idea, there are easier games to get started on than trying to make one with WASD movement
like rock-paper-scissors
or solitaire
or battleship
bro vs sucks compared to vsc tbh
but
.
looooooooooooooool, no
not for C#
and not for beginners
which one u mean vs or vsc
ngl I prefer vsc but ok
easier to use tbh
no offense, but that's cause you don't know any better
you don't know about all the tooling that you're missing in VS Code
which you CAN add in the form of VS Code plugins and such
and approximate the experience of Visual Studio
VS is tailor-made for C# development (also C++ and other .NET languages, but yeah)
it's a first class experience
the experience you get with VS Code depends on how knowledgeable you already are with how C#/.NET works, and how all the tooling works, and whether or not you know how to properly configure it
VSC = visual studio code
@ReactiveVeina
....yes, as does "VS Code"
not the tools
that's my point
brih I meant something else
VS Code doesn't inherently include tooling
other than tools
like the gui and how it looks is what I meant.
it's not significantly different than VS
it is
just enough to make it feel different, if you're not used to it
but not very meaningful when it comes to functionality
vsc looks better than vs
right, not meaningfully different
enough that it's a matter of personal preference, and doesn't affect what you can DO with it
and enough that you could get used to either one
Idk i just dont rly like vs
but I need to use it
so
.
which is fine
but use it for any amount of time, and you'll likely appreciate what it has FUNCTIONALLY that VS Code doesn't
outside of just text editing
why do I feel like VS is different from vsc cuz in vsc its correct but here its wrong:
uhh
it's not correct
..
yes
y is it correct in VSC?
it's not
it wasnt
VS Code just isn't reporting the errors to you, until you compile
ZP ur finally back
VS Code doesn't give you live feedback
which I can agree with
.
lol
But I ran the program a LOT of times yet only yellow lines, no red line
..
define "ran the program"
maybe nobody saw that
i realized the error
LOL
I didn't sleep for like 8 hours
lol
yall thanks
it happens
WAIT
I also have another problem
that I struggled with
a lot
42
i still dont know how to fix it..
42 ?
42
that's the answer to your problem
42 is a hitchikers guide to the galaxy joke. google it
now better
or better yet... read the booke 😛
or watch the movie
both are good
i love da movie 🙂
never heard of it
i dont rly watch movies anyways
what happens
if i switch
int and float
with VAR?
or var
sorry caps
depends where you mean
i think its the same
if you do it within a property or field definition, you'll get a compiler error
for two reasons
A) that's simply not allowed
B) even if it were allowed, the compiler can't tell what you WANT the type to be
the point of
var
is that it's shorthand for int
or float
or any other type IF the compiler can figure out what the type is supposed to be, from context
var
is only valid when declaring local variables
like, inside a method bodyoh
.
nvm then i would get a compiler error
if i switch float and int
with var
here, the compiler figures that
var
should be int
, since that's the type of 0
wouldn't work, because there's no context to say what type it's SUPPOSED to be
correctthe compiler would say "wat? nvm i'll give him an error his dumb he deserves it"
jkjk
.
lol
it was just a joke
an accurate one, tho
😛
and my english sucks so sometimes I might just go to google translate lmao
ima do something
im not sure if its gonna work
but
im gonna try
nothing bad is gonna happen
godspeed
reactive what does public mean?
i forgot
.
public int etc
access modifier
means anyone can access it
oh
.
and private is da opposite?
basically
ik i get what u mean
means only the immediate class it's defined in can access it
i get it from the start
but now
ima try smthing
rq
1 sec
veina ur on all day
tf?
I feed my baby he is not a parrot thats an edit
?
.
u got a pet btw?
yes
wat pet
dog
I have 3 birds
neat
well 4 birds cuz one is coming in the way
lol
wait
so is it correct
if I do like
public int Castspells; then go under console.writeline and type castspells--;
?
I want the spells go down
when the user uses the spell
ig castspells--;
assuming you get the naming right, yes
weird,
Castspells
and castspells
are not the same thingik
u need to get the correct caps
i got a red line
var x = Castspells--
is shorthand for...
right
Castspells
is defined as an instance member of the wizard
classcorrect..
wait
i gotchu
you can only refer to it by specifying WHICH instance of the
wizard
class you want to referenceno need to type
or by being inside another instance member of the class
precisely
now good?
nvm
prob wrong
lmao
no way its correct
trying wont hurt tho
I mean... there's no error
beyond that, I dunno
but look, it kinda makes sense
I'd have to know what your intentions are for what that code is supposed todo
since there is a var thats int and float, it worked..
and to access the wizard class wizard01....
other vars got the same error ( I mean i got the same error from other vars) yet this kinda makes sense that I have to put wizard01...
when the user uses the spell, it goes down
so like he has 7 spells, uses the spell and it goes down to 6
right
pro skills
lol
jk im rly bad
umm
what abt this one tho
uhhh
hmmm
show me the whole file with
Main()
in itthere goes the others
?
das the file
try dropping that semicolon in the middle there
that makes no sense but ok
well
it worked
..
nah, it makes sense
Y?
it's just invalid syntax
semicolons belong at the end of statements
look
ik
but
i was like
changing
yknow when u have uhh like Cw and u want to make it go up
yea
the thing that came right before that semicolon was the
Main()
method definition
which is not a statementi was changing them but never noticed the semicolon
and should not have a semicolon after it
yeah i know that
i was just changing the lines positions
never noticed that semicolon lmao
I'm actually not sure why that wasn't a straight-up error, upon the semicolon
theres a fly annoying me
.
oh god
wait
maybe that's actually valid for local functions?
im never gonna use my small brain
so tell me if its correct or not
so i wanna use console.readkey (i know the full code its just shortened)
but it will not work, as its supposed to be on the wizard class..
correct ?
uhhhhhh
no
but really, I don't know what you're asking
ye wrong lmao
1 sec
ima use my small brain again
fff
now correct
ok now my brain upgraded from small to big
XD
anyways
okay
no need to eplain this was so obvious
well i still call myself big brain cuz i didn't sleep for almost 10 hours
lol
wait I woke up yesterday at 10PM
.
ok now I edited it
me everyday:
😂
@ReactiveVeina
literally me everyday
and um ignore this language
its only the top 2 hardest language to learn yk
which is my main language
@zacharypatten
bro
nevermind
he is off
..
People are from different timezones and need to sleep and stuff, y'know.
So, your last 20+ messages here are unrelated to code, so is your issue solved?
I still have 1 issue then im done
Okay, describe the issue
alright, look so I want to make a console game (not done yet but part of it)
so i want in text the wizard cast spells, Now here's an ss:
So I struggled with this A LOT i mentioned ZP but he didn't respond
now the You have + spells dont worry
I know its supposed to be wizard01.spells
but
uhm
public void castspell(); and wizard01.castspell; and wizard01.Castspell--;
you are mixing top level statements with classic main
you cant do that
pick a style and stick to it
apparently it actually compiles
what
okay, thats... uncomfortable, but whatever
veina how?
your current problem is that
public void CastSpell();
doesnt have a bodyearlier, he had a stray semicolon that caused a "there is no suitable Main() method" error
you can't declare empty methods
he removed that and the error went await
Then why am I getting redline?
and all 3 places you try to "call" the method, you forgot the
()
I was referring to your use of the main method
correct, thanks for reminding also
look
(btw my memory is so bad so I cant remember that when u try to call a method u need() )
it's time we take a different approach here
anyways
this is not about memory
look
you have errors
yes I know
what do the errors say
1 sec
you don't have to memorize everything, that's what error messages are for, the error messages will TELL you what's wrong
memory what I mean is sometimes it happens on other thing, now i forgot that when u call a method u need ()
I dont understand errors , which is a big problem
that's what you should focus on, then
^
understanding error messages
learn how to read and understand the errors. thats a CORE skill
how do I practice
understanding error msgs?
lets begin with the top one
what do you think it means
hmm..
i think it means i have to get public void Castspell(); into main?
?
wait
nmv
nvm
um
how on earth do you get that from
The name 'Spells' does not exist in the current context
um
ez i fixed it
lmao
uh
ignore that
my brain died for a sec
here ima ss and show u why..
or tell u
okay. can you show the updated error list?
idk the first and 2nd
i've been getting those
for a while
lets start with the third one down
ye sorry my brain died there
Cannot assign to CastSpells
because its a method group
what does this tell youthis one is pretty self explanatory..
but i have time to think soo
hint: what is a "method group"?
uhh the curly brackets for the method
i guess?
no wait
MY BRAIN DIES
..
NO SORRY
I DIDN'T MEAN THAT
MY BRAIN DIED
no it means the symbol is a method
bruh my brain dies
ie
CastSpells
is a method
not a variable, not a property, not a classyep..
and you can't assign, ie change the value, of a method
it says line 10, so we look at line 10
so why wont that work
whats wrong here
im changing the value of the method here..
you are.
or well, you're trying
Hmm, but I want the spells go down when the user casts a spell
So maybe that method should do that?
the method that is responisble for casting a spell should also reasonably make sure spells can be cast, AND decrement the spells property
oh umm..
that makes sense now
But wait, what's the difference between static and public?
@pobiega
stop pinging
ok sorry
also thats an apples and oranges question
public is an access modifier
static means the member belongs to the class itself, not an instance of the class
oh
now back to the error
ok
oops
i just randomly fixed 1 error
wat
well, quite a bit of them were interconnected
one error often leads to more errors
well yknow the castspell method
instead of semicolon, i replaced it with curly brackets
good
turns out it was correct
wat
yes
because now it has a body
its an empty body, but its still a body
you can't declare body-less methods unless they are abstract or in an interface
oh
now to the 3 errors
why would you want to anyways? a body-less method by definition does nothing
wait
is it correct
hold on
im gonna do smthing
ok wait
maybe I have to put something in the curly brackets
eventually, yes
but not right now
wise
..
anyways
it's quite hard for beginners ig
not i guess but for sure
¯\_(ツ)_/¯
or my brain is just too small
I think you are just rushing ahead.
not really
its been 5 days since i started
I only briefly scrolled through the history on this thread, but I saw the word "brackeys"
correct.
so I guess you're following his bad and outdated tutorials?
then wat do i do
that is 100% correct.
$helloworld
Written interactive course https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/
Videos https://dotnet.microsoft.com/learn/videos
these are good.
do u know him?
or like did u watch his toturials
its time for me to sleep
nrn
but
im bored and I might sleep so
thanks and goodbye
@zacharypatten
stop pinging people
if you have a question, ask it
ok fine
sorry
why isnt the console showing anything?
using System.Security.Cryptography.X509Certificates;
static void Main(string[] args)
{
wizard wizard01 = new wizard();
wizard01.name = "Wizardie boi";
wizard01.Favouritespell = "Chounga bounga";
wizard01.Spells = 7;
wizard01.experience = 0f;
Console.ReadKey();
for (int i = 7; i < 8; i--)
{
Console.WriteLine("Spell Slots: " + wizard01.Spells);
} Console.WriteLine(wizard01.name + "spells" + wizard01.Favouritespell);
} class wizard { public string Favouritespell; public string name; public int Spells; public float experience; public void CastSpell() { } } oops the copy paste messed up 1 sec oh it didn't mess up ..
} class wizard { public string Favouritespell; public string name; public int Spells; public float experience; public void CastSpell() { } } oops the copy paste messed up 1 sec oh it didn't mess up ..
using System.Security.Cryptography.X509Certificates;
static void Main(string[] args)
{
wizard wizard01 = new wizard();
wizard01.name = "Wizardie boi";
wizard01.Favouritespell = "Chounga bounga";
wizard01.Spells = 7;
wizard01.experience = 0f;
Console.ReadKey();
for (int i = 7; i < 8; i--)
{
Console.WriteLine("Spell Slots: " + wizard01.Spells);
} Console.WriteLine(wizard01.name + "spells" + wizard01.Favouritespell);
}
class wizard
{
public string Favouritespell;
public string name;
public int Spells;
public float experience;
public void CastSpell()
{
}
}
standby a moment, I need to test something
okay
I'd like you to look at your warnings list, please
alright
top one
wdym top one?
I mean, look at the top warning in that list
"The local function 'Main' is declared but never used"
yes, that one
i have nothing in mind to fix it
well
it's telling you what's wrong
Main
is never used
and the code you're expecting to run is inside Main
so, why would you expect it to run?
you never told it to run
this is why I despise the "top level statements" feature
as well as a whole host of other features that .NET has released in the past year or two that encourages people to write less code, at the expense of knowing how it fucking works
your code is effectively...
this compiles to
can you see the problem now?hmm wait
i think
when you tell a .NET program to run
rather, when you tell .NET to run a program
it looks for a
static Main()
method to use as an entry point
in this case, it finds MyNamespace.Program.Main()
MyNamespace.Program.Main()
declares a local function named Main()
never calls it
and then endsohhhh
i get it now
here is your template
but look
use this
copy paste?
as a template
fill in whatever namespace you actually want
oh
and put the code you want to run inside
Main()
wat is a namespace btw
a space for names
example pls?
a thing that lets you declare things with the same name, as long as they don't share a namespace
or how about an example from a project I'm currently working on
that'd be interesting
hmm i dont get it but im gonna leave namespaces for later
two classes
one is a model for a version of an Account record
one is a model for a version of a Transaction record
I can name them both
VersionEntity
, because they exist in separate namespaces
if I ever need to write code that deals with both accounts and transactions, I can refer to these classes as Accounts.VersionEntity
and Transactions.VersionEntity
(assuming I also have using Saaft.Data;
)
otherwise, I'd have to name them AccountVersionEntity
and TransactionVersionEntity
which wouldn't be terrible, but this is a little less verbose, and more flexiblei want to say something..
now sometimes i know how it works but i also do not know what to type in vs,
it's an issue im dealing with
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Criminal offensive Side eye
bombastic side eye
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.