Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Having classes modify higher order classes?

Yeah, this may seem a bit weird and complex as I'm going far into the concepts of OOP, but here me out. I have 3 objects: a GameBoard Object, a Card Object, and an Effect Object.

GameBoard has-a Card, and Card has-a Effect.

If I wanted Effect to provide instructions for GameBoard to modify its descendants, how would I do so? I was wondering if I could simply have a high order class like GameBoard read a function in from Effect, but I'd assume the variables of that function and all of its effects wouldn't be understood as they don't exist within Effect. Maybe even loadstring()()? I've been pondering this for months now and I wonder how I should revise my thinking.

2 comments

1

Counldn't you invoke the card to invoke the effect? ie: Have the gameboard call a function of Card that calls a function of effect and returns data back to GameBoard

0

Yes but what data am I to return? Functions of gameboard that are not visible to effect?

1 answer

My best shot at this is to pass a reference to the GameBoard itself to Effect.

Let's say you have a method of Effect - fire(), which reads the desired function. Make fire() take the parameter of GameBoard, so that Effect can use a reference to GameBoard

It would look like

Card.Effect:read(self)

This discussion is preserved as it was. New answers, comments, and votes are closed.