ID:264038
 
Code:
    proc
FightFinish(mob/A,mob/B)
begin
if(A.hp <= 0 && A.tourny == 1) /// YOU MIGHT HAVE TO CHANGE THIS INCASE YOUR HP VAR IS DIFF, see: your death proc for more info
world<<"<font color = white><font face = 'Comic Sans MS'>[B] has won against [A]!"
B.Battle = 0
A.Battle = 0
Entries.Remove(A)
A.hp = A.maxhp
A.loc = locate(1,3,1)
B.loc=locate(10,107,3)
Tournament_AI()
return // stop runtime errors
if(B.hp <= 0 && A.tourny == 1) /// YOU MIGHT HAVE TO CHANGE THIS INCASE YOUR HP VAR IS DIFF, SEE: your death proc for more info
world<<"<font color = white><font face = 'Comic Sans MS'>[A] has won against [B]!"
B.Battle = 0
A.Battle = 0
Entries.Remove(B)
B.hp = A.maxhp
B.loc = locate(1,3,1)
A.loc=locate(10,107,3)
Tournament_AI()
return // stop runtime errors
else
spawn(200)
goto begin

proc
Tournament_AI()
if(Entries.len==1)
world<<"<font color = white><font face = 'Comic Sans MS'>Tournament over, winner is:"
for(var/mob/K in Entries)
world<<K
Entries.Remove(K)
for(var/mob/M in world)
if(M.client)
M.verbs-=typesof(/mob/learn/verb/Join)
M.tourny=0
Tournament=0
return
doit
for(var/mob/M in world)
if(M.tourny)
var/A=pick(Entries)
var/B=pick(Entries)
if(A==B)
goto doit
sleep(10)
M<<"<font color = white><font face = 'Comic Sans MS'>Tournament Announcer: Okay lets start this match!"
sleep(20)
M<<"<font color = white><font face = 'Comic Sans MS'>Tournament Announcer: This match will be..."
sleep(30)
M<<"<font color = white><font face = 'Comic Sans MS'>Tournament Announcer: [A] .VS. [B]!"
B:loc=locate(16,115,3) /// locate them to a specific place.
A:loc=locate(4,115,3) /// locate them to a specific place.
sleep(30)
M<<"<font color = white><font face = 'Comic Sans MS'> Fight!"
A:Battle = 1
B:Battle = 1
FightFinish(A,B)


Problem description: For some reason whenever I host the tourny it picks one A, and one B, then a couple of seconds later 2 more people come in even though the battle isn't over. Any way to fix this, All help appreciated.

Ungh. No put goto statement in code.
Ungh. No put : operator in code.
In response to Kaioken
Kaioken wrote:
Ungh. No put goto statement in code.
Ungh. No put : operator in code.

What could you put instead of goto, would could you put to make the code do the same thing, but not have goto?
In response to Howey
var/mob/B=pick(Entries-A) // Picks someone random from Entries while taking away who was chosen for A


B is now typecasted as a /mob, giving it all inheritance of /mob. Therefore the : can be replaced with ., getting rid of the : abuse (the : abuse is strongly discouraged as, for example, if you decide to remove some variables - either getting rid of useless variable or redoing them - the typecast variable (X.y) will give a compile-time error where the semicolon operator (X:y) would not tell you until you get a runtime error when you attempt to use it.

Also, did you made sure to remove the fighters from the list when they were done/picked? What if there was an odd number of entries?
In response to Howey
Use a while() or for() loop to re-iterate those parts rather than a goto statement. It's much cleaner.
Also, when checking true or false variables, do not use the == (or !=) operator; put the value itself in the if() check directly, which will check directly whether it is true or false, and so is faster but also more robust. More info here: http://www.byond.com/members/ DreamMakers?command=view_post&post=37940
In response to GhostAnime
Wait I'm confused,
                        var/B=pick(Entries)
, What do I do with that code, do I delete it and only keep the code that you gave me , in the code, or do I put the code you gave me with an A variable too? I'm not sure :/