ID:821987
 
(See the best response by LordAndrew.)
    proc //proc
battleinput() //proc's name
while(1) //while 1 is true which is always
if(src.loc==locate(12,6,1) | src.loc==locate(12,3,1) | src.loc==locate(11,9,1) && src.pturn) //if the location of myself and my 2 allies is true as well as if its my turn. pturn means player's turn.
for(var/mob/enemy/Prowler/o in locate(15,6,1)) //defining enemy 1: Prowler that already exists in location 15,6,1 of my map
for(var/mob/enemy/Bandit/i in locate(15,3,1)) //same as above but with Bandit
var/tmp/action=input("What would you like to do?") in list ("Attack", "Run") // input turn actions. variable is "action"
if(action=="Attack") //if that action is attack
var/tmp/attackwho=input("Attack who?") in list ("Enemy 1", "Enemy 2") // second input this time choosing to attack who. variable is "attackwho"
if(attackwho=="Enemy 1")//if chosen enemy 1
var/tmp/randomdmg = rand(1,10) // random damamge variable
o.hp-= randomdmg //"o" Prowler variable is damaged randomly
world << "[src] attacks [o] for [randomdmg] dmg" //outputs into the world what has happened. the player attacked prowler for that random damage
src.pturn=0 // player's turn becomes 0 so its not my turn anyore
if(attackwho=="Enemy 2") //same as above just enemy 2
var/tmp/randomdmg = rand(1,30)
i.hp-=randomdmg
world << "[src] attacks [i] for [randomdmg] dmg"
src.pturn=0
if(gturn==2) //if global turn is 2(which it would be after Prowler attacked) then it will be 3 so that after its my turn it will be Bandit's turn.
gturn=3
else if(gturn==1) //if it was global turn 1 then it will be 2 making it Prowler's turn
gturn=2
if(action=="Run") // if chose the action Run
if(prob(20)) // 20% probability to run away
src.loc=prevloc // returns to previous location as I defined it in the Move() proc
src.pturn=1 //returns player's turn to 0 if run away
src.pturn=0 // if I don't run away then its no longer my turn
gturn=2 // global turn 2 making it Prowler's turn
sleep(10)

enemyinput() //proc's name
while(1) //while 1 is true which is always
for(var/mob/q in locate(11,9,1)) //defining allies at that location
for(var/mob/y in locate(12,3,1))
for(var/mob/s in locate(12,6,1))
if(q.loc==locate(11,9,1) && y.loc==locate(12,3,1) && s.loc==locate(12,6,1) && !s.pturn && !y.pturn && !q.pturn) //as long as you and your allies exist at those locations and its not their turns, continue the code
if(gturn==2) //if its global turn 2
var/tmp/random=rand(0,1) //variable "random" is random 0-1 it will do either attack or super attack
if(random==0) //if random is 0
var/tmp/turn=rand(0,2) //"turn" random variable 0-2 for who to attack
if(turn==0) //if that random comes up 0
var/tmp/randomdmg = rand(0,10) //random damage
q.hp-= randomdmg //random damage to q player
world << "[src] attacks [q] for [randomdmg]" //world say that the enemy attacks q player for random damage
else if(turn==1) //same as above
var/tmp/randomdmg = rand(0,10)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
else if(turn==2)
var/tmp/randomdmg = rand(0,10)
y.hp-=randomdmg
world << "[src] attacks [y] for [randomdmg]"
s.pturn=0//not s' turn
y.pturn=0//not y's turn
q.pturn=1//q player's turn
gturn=3 // global turn 3
if(random==1) // if that random was 1 then its super attack one of the 3 players
var/tmp/turn=rand(0,2)
if(turn==0)
var/tmp/randomdmg = rand(1,30)
q.hp-=randomdmg
world << "[src] Super Attacks [q] for [randomdmg]"
if(turn==1)
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] Super Attacks [s] for [randomdmg]"
if(turn==2)
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] Super Attacks [y] for [randomdmg]"
s.pturn=0
y.pturn=0
q.pturn=1
gturn=3
for(var/mob/y in locate(12,3,1)) //same aas above
for(var/mob/s in locate(12,6,1))
if(y.loc==locate(12,3,1) && s.loc==locate(12,6,1) && gturn==2)
var/tmp/random=rand(0,1)
if(!random)
var/tmp/turn=rand(0,1)
if(!turn)
var/tmp/randomdmg = rand(1,30)
y.hp-=randomdmg
world << "[src] attacks [y] for [randomdmg]"
else if(turn)
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
y.pturn=1
s.pturn=0
if(random)
var/tmp/turn=rand(0,1)
if(turn==0)
var/tmp/randomdmg = rand(1,30)
y.hp-=randomdmg
world << "[src] super attacks [y] for [randomdmg]"
else if(turn==1)
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] super attacks [s] for [randomdmg]"
gturn=3
for(var/mob/s in locate(12,6,1))
if(gturn==2)
if(s.loc==locate(12,6,1))
var/tmp/random=rand(0,1)
if(random==0)
var/tmp/randomdmg = rand(1,10)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
if(random==1)
var/tmp/randomdmg = rand(1,10)
s.hp-=randomdmg
world << "[src] super attacks [s] for [randomdmg]"
sleep(100)
s.pturn=1
gturn=3
sleep(10)

//code below same as above

enemyinput1()
while(1)
for(var/mob/q in locate(11,9,1)) // last one goes first
for(var/mob/y in locate(12,3,1))
for(var/mob/s in locate(12,6,1))
if(q.loc==locate(11,9,1) && y.loc==locate(12,3,1) && s.loc==locate(12,6,1) && gturn==3 && !q.pturn && !y.pturn && !s.pturn)
var/tmp/random=rand(0,1)
if(random==0)
var/tmp/turn=rand(0,1)
if(turn==0)
var/tmp/randomdmg = rand(1,10)
q.hp-=randomdmg
world << "[src] attacks [q] for [randomdmg]"
else if(turn==1)
var/tmp/randomdmg = rand(1,10)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
else if(turn==2)
var/tmp/randomdmg = rand(1,10)
y.hp-=randomdmg
world << "[src] attacks [y] for [randomdmg]"
s.pturn=1
y.pturn=0
q.pturn=0
gturn=1
if(random==1)
var/tmp/turn=rand(0,2)
if(turn==0)
var/tmp/randomdmg = rand(1,30)
q.hp-=randomdmg
world << "[src] Super Attacks [q] for [randomdmg]"
if(turn==1)
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] Super Attacks [s] for [randomdmg]"
if(turn==2)
var/tmp/randomdmg = rand(1,30)
y.hp-=randomdmg
world << "[src] Super Attacks [y] for [randomdmg]"
gturn=1
for(var/mob/y in locate(12,3,1))
for(var/mob/s in locate(12,6,1) && y.loc==locate(12,3,1) && s.loc==locate(12,6,1) && gturn==3)
if(s.loc==locate(12,6,1) && y.loc==locate(12,3,1) && s.loc==locate(12,6,1))
var/tmp/random=rand(0,1)
if(random==0)
var/tmp/a=rand(0,1)
if(a==0)
var/tmp/randomdmg = rand(1,10)
y.hp-=randomdmg
world << "[src] attacks [y] for [randomdmg]"
else if(a==1)
var/tmp/randomdmg = rand(1,10)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
if(random==1)
var/tmp/a=rand(0,1)
if(a==0)
var/tmp/randomdmg = rand(1,30)
y.hp-=randomdmg
world << "[src] super attacks [y] for [randomdmg]"
else if(a==1)
var/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] super attacks [s] for [randomdmg]"
y.pturn=1
s.pturn=0
gturn=1
for(var/mob/s in locate(12,6,1))
if(gturn==3)
var/tmp/r=rand(0,1)
if(r==0)
var/tmp/randomdmg = rand(1,10)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
if(r==1)
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] super attacks [s] for [randomdmg]"
sleep(100)
s.pturn=1
gturn=1
sleep(10)


Problem description: I check for src.pturn through a verb when its my turn and it says 0 when it pops up. But I made the if statement that the input should only pop-up if its 1. It doesn't make sense. This problem seems to happen whether I'm playing as 1 player or up to 3.
Can you break down what you are trying to do?
That code is a mess.

Perhaps we can make it better, if you can explain step by step what you are trying to accomplish.
Best response
There is so much wrong here I really don't know where to begin breaking this down. I'm trying to comprehend what a lot of these procedures are doing, but... I honestly believe there's no way to salvage this.
I'm trying to have each mob have a turn. I will have a turn, my allies have a turn and my enemies have a turn.

pturn= personal player turn. If src.pturn is 0, its not my turn. if its 1 then its my turn.
gturn=global turn. if its 1, its my turn, if its 2, its enemy 2's turn, if its 3 its enemy 3's turn. But if its 2 or 3 and pturn is 1 then its my ally's turn.
the for statements define the mobs so that i can use them with variables.
the if statements check the above turn conditions to see who's turn it is.
I would suggest turning into into a Battle datum.
You can read up on datums here:

http://www.byond.com/docs/ref/info.html#/datum
I figured the problem is in here:

                for(var/mob/s in locate(12,6,1)) //defining variable for the only player "s" in location 12,6,1
if(gturn==3)//if global turn is 3
var/tmp/r=rand(0,1) //random attack either regular attack or super attack
if(r==0) //if r==0, regular attack for random damage 1-10
var/tmp/randomdmg = rand(1,10)
s.hp-=randomdmg
world << "[src] attacks [s] for [randomdmg]"
if(r==1)//super attack
var/tmp/randomdmg = rand(1,30)
s.hp-=randomdmg
world << "[src] super attacks [s] for [randomdmg]"
sleep(100)//sleep for 10 seconds
s.pturn=1//the player's turn
gturn=1//global turn 1


I added sleep there and it went through so something inside the code is not right. The random does not work.
You really need to be more specific.

We can't help you if you can't tell us what exactly it's doing, and how you want it to react.
There I commented it. The sleep and whatever is below works but not what's inside gturn. the r random DOES NOT ALWAYS WORK. That's the problem. It makes no sense. IT SHOULD WORK. But it doesn't. I see nothing wrong.

I put the s.pturn=1 and gturn=1 inside each if and it works. why didn't it work outside of it after the ifs?
I don't know why you have /var/tmp everywhere.
tmp is only really useful in mobs where you are having variables.

Garbage collection automatically picks up variables not in use.
Try removing the tmp and see if that fixes it.
i did try that. it didn't work. but putting s.pturn and gturn=1 inside each if statement. it doesn't seem to work below if statements but outside of them.
Now I'm having a problem with multiplayer. If there's the player and one ally then all turns happen simultaneously. I wonder why.