OOP guidance (for myself)
I'm having a real tough time grasping OOP for a project in school using Monogame, like I can't quite figure out how to reference variables / sprites and such from other classes, maybe i'm just being silly but I was looking for any in depth OOP guides, tips or even talks from people
35 Replies
i mean, tbh, the best way to understand and learn OOP is just through practicing
i started with JS classes
which helped me get some basic understanding
and some intermediate as well
right now i am doing C++ which is also kinda teaching me some
it would be much more helpful if you could provide help here, so others can learn from it too. I do feel the need to point out that if you're trying to sell anything by asking folks to DM you, and we get reports of this, it's considered a violation of #📝rules 7
If you're just being helpful (for free) and prefer one on one contact, that's fine
🥲

idk if that counts as selling but yeah
like I can't quite figure out how to reference variables / sprites and such from other classes,make sure those varables are public. public methods and properties are accessible from outside the class by anyone. idk about c# but there is something called
friend
in c++ which can grant access to private props and methods as well in case if that helps u
in cpp , classes has all methods and props private by default . which means
here the x,y and even the constructor is private. so i have to make them public by doing
so incase this is same for c# make sure to make them publicbro really went ahead and tried even though I just told him... you may want to block him
already done haha thanks
yup theyre public, i guess it's my fault for starting to code in the main game1 folderi nstead of branching and making a class beforehand, i tried even making my new class a child of the main one and still couldnt grab certain aspects that i needed of it though
u can try searching up and see if others have faced same issues or not
for instance, i want to try get a hold of the gameState variable from the main program to make if conditions etc in the new class


oh okyy
okayy
also , since this is web dev focused server, it is less likely to get help here
there are c# specific servers out there, you'll get better help from there
if u just go here and search c# you'll see

ohh
right well thanks a bunch haaha, sorry i thought it meant like backend in general
where is this game state var located?
like in which scope?
uhh
is this inside the Game1 class?
i defined it under my game1 class when naming the other attributes but since i made the screenManager a child of that, i shouldve been able to reference it
yeah

ok and where r u trying to access this var?
in the screenManager class?
yup
so screenManager extends the game1
right?

yeah
(thats all that comes up when i try find it)
after u typme
gameState
, what does it say when u hover over the squiggly red line?does not exist in current context
i see that your Game1 is a public class while screenManager is internal class, could that be a problem?
why is there those 3 dots ? wut does it say

idk why its saying this tbh

i can try change it to a public class rq
try it
yeah still nothing
this is just naming convntion
it seems like
classe names should start with uppercase
this is just convention
i have joined a c sharp discord tho so if ur busy dont burden urself with me haha
oohh
nah its ok
imma get dinner rq
cya
mhm! thanks tho (: