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
glutonium
glutonium2mo ago
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
Jochem
Jochem2mo ago
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
unluqy
unluqyOP2mo ago
🥲
No description
unluqy
unluqyOP2mo ago
idk if that counts as selling but yeah
glutonium
glutonium2mo ago
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
class Vector {
int x, y;

Vector(int x, int y): x(x), y(y) {}
}
class Vector {
int x, y;

Vector(int x, int y): x(x), y(y) {}
}
here the x,y and even the constructor is private. so i have to make them public by doing
class Vector {
public:
int x, y;

Vector(int x, int y): x(x), y(y) {}
}
class Vector {
public:
int x, y;

Vector(int x, int y): x(x), y(y) {}
}
so incase this is same for c# make sure to make them public
Jochem
Jochem2mo ago
bro really went ahead and tried even though I just told him... you may want to block him
unluqy
unluqyOP2mo ago
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
glutonium
glutonium2mo ago
u can try searching up and see if others have faced same issues or not
unluqy
unluqyOP2mo ago
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
No description
No description
unluqy
unluqyOP2mo ago
oh okyy okayy
glutonium
glutonium2mo ago
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
glutonium
glutonium2mo ago
if u just go here and search c# you'll see
No description
unluqy
unluqyOP2mo ago
ohh right well thanks a bunch haaha, sorry i thought it meant like backend in general
glutonium
glutonium2mo ago
where is this game state var located? like in which scope?
unluqy
unluqyOP2mo ago
uhh
glutonium
glutonium2mo ago
is this inside the Game1 class?
unluqy
unluqyOP2mo ago
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
unluqy
unluqyOP2mo ago
No description
glutonium
glutonium2mo ago
ok and where r u trying to access this var? in the screenManager class?
unluqy
unluqyOP2mo ago
yup
glutonium
glutonium2mo ago
so screenManager extends the game1 right?
unluqy
unluqyOP2mo ago
No description
unluqy
unluqyOP2mo ago
yeah (thats all that comes up when i try find it)
glutonium
glutonium2mo ago
after u typme gameState, what does it say when u hover over the squiggly red line?
unluqy
unluqyOP2mo ago
does not exist in current context
glutonium
glutonium2mo ago
i see that your Game1 is a public class while screenManager is internal class, could that be a problem?
glutonium
glutonium2mo ago
why is there those 3 dots ? wut does it say
No description
unluqy
unluqyOP2mo ago
idk why its saying this tbh
No description
unluqy
unluqyOP2mo ago
i can try change it to a public class rq
glutonium
glutonium2mo ago
try it
unluqy
unluqyOP2mo ago
yeah still nothing
glutonium
glutonium2mo ago
this is just naming convntion it seems like classe names should start with uppercase this is just convention
unluqy
unluqyOP2mo ago
i have joined a c sharp discord tho so if ur busy dont burden urself with me haha oohh
glutonium
glutonium2mo ago
nah its ok imma get dinner rq cya
unluqy
unluqyOP2mo ago
mhm! thanks tho (:
Want results from more Discord servers?
Add your server