#index chain too long, possible loop

1 messages · Page 1 of 1 (latest)

terse mason
#

i am trying to make a server sided inventory system for an mmorpg what does this bug even mean

#

i dont even know what im doing anymore

#

please someone

#

PLEASE

iron epoch
#

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

sand lynxBOT
#

studio** You are now Level 7! **studio

terse mason
#

i know oop a little

iron epoch
#

learn the basics bruh

terse mason
#

i idd

iron epoch
#

u dont even know how to set it up

terse mason
#

wdym

iron epoch
#

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

terse mason
#

yeah because ive never seen that error

#

also how does a metatable loop

iron epoch
#

cus it points to the same table

#

u dont even need oop for inventory

#

and its rather better not to use it

terse mason
#

then how do i set it up

#

ive been trying for a week

iron epoch
#

normally bruh

#

legit make a table for items

#

done

terse mason
#

its not that simple

iron epoch
#

it is that simple

terse mason
#

so should i restart?

iron epoch
#

probably

#

ts kinda horrifying

terse mason
#

alr thx

#

also then what is the point of using metatables

iron epoch
#

for oop

terse mason
#

when would you use oop

iron epoch
#

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

terse mason
#

i was trying to make methods for the inventory like adding to it and using items

iron epoch
terse mason
#

not until i get better ig

iron epoch
#

oop is optional anyway

#

u can write everything like that

#

but it doesnt matter its good

#

just another approach

undone wadi
#

But wouldn't be oop perfect for an inventory system as every item can be identified as an "object" which has a state

undone wadi
#

just a more complex one

iron epoch
#

and like i said u can make anything with oop

undone wadi
#

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).

iron epoch
#

its just there as a table

undone wadi
terse mason
#

should I keep the non metatable parts or just restart completely

undone wadi
undone wadi
swift anchor
#
  1. Since ur using datastores you should only access the player datastore when they enter the game and when they leave never inbetween.
  2. 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.

  1. OOP is optional but when ur starting out its not that bad it kinda lets u get away with some stuff.
undone wadi
iron epoch
#

where one of the points is violently hates oop

iron epoch
#

its not as much about confusion as its about knowing what it does

undone wadi
#

I see

iron epoch
#

its not confusing in the slightest u js have some boilerplate and the rest is whatever u want

swift anchor
iron epoch
swift anchor
#

yea I know just in general

iron epoch
#

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

swift anchor
#

@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

terse mason
#

i restarted

#

but i do have some questions

#

should i just use a table or keep the slot thing

swift anchor
#

what u mean about the slot thing

#

oh like inventory slots for the player?

iron epoch
terse mason
iron epoch
terse mason
#

no

iron epoch
#

thats saved to datastore

terse mason
#

how is it per player

iron epoch
#

i use profilestore here tho

swift anchor
iron epoch
#

lowk hard to explain

swift anchor
#

you just use the player as the key in the table

terse mason
#

playerid?

iron epoch
#

or whatever

#

most people use profilestore so maybe u should too

#

u gonna understand it better then

terse mason
#

isnt profilestore for saving data

iron epoch
#

it is

#

but thats what this abt

#

u index player data including inventory by player id

terse mason
#

so it wouldnt be seperate the inventory stuff and profile store

#

@iron epoch

iron epoch
#

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

terse mason
#

where do i start?

#

@iron epoch

#

question

iron epoch
#

u start at inventory = {}

terse mason
#

in a module script?

iron epoch
#

bruh

#

no like as for ur data structure

#

i aint gonna tell u step by step bruh

#

go chatgpt

#

it aint bad

terse mason
#

ok

#

wait i get it now

terse mason
#

yo i did it

#

the inventory saves now i just have to implement items

stoic axle
#

i didn't see this shown

#

;compile lua lua local t={} t.__index=t setmetatable(t,t) print(t.foo) this is your error

distant finchBOT
#
Program Output
/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 ?

stoic axle
#

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