ID:1822684
 
(See the best response by Mightymo.)
Problem description:

What I'm trying to do is create a joint bank account for organizations coded into this specific game. The var for money is Yen, and Organizations have already been set up, but I'm having issues deciding how to go about doing this. The Organization Bank var can't be tied to the mob/leader, because it needs to be something anyone can contribute to at all times.

But the problem with making it a world var, would be that all organizations would have the same bank var, right? A friend suggested created savefiles for every organization, making the bank var a world var, and saving it in each Organization Savefile, but I'm not sure if that would work.

Any insight into this issue would be greatly appreciated! Thanks!
Create a datum, called account or something. Then instantiate it for each organization.
A datum? Uhhhh, I'm kind of a novice coder. Could you explain a little more?
Best response
http://www.byond.com/docs/ref/info.html#/datum

Datums are the highest level of data type, and pretty much all other types descend from them. They are great for storing information that will not be an object on the map.

For example:
Point
var
x
y

Creates a datum called Point. It stores an x value and a y value. This could be useful for storing something like coordinates.
var/Point/p = new /Point()

Creates a new Point.

You can access variables just like you would on an object or mob. You can override New() to allow parameters to be passed in to the object on creation, just like a mob or object. You can create procs under these in the same fashion.
I see, I see. So this can be specific to each organization, regardless of having a single var.

OrgAccount
var
JointBank=0


This creates the Organization Account, I get that. How do I access it to make it specific to these organizations, though?

proc/SaveOrg(mob/m)
var/savefile/F = new("Save/World/Organizations/[m.AOrganizationID].sav")
F["name"]<<m.AOrganization
F["id"]<<m.AOrganizationID
F["color"]<<m.AOrganizationColor


This is the savefile code for specific organizations. How would I be able to save it into the organization, then access it later? Would I even need to save it?

And how could I access it specifically? Like, for a verb that deposits Yen into the OrgAccount/var/JointBank var without it changing the var for everyone? Like I said, I want it to be different for each organization.
Sorry if I'm being a bit hardheaded. This is fairly new to me, and I'm trying to wrap my mind around it, aha.
It seems likely that your organizations themselves should be datums. In this way, your organization would save itself, rather than having a mob do it.

Something like what follows, perhaps?
Account
var
yen

Organization
var
ID
color
Account/bankAccount
proc
save()
... // saving stuff here


By doing it this way, access is pretty easy. Assuming you have an organization o, the account is o.bankAccount. The yen is o.bankAccount.yen. Remember that each organization has its own account, so changing values will not affect others. However, if the Account only stores yen, and no other information, you would be better off not creating a separate datum for the account, and just storing the yen in the organization.
An Organization O? You mean an Organization Object? That's something we don't really have, if I'm understanding what you mean right.

Could you please provide an example, perhaps, of a verb that deposits Yen directly into the account? Just so I can see if I'm understanding it right. There's a bunch of things that'll tie the Account Yen. Also, whats the difference between Account/var/yen and Organization/var/Account/bankAccount?
What I'm suggesting is that you restructure how your organizations are set up, as however you currently have them is likely going to cause headaches down the road.

What we likely want to do is add some extra procs to our Account object.
Account
var
yen
proc
addYen(var/amount)
yen += amount
setYen(var/amount)
yen = amount

By doing something like this, you can have the account capable of modifying its own variables, without external objects doing it.

Assuming that you use organizations like above, a player may look like this.
mob
player
var
yen
Organization/organization
verb
deposit(var/amount as num)
if(yen >= amount)
yen -= amount
organization.bankAccount.addYen(amount)


This allows the player to deposit yen into the account that belongs to their organization.

Also, whats the difference between Account/var/yen and Organization/var/Account/bankAccount?
The first is an Account that has yen in it, the secomd is an Organization that has an account. That account has yen.
Oh, I see, I see. I'm going to rework a bunch of things in according to these changes. I really appreciate your input, and if I can't get things to work out, I'll probably be posting again later tonight.

Thank you!
Organization
var
Name
ID
color
Account/bankAccount
proc
OSave()
var/savefile/F = new("Save/World/Organizations/[ID].sav")
F["name"]<<Name
F["id"]<<ID
F["color"]<<color


When creating an organization, how do I set the vars for the organization?

Organization.ID=rand(1,999999)


This doesn't work, so how would I call that?
You need to instantiate the Organization like any other object.
var/Organization/blueTeam = new /Organization()
blueTeam.ID = rand(1,999999)


However, you can set the Organization to automatically set itself up on creation.
Organization
New()
ID = rand(1,999999)
. = ..()

Then, when you create the new Organization, you don't have to set the ID each time.

As a side note, you could end up with collisions by calculating ID like that. Not likely, but you may want to reconsider your method.
mob
var
Organization/organization


Another thing, what exactly would this be used for? @_@ Sorry. I'm really trying to wrap my head around this, and the fact that you're tolerating my stupidity means alot ^^;
In a case like you post, a mob would have a variable called organization, which is a /Organization. Multiple mobs could have the same organization, or they could have different ones.

For example, say we have an Organization stored in blueTeam. If we have a player M, we could put
M.organization = blueTeam

to set the player's organization to blueTeam. From then on, anything that uses M.organization will reference that Organization.
One more thing. I'm kind of getting the hang of this, and understanding it better. What if I wanted to create a list of all the members, how would I add and remove members to that list?

Organization
var
list/Members
Name
ID
color
Description
Account/bankAccount
Rank1="Member"
Rank2="Recruiter"
Rank3="Co Leader"
Rank4="Leader"


As you can see, I've already created the members list, but I'm unsure of how to add it. I tried this, but it didn't work.
O.Members.Add("[usr.name]([usr.AOrganizationRank])")


This'll help because I want to be able to manage the organization members even when they're offline.
If a datum contains a variable which is another datum such as /list, that datum also needs to be instanced for it to work appropriately:
Organization
New()
..()
Members = new/list() // instances the Members list
bankAccount = new/Account() // instances the Account datum
You can do list initialization at the time you declare the variable.

Organization
var
list/members = list()


And you don't have to specify the type if you're instancing a type-cast variable and want it to be that type.

Organization
var
Account/bankAccount
New()
bankAccount = new()
. = ..()


Declaring the type the way Mr_Goober does is almost exactly the C# syntax, so if you're used to that or plan on using C# (if you plan on using Unity, for example), then that might be more comfortable.
Okay, now that I've completely reset how organizations work, I've started back on my original goal of the Organization Bank Account.

Organization
New()
bankAccount=new()
.=..()
var
Name
ID
color
Description
Account/bankAccount
Rank1="Member"
Rank2="Recruiter"
Rank3="Co Leader"
Rank4="Leader"
proc
OSave()
var/savefile/F = new("Save/World/Organizations/[ID].sav")
F["name"]<<Name
F["desc"]<<Description
F["id"]<<ID
F["color"]<<color
F["rank1"]<<Rank1
F["rank2"]<<Rank2
F["rank3"]<<Rank3
F["rank4"]<<Rank4


This is currently how it's set up, taking the advice from MisterPerson to instance the bankAccount var. I also added when creating an organization, it automatically adds 50,000 Yen to the organization's account.
usr.aorganization=O
O.bankAccount.addYen(50000)


In this case, O is set up as var/Organization/O=usr.aorganization.

The issue with this is, when I tested it, instead of adding 50,000 yen, the organization's yen became "/Account". I'm unsure of the issue here because this is all so new to me..
It sounds like you're trying to access yen like
O.bankAccount

rather than
O.bankAccount.yen
Organization_System_Apophis.dm:133:error: O.bankAccount.yen.addYen: undefined proc
Page: 1 2