#(OOP) cyclic table and general help in oop

1 messages · Page 1 of 1 (latest)

quick garnet
#

When is table becoming cyclic? I always get an error (screenshot)

I'll explain as short as possible:

I wanted to create a game using oop. So:

in my game is going on:

  1. When player joins the game the server makes a SELF for that player and also the local side of player makes a SELF.

  2. Server sends a remote event to local side of player with the SELF properties (and because you can't pass metatables it returns just a table with all of its properties) to achieve the synchronization of player and server (because roblox does not provide that and oop in general)

  3. My game uses A LOT of module scripts and instead of connecting them all with setmetatable() (because it was 1. boring 2. long 3. non optimized for new modules) i decided to make a MODULELOADER which gets all of modules from the folder, requires it, gets functions and methods from it, then 3 tables is being created inside of player's SELF (self.Variables = {}, self.Tables = {}, self.Functions = {}).

  4. After the SELF gets all of that stuff (variables, tables and functions), goes next:

for i, v in pairs(self.Variables) do

self[i] = v

end

(and the same for self.Tables and self.Functions)

Why i did that? BECAUSE i think i will get a SELF metatable with all of containing functions (like the SELF was having all of those functions itself instead of requiring modules and calling them and blah blah blah.

I don't know will it work or not but i got a problem here.

You see, there is a "cyclic table". I thought it was because when i passed the "table" to put it into self.Tables then the system thought like (module script is a table itself so i will put it into self.Tables()) so it got error. I removed it but still something gets me "cyclic table".

Bro, i spent 2 months just creating the oop system, i want to drop it all and make usual game without modules. Help me please.

Also write down what you think about those complex things i made and is it easier for me just to make usual shit-code game. 😄

help me

#

i can also send some screenshots of everything that you think you need to solve this problem

#

but i think i just need someone of you guys to go into a voice call and explain what is going on and what to do

vale blaze
#

there's usually a specific line associated with the error, show this code

quick garnet
vale blaze
#

which line is the error

#

need to see the code around it

quick garnet
#

the first one SVG:FireClient()

#

as i said when i pass that it says "table cannot be cyclic"

#

i got no clue

vale blaze
quick garnet
vale blaze
#

lemme double check this

#

also you cannot send functions over remotes

quick garnet
#

but it's a table

vale blaze
#

i would've thought roblox had a catch for this

#

first i've seen it

#

anyway

#

it's because you're doing this

#

local t={} t.x=t print(t) game.ReplicatedStorage.remote:FireServer(t)

#

probably something in FullTheMethodsTable doing that

#

this is also a really bad technique, but i suppose you need to have tried it to understand why

vale blaze
# quick garnet

modifying a table while iterating on the table is usually bad idea

#

for k,v in t do self[k]=v end can have similar issues but eh it's a way to do things i suppose

#

working counts 👍

quick garnet
#

I just got no clue how to do better

vale blaze
quick garnet
#

ping the message how pls

vale blaze
#

you can either serialize/deserialize or change how your tables are set up to not be cyclic when sending through the remote

quick garnet
#

yeah i understand but how to set em up not for them to be cyclic

vale blaze
#

right now you are sending self.Tables which contains itself, meaning somewhere in your code you have self.Tables.self = self so when you go to send Tables, it sends the parent table which includes itself etc, it is recursive/cyclic

#

meaning when indexing your code right now, self.Tables.self.Tables.self.Tables.self.Tables.self.Tables.self.Tables is valid code

#

whatever you happened to name the 'self' as

vale blaze
#

so whatever that reason is, is what you need to change. the cyclic table is a symptom of a design choice you made elsewhere in your code

#

and now that you're aware of this, in all future code you write, you'll know to account for situations like this salute

quick garnet
#

and now i'm supposed to digest this information

vale blaze
vale blaze
somber locust
#

bro has fallen for the OOP trap

quick garnet
#

probably here...

#

Because self.Variables and self.Functions are doing great

#

they get no issues

#

only self.Tables