#having trouble with items.

1 messages ยท Page 1 of 1 (latest)

narrow torrentBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
When I run my program the items in room and characters in room show as null although ive added the items etc to the rooms.

It sounds like there may be an issue with how you are adding the items to the rooms. Make sure that you are properly initializing the items in the room class and then adding them to the room object in your main program.

Double check that you are calling the correct methods to add the items to the room and that you are not accidentally overriding them with null values somewhere in your code.

Additionally, ensure that when you are displaying the items in the room, you are accessing them correctly from the room object.

If you are still having trouble, consider debugging your code by printing out the values of the items and rooms at various points in your program to see where things may be going wrong.

It might also be helpful to get a fresh pair of eyes on your code by asking for help from fellow developers on the discord server or posting your code for review. Sometimes a different perspective can help identify issues that may have been overlooked.

vernal ferry
#

main game class

#

room class

forest bloom
#

@vernal ferry you probably don't want to share this

vernal ferry
#

whys that

forest bloom
#

I mean, if you are fine with leaking your name, it's not a problem I guess

vernal ferry
#

oh one sec

narrow torrentBOT
forest bloom
#

Same here

vernal ferry
narrow torrentBOT
radiant moon
#

ur still having issues with wrong responsibilities in ur class

#

all of this here makes no sense to put into the Room class

#

see, with that setup, each room that u create, for example a bathroom, will contain a Game, contain a second room called currentRoom, contain outsideItems, mainItems, officeItems,....

#

that's for each room that u have

#

so if u create 10 rooms, u have 10 games, 10 currentRoom, 10 outsideItems, 10 mainItems,...

#

that's just incorrect. not what u want

#

Room is the perspective of a single room. not the perspective of the manager of rooms

vernal ferry
#

how would i list the the items ive added to the arraylists then?

radiant moon
#

not in the room class

#

a room may have a List<Item> myItems

#

but not lists of items for any room in the game

#

like, why would all ur rooms maintain lists of all rooms in the game

#

a room has to maintain its own items

#

not the items of everyone else

vernal ferry
#

so do i keep that in game class?

radiant moon
#

u as a person have ur own money bag. and not one billion money bags of everyone else on earth

#

yes, all that stuff goes to whoever manages rooms

#

which is likely Game

vernal ferry
#

so what type of stuff would i specifically include in the classes

#

so what should room class include?

radiant moon
#

room includes whatever makes up a room

#

describe what a room has and can do

#

a single room

#

it has a description. it has exits to other rooms. it has a list of items

#

so. add these 3 things

#

done

vernal ferry
#

hmm alright

#

and one last thing am i overusing these questions posts or is this how its meant to be used?

radiant moon
#

nah ur fine. its how its keant to be used ๐Ÿ™‚ feel free to make a million threads

#

๐Ÿ‘Œ

vernal ferry
#

alright thank you very much

#

where should something like a pickup command be then

#

in the player class

#

or game (main class)?

#

and is there some sort of video that goes other this structuring stuff?

radiant moon
radiant moon
#

while room then has a method to remove an item from its list and player one to add an item

vernal ferry
#

i have inventory class i said player instead sorry

radiant moon
#

an inventory definitely won't deal with rooms

#

inventory should offer methods to adf/remove items

#

but not have anything to do with a room

vernal ferry
#

yh pickup adds item to inventory no?

#

so shouldnt inventory deal with that?

radiant moon
#

inventory should offer a method to add an item to it. but it should not have a method "ill pickup an item from a room"

#

someone else decides where the item is taken from

#

not inventory

#

ur money bag also doesn't execute a transfer from ur bank account. that's u who does that

#

not ur bag

#

ur bank offers a method to deposit. ur bag a method to put money into it. but u, the human, has the method to "takeMoneyFromBankAndPutItIntoBag"

vernal ferry
#

then im just gonna end up moving everything to game class, is that not bad?

radiant moon
#

everything? no, only the stuff that shouldnt belong elsewhere

#

and yes, if ur game class keeps growing u should split responsibilities further

vernal ferry
#

well if i move pickup etc there then am putting most of the responsibilty on the game class

radiant moon
#

well. first of all u need to move everything to the right place. cause right now it's not just a design/style issue but leading to a setup that makes no sense logic-wise and hence is impossible to get working without severe bugs

#

once thats done u can approach making it nicer

vernal ferry
#

yh im having trouble understanding what should be where, how can i understand this or learn

radiant moon
#

perhaps u need to step back and consume some oop lessons and do exercises

#

i feel like u didn't fully grasp the purpose and responsibilities of a class

vernal ferry
radiant moon
#

In particular since u keep adding stuff to them that is the responsibility of a manager of the class rather than what a single instance of it deals with

#

which then consequently ends up being impossible to get working

#

bc that's not how classes work

vernal ferry
narrow torrentBOT
vernal ferry
#

when i try to call the methods from player class i am getting error

#

although i have created and object of player class