#Can someone teach me OOP (Object orientated programming)
1 messages · Page 1 of 1 (latest)
you need to know how to script to learn OOP
Oop is hot garbage forget about it (everyone who says otherwise is coping)
it is?
huh
It is indeed NOT
its one of the most important things to learn wehn you actually want good code
i dont understand oop very well, i kinda understand that metatables can allow you to call things that may not exist yet but i personally havent found a good use for it yet... i did make a game without any oop i just dont really understand oop enough yet
i am currently making a game that contains no oop*
solely because i dont understand
OOP is kinda self expainable "Object Orientated Programming"
Heres an example of the use of OOP:
--No OOP
local part = script.Parent
local function killPlayer()
--bla bla bla get player
--set player health to 0
end
part.Touched:Connect(function(hit)
killPlayer()
end)
--With OOP
local partsFolder = game.Workspace.KillParts:GetChildren()
local function killPlayer()
--bla bla bla get player
--set player health to 0
end
for _, part in partsFolder do
part.Touched:Connect(function(hit)
killPlayer()
end)
end
we are trying to build our code easily expandable
and try to not reuse the same code snippet over and over again
setting a metatable allows you to set classes with default values for objects even when the objects dont exist yet - something like that
also zyos73 i use that but i didnt know that was OOP????
well metatables is another example of OOP
you just try to not reuse code snippets over and over again and make code OBJECT ORIENTATED
ye its easy theres just diffrent depths of OOP
like metatables is are advanced for example
yeah i dont understand metatables very well myself - but i definitely understand functional coding and looping through folders
ye OOP involves much loops and arrays
using functions and just calling them whenever i want to do a specific action
ye
its cuz LUAU does not have traditional 'OOP' like java or c# does
so you kinda gotta make it up
ig idk I dont code with java or c#
classes are built into the language - lua does not have classes
--!strict
-- @zyos73
-- 07/29/25
--Use: debugger(-1, script, debug.info(1, "l"), nil)
local debug_messages = require(script.debug_messages)
local config = require(script.Parent.config)
return function(code : number, script : Instance, line : number, info : any)
if not config.global.debug then return end
info = info or "No Info"
local msg = debug_messages[code]
if not msg then
warn("\n[DEBUG] \n Message not found for: " .. code)
warn("\n[DEBUG]", "\nScript:", script, "\nLine:", line, "\nMessage:", msg, "\nInfo:", info, "\n")
return
end
print("\n[DEBUG]", "\nScript:", script, "\nLine:", line, "\nMessage:", msg, "\nInfo:", info, "\n")
end
heres another use case for modules you dont want to use this script every time you wanna debug something so you can just require the module and call the variable
are these like javascript classes? i used those in school
i think so
minecraft java is what i was talking about not javascript
but ye
i think thats right
ye i know but i only use javascript for school and luau lol
we also use a little C++ in school but I dont rlly like it tbf
int main {
yes sum like that
why is main an integer
I got no idea bro
lol
i dont even know if its C++
//www.elegoo.com
//2016.12.09
// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(500);
}
idk what this is
yes its definitely C something
void means return nothing
OOP wont help you script, youre going to have learn scripting first before moving onto OOP, but OOP can help in cases of game/engine development whenever you do decide to tackle it!
now.. bare with me as im very bad at c++ but here is an example 
struct Sprite
{
SDL_Texture* SpriteTexture;
float x,y,w,h;
Sprite(SDL_Renderer* renderer, const char* SpriteLocation, int Nx, int Ny, int Nw, int Nh);
void render(SDL_Renderer* renderer);
void editTransform(float Nx, float Ny, float Nw, float Nh);
void editTransformWithVector2(Vector2 vector);
Vector2 GetVector2();
};
this is an example of an object base! it has in-game position variables like x,y,w,h aswell as functions.
also for the record just know that structs and classes are pretty much the same except for the exception of public and private categories for variables or functions, classes aren't needed for my environment but they work similarly!
now these functions only affect the specific struct you call them from, for example:
Sprite MoveToolSelectedSprite(renderer, "Textures/MoveToolSelected.png",0,0,50,50);
here we define the object!
MoveToolSelectedSprite.render(renderer);
and here we render that specific object! 
you can have as many "objects" you want then edit their attributes individually.
and thats about it. 
the c++ stuff was irrelevant that was just a convo between me and zyros
OP (sandwicheater) probably meant script = lua script for roblox
oh, my bad lmao 😭 the first thing i saw in this thread was about c++ so i thought OP meant cpp 🥀
lua doesn't have classes / structs, i don't think OP would be asking the right question in that case 😔
you are correct tho you do have to learn the basics of scripting before learning oop