#index chain too long, possible loop
1 messages · Page 1 of 1 (latest)
ay good news is that no one knows what u are doing
why u do oop if u dont know how to do oop
ur metatable loops so if u are concerned about the title error theres that
** You are now Level 7! **
i know oop a little
learn the basics bruh
i idd
u dont even know how to set it up
wdym
and why are we here
because you had an error which you cant even identify
which is caused by you not knowing what youre doing
cus it points to the same table
u dont even need oop for inventory
and its rather better not to use it
its not that simple
it is that simple
so should i restart?
for oop
when would you use oop
bruh ask chatgpt
i do it by feel
when something feels like it should be an object and have own methods
an item an enemy
but u dont have to use oop
i was trying to make methods for the inventory like adding to it and using items
ye u can do that but rather nah
not until i get better ig
oop is optional anyway
u can write everything like that
but it doesnt matter its good
just another approach
But wouldn't be oop perfect for an inventory system as every item can be identified as an "object" which has a state
item is not inventory
But it is inside an inventory and an inventory is an object aswell with a state
just a more complex one
doesnt change anything
and like i said u can make anything with oop
Im just asking because i thought it would make things much simpler
But im also quite new to oop so i might not know what im talking about and i've only used it for a Tower Defense game (I started this year with oop).
i dont like wrapping my inv
its just there as a table
Im sorry but i don't know what you mean by the term wrapping
should I keep the non metatable parts or just restart completely
making it oop
Well i mean oop is just a more complex table in way isn't it?
I see
- Since ur using datastores you should only access the player datastore when they enter the game and when they leave never inbetween.
- U should store the players the items as references so lets say they got a weapon liek this:
weapon = {
name = "sword",
damage = 20,
staminaCost = 10
You wouldnt save the whole table just save it as sword and when the player loads in the server will use that as a key to find the item that way we can avoid storing useless stats in the datastore.
- OOP is optional but when ur starting out its not that bad it kinda lets u get away with some stuff.
with methods ye
so its a table that gives you more options for the pay off of possible confusion when setting it up
can someone send that roblox scripter roadmap
where one of the points is violently hates oop
u can do whatever with metatables
its not as much about confusion as its about knowing what it does
I see
its not confusing in the slightest u js have some boilerplate and the rest is whatever u want
not sure where the oop hate is coming from its pretty good imo
i dont dislike it
yea I know just in general
ye i know i just wanted to present my opinion
its just youll find yourself mixing oop with other stuff and the code wont be as nice in the end
its cool for smaller projects
@terse mason if ur still struggling with ur code I can maybe look at it more thoroughly tomorrow if you want and give u some suggestions
i restarted
but i do have some questions
should i just use a table or keep the slot thing
this is my inventory
but thats the same inventory for every player
no thats per player
no
thats saved to datastore
how is it per player
["player1"] = {} -- that table its inventory,
["player2"] = {}
["player3"] = {}
he not gonna understand like that
lowk hard to explain
you just use the player as the key in the table
playerid?
or whatever
most people use profilestore so maybe u should too
u gonna understand it better then
isnt profilestore for saving data
what
all player data should be together
and u get player data through profilestore
and besides inventory is just a table
all the functions you write for it are technically separate
in a module script?
bruh
no like as for ur data structure
i aint gonna tell u step by step bruh
go chatgpt
it aint bad
i didn't see this shown
;compile lua lua local t={} t.__index=t setmetatable(t,t) print(t.foo) this is your error
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:4: '__index' chain too long; possible loop
stack traceback:
prog.lua:4: in main chunk
[C]: in ?
when a metatable's index has itself a metatable, lua will recursively search through the metatable index metatable until it finds the value.
if the metatable's index's metatable is the first metatable, this will loop infinitely like while true do end
that's why local t={} t.__index=t is lazy