problem with setTimeout

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Tomas3956
Posts: 1
Joined: 06 Sep 2020, 14:15

problem with setTimeout

Postby Tomas3956 » 06 Sep 2020, 14:18

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 .
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: problem with setTimeout

Postby Lapo » 07 Sep 2020, 08:00

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
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 33 guests