ID:161110
 
I've tried to get this question answered before, and I'm going to try again but with a differend story behind it.

I give MOBs a trading verb, anyone close enough can click it, sellect a item from that person and offer something in return.
Because I don't want them to move at all during trading I lock them down by setting some var to be true (when moving, that var is checked and if it is true you can't move)

Now how would I beable to make sure that when someone trades, and prevents movement on both mobs untill trade is completed, this trade is canceled if one of the mobs takes to long to pick/offer/accept/decline or when one of the mobs is idle for to long?

The question is how to do this, not how this trade system should work. The trade system is just there to give you an idea of what the problem could be. (and I know it's one crappy way to implement trading in a game)

I thought I could spawn the input proc, then start a while proc which waits and only continues when either client is gone, when input is given or when a client is idle for to long.
But this just does not seem to work.

var/i = null
spawn() i = input(m,"Select","Trading") in list("Apple","Pear")
while(!i && m && m.inactivity < 600) //so as soon as we have input, or m is gone or m is idle for a minute this loop breaks, you would think ...
sleep(50)
world << "And we wait another 5 second, we have time ..."
if(m)
world << "We have a winner, [i]!"
else
world << "He strangely disappeared"


The basic thing is, if someone just disconnect when having a input window open this input proc is never returned and thus the other person can't ever move again because trade is not finished. (I sense a relog)

Anyways, that is the story, and my way of asking how to trigger input procs in a way that code will keep running if they are never returned.

Thanks in advance!
input() and alert() already sleep until something is returned.
In response to Adam753
That was not the point, the point is that it sleeps inf amount of time when nothing is inputted and it will thus never return anything.

That way people disconnecting while having a input box open prevent any code written behind the input proc being called.
This is what I'm trying to prevent...
In response to Fint
Oh.
Well, the only problem I can anticipate with your code is this bit:
if(m) //Surely this would be if(m&&m.inactivity<=600)
world<<"we have a winner, [i]!"
else
world<<"he strangely disappeared..."

If someone is inactive for 60 seconds, then the while() will stop looping, it will check for m and see that it's there, then try to look for i. but, there is no i! Disaster! The proc will be ended, and both players will be stuck and unable to move.
In response to Adam753
Again, this is not what I need help with, this trade system and the code is to illustrate the setup.
This is not a "code problem" post but a "how-to" post.
And its not a "how to make a trade system" but a "i need to keep code running after a input proc is never returned, how do I do this?" post.

Read the first post more carefully, I explaned it there in detail.
This is where the spawn() function comes in handy, it's basically like sleep() except the code beyond it gets executed before the code contained by it.
spawn(1)
var/myinput = input(src,"Some input")
sleep(20)
src << "Time's up!"


You could also attach the input() and alert() calls to a temporary object to allow you to close the boxes when time runs out.
promptbox
proc
ShowAlert(mob/M,T)
return alert(M,T)
ShowInput(mob/M,T)
return input(M,T)


mob
verb
ShowTest()
var/promptbox/P = new()
spawn(1)
var/myinput = P.ShowInput(usr,"Some input")
if(myinput)
usr << "You entered: [myinput]"
del(P)
sleep(50)
if(P) // If the box is still open
usr << "Times up, you didn't enter anything."
del(P)


By deleting P we're killing any functions being used by it, including your input() and alert() calls.