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