ID:572880
 
(See the best response by Forum_account.)
I'm not gonna deny it, I suck at debugging my own code. I guess it's something to do with my calculation abilities, but I really fail at finding bugs etc in my own code.

I made a team system today, it's extremely messy, and I just want to know if it has a lot of tiny bugs in it - no need to post a cleaner format or anything. : P

So, could somebody proofread this, please?

mob

var

tmp

team

list

team_mates


team

verb

Guild_Chat (msg as text)

set category = "Team"

if (muted)

usr << "<font color = red><b>You're muted!</b></font>"

else

if (msg)

for (var/mob/m in world)

if (m.team == usr.team)

m << "<b>Team:</b><font color = #99ffff> [name]</font>: [msg]"

Leave_Guild ()

set category = "Team"

for (var/mob/m in world)

if (m.team == usr.team)

m << "<b><font color = red>[usr] has left the team!</font></b>"

usr.team_mates -= m

m.team_mates -= usr

usr.team = null

team_leader

verb

Boot (mob/m in usr.team_mates)

set category = "Team"

m << "<b><font color = red>You have been booted from [m.team]!</font></b>"

usr << "<b><font color = red>You have booted [m] from the team!</font></b>"

usr.team_mates -= m

m.team_mates -= usr

for (var/mob/h in usr.team_mates)

h.team_mates -= m

m.team_mates -= h

m.team = null

Invite ()

set category = "Team"

var/potentials = list ()

for (var/mob/m in world)

if (m.client)

if (!m == usr)

if (!m.team)

potentials += m

var/mob/inv = input ("Who do you wish to invite?") in potentials

var/answer = input(inv, "Do you want to join [usr]'s team, [usr.team]?", "Team") in list ("Yes", "No")

switch (answer)

if ("Yes")

inv.team = usr.team

inv.team_mates += usr

for (var/mob/f in usr.team_mates)

inv.team_mates += f

usr.team_mates += inv

for (var/mob/a in world)

if (a.team == usr.team)

a << "<b><font color = yellow>[inv] has joined the team!</font></b>"
Why do you have an empty line between each line of code?
In response to Zerok Kaiba
Zerok Kaiba wrote:
Why do you have an empty line between each line of code?

Whitespace.
Yeah, it's just a habit I've developed. It's much easier to read your own code if you whitespace like that.
In response to Shaoni
Shaoni wrote:
Yeah, it's just a habit I've developed. It's much easier to read your own code if you whitespace like that.

Using whitespace loses its significance if you *always* put one blank line between two lines of code. You should use whitespace to group related things together. For example:

team_leader
verb
Boot(mob/m in usr.team_mates)
set category = "Team"

m << "<b><font color = red>You have been booted from [m.team]!</font></b>"
usr << "<b><font color = red>You have booted [m] from the team!</font></b>"

usr.team_mates -= m
m.team_mates -= usr

for(var/mob/h in usr.team_mates)
h.team_mates -= m
m.team_mates -= h

m.team = null

This makes more sense. Also, it acts as a grouping mechanism if you want to add comments:

team_leader
verb
Boot(mob/m in usr.team_mates)
set category = "Team"

// Output messages to each player.
m << "<b><font color = red>You have been booted from [m.team]!</font></b>"
usr << "<b><font color = red>You have booted [m] from the team!</font></b>"

// Update each player's team_mates list.
usr.team_mates -= m
m.team_mates -= usr

// Update their teammates' team_mates lists.
for(var/mob/h in usr.team_mates)
h.team_mates -= m
m.team_mates -= h

// Clear the booted player's team.
m.team = null

Blank lines split the code into segments, and each comment clearly applies to a segment.

Here is an article I wrote about whitespace and comments =)
Best response
Also, more on topic, for a player leaving a team I'd just do this:

team_leader
verb
Boot(mob/booted in usr.team_mates)

// Let the players know what happened.
usr << "You booted [booted] from the team."
m << "[usr] booted you from the team."

// Remove the booted player for all of their
// teammates lists of teammates.
for(var/mob/m in booted.team_mates)
m.team_mates -= booted

// Clear the booted player's list of teammates.
booted.team_mates.Cut()
booted.team = null

Though really, I'd probably do it like this:

mob
proc
leave_team()
// Remove this player for all of their
// teammates lists of teammates.
for(var/mob/m in team_mates)
m.team_mates -= src

// Clear the player's list of teammates.
team_mates.Cut()
team = null

team_leader
verb
Boot(mob/booted in usr.team_mates)

// Let the players know what happened.
usr << "You booted [booted] from the team."
m << "[usr] booted you from the team."

// Do the operations to make the player
// actually leave the team.
m.leave_team()

There may be many situations where a player leaves a team - they get booted, they leave voluntarily, they log out, etc. This is really the same event - the team_mates lists are all updated in the same way. The only difference is the message you output (ex: "so-and-so was booted", "so-and-so left the team", etc.). Your Boot verb just has to output the appropriate messages and call the leave_team() proc. Your Leave_Guild() verb would be almost the same, it'd just output different messages.
Yeah, thanks, that definitely looks much easier. Guess I had a brain freeze there.