mob
var/Squad/squad
var/list/Squads = list()
Squad
var
name = "Squad"
Number = -1
Rank = "Unseated"
Level = 1
Exp = 0
MaxExp = 5000
Funds = 0
list/Members = list()
New(var/Num)
if(Num)
src.Number = Num
else return src.Number
..()
mob/proc
JoinSquad(var/Num)
var/Squad/S = new(Num)
if(!(src in S.Members))
S.Members += src.key
Squads += S
SaveSquads()
src.squad = S
Then the usage on the DblClick(), it is like this usr.JoinSquad(usr, 1)
Problem description:
- Hello, not gonna lie, I am trying to learn how datums work properly, I spent 1 day trying to make a Squad datum. I have read guides and took a few looks at other's people code and so on. I am not sure where I am failing but I don't intend to quit as a I want to improve my programming.
It seems like squad datum is always null no matter what. Am I missing initialization or something somewhere ?
Thanks!
The main thing i noted, eitherway, is how you're calling the JoinSquad proc. It doesn't currently match the parameter length you defined it to be expected to take, so going from how you've programmed things you would instead have:
Moving on, here are some further suggestions.
1. You should change the way you're adding players to a squad's member list so that you're handling that within the datum and not outside. You can pass in both a reference to the client and a number as arguments upon squad creation, in a fashion like below:
2. I also suggest you change the way you're currently approaching squad joining. A sensible way would be to have one proc/verb for creation of a Squad, and another verb for the joining of an existing squad. You'd then have things work either on an invitation basis (My suggestion for this being something along the lines of:
Ooor you could make it so that a mob has the choice to join an existing squad without invitation. This would not be very different to the InviteToSquad verb, at least for this example. What would change is the focus of the list chosen from so something like
As an extra it might be worth you taking a look at a Similar Topic made some time back, and reading through to get a better general idea on how to go about creating a system similar to yours.
A lot of what i would want to suggest (and more) is pretty well covered in that thread, i think you'd find it useful.
A related entry should also be helpful towards understanding how to go about the saving and loading aspects for each squad.
Edit: made some changes to code based on points made on the saving aspect and naming convention etc. Also made necessary changes in general to the post, attempted to remove fluff.