Page 1 of 1

problem with setTimeout

Posted: 06 Sep 2020, 14:18
by Tomas3956
I'm programming a JavaScript app

in the app there is a button when the user clicks on it, a door supposed to be opened for 7 seconds then close again
(the default is close state)

that's my code :

Code: Select all

if (cmd == "clickOnButton") {
  var rVars = []
  rVars.push({
    name: "door",
    val: 1
  }) // 1 for opening , 0 for closing

  _server.setRoomVariables(r, user, rVars)

  function closethedoor() {

    var rVars = []
    rVars.push({
      name: "door",
      val: 0
    })
    _server.setRoomVariables(r, user, rVars)
  }
  setTimeout(closethedoor, 7000);
}


the door open successfully but it doesn't close after 7 seconds , that's the problem I found:

Can't find method java.util.Timer.schedule(adapter1,org.mozilla.javascript.Undefined).



also clearTimeOut doesn't work .

Re: problem with setTimeout

Posted: 07 Sep 2020, 08:00
by Lapo
Hi,
in SFS PRO on the server side there is no setTimeout command. Maybe this is some custom function?

Instead you should use setInterval, as shown in the docs here:
https://www.smartfoxserver.com/docs/1x/ ... terval.htm

Cheers