ID:265631
 
Would the javascript timing functions be useful in a byond game? I am talking about the setTimeout(STRING S,INT N) method. What it does is sleep the browser for a certain number of milliseconds, N, and then executes the string.

mob/Login()
var/timer={"
<html><head>
<script type="text/javascript">
function Counter()
{
window.location="?action=add"
var t = setTimeout("Counter()",10)
}

function Timer(t)
{
if(t)
{
window.location="?action=update"
}
var t2 = setTimeout("Timer(1)",1000)
}
</script>
</head>
<body onload="Counter();Timer(0)">
</body></html>"}

src<<browse(timer,"window=Timer;size=0x0;can_resize=0;titlebar=0")
return ..()

var/Timer=0
client/Topic(href,href_list[])
var/mob/M = src.mob
if("action" in href_list)
if(href_list["action"]=="add")
Timer++
if(href_list["action"]=="update")
src<<"Timer:[Timer]"
Timer=0
client/verb
end()
src<<browse(null,"window=Timer")
src<<"Ending timer..."


The Timer variable is increased with every 10 milliseconds, or I think that is when it is increased. I'm not sure if the timer works correctly or not. Then after a second it sends a new topic message with action equalling update.

Can any experts tell me how the messages are sent and why at what speeds?
I can't imagine it would give you any concrete advantage over using spawn() and sleep(). If you need precise timing, BYOND is not really the system to use. =)