ID:151912
 
Ok so Ive been coding for awhile and have been avoiding this and going about it in probably a difficult way but im doing a lot of revamping in my code for my game and decided to ask the dumb questions. I have two parts to this question. So I want to have a lot of datums for various things in my game, like for my market system and mail system, cause I think they will be more suited for what im doing than what im using now. Right now im creating a mob to use as a holder of the items and adding the items to that mobs contents and just saving it when the world is shutdown.

The problem I have is accessing that mobs contents, the way I can think of doing it is cycling through the mobs with a for loop like this
for(var/mob/Shopkeeper/S in world)

But I was wondering if there is a better more efficient way to access something and assign it to a variable that way I can use datums

So if I end up using datums instead (which i think would be a better choice) I was thinking of creating a Market datum for example and have list for the different types of objects in that datum. But the problem im coming across (something that is probably real basic that I missed while learning) is how to access the datum when I need to call up the items in the market.

Also if you think there is a better way than datums to do this im open to suggestions
I would probably use a market datum as well. I'm not sure how your game plays, so I really don't know what to suggest. Is this like an RPG shop with a shop keeper, or more like a menu system tied to some place on the map?

I suspect whatever your system, the player has to interact with an object of some sort to access the market and mail. I would attach the datum to that. Your system can then just jump off the interaction the player started and handle everything between itself, the datum it holds and the player. The object the player clicked or whatever would act s the interface between the player and the datum tied to the object. So... basically, that object or whatever has a variable to point to the mail or market datum. The datum handles actually managing the mail or store, so you could have many objects all pointing to the same single market or mail datum.
In response to Xooxer
First it is an RPG...Ok so for example my mail system is set up to where players can send messages/money/item to each other across the world using a messenger hawk. It will either go directly to the player (if they are online) or store it in the mailbox (if they are offline). They go to a "Mailroom" and talk to the guy to check their mail once they are online. And my market is a similar process they will talk to a certain type of npc but there will be more than one of the same. So say i have the following code how are you saying to link it im a little confussed on what you mean as a link and where would i create and store the datum
mob/Mailman
verb/Check_mail()//what would a put here

Mailbox//and how would i set this up so there is a datum in the world
var/Mail=list()//add messages to this list messages are made as objects

right now im doing something like this
var/list/Storage=list(new/Mailbox,new/Market)

for(var/Mailbox/M in Storage)
blah
In response to NightJumper88
Looks like you only want one instance of each object in the game? You'd simply use a global var for that, just like how DM's built-in world object is handled.
Mailbox
var/name = "mbox"
var/Mailbox/mailbox = new
mob/verb/Hi()
src << mailbox.name //this displays "mbox"
In response to NightJumper88
I mean something like:

var/PostOffice/Post

world
New()
Post = new()
..()

proc/GetMob(MobName)
for(var/mob/M in world)
if(M.name == MobName)
return M

Mail
var/Recipient
var/Sender
var/Sent_Date
var/Subject
var/Message

verb
Read()
usr << "On [Sent_Date], [Sender] wrote regarding [Subject]."
usr << Message

PostOffice
var/list/mailbin

proc
GetMail(var/Recipient)
. = list()
for(var/Mail/M in mailbin)
if(M.Ricipient == Recipient)
mailbin -= M
if(!mailbin.len) mailbin = null
. += M

SendMail(var/Mail/M)
var/mob/Recipient = GetMob(M.Recipient)
if(!Recipient)
if(!mailbin) mailbin = new()
mailbin += M
else M.Move(Recipient)

mob/Mailman
verb/CheckMail()
var/list/L = Post.GetMail(usr.name)
if(!L || !L.len) usr << "No mail today!"
else for(var/Mail/M in L)
M.Move(usr)

In response to Xooxer
ok thanks i get it now im just an idiot sometimes I guess thats what happens when you only code when your tired. I was forgetting i could just define a global variable for it.

Thanks