How to send a bot to another room?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

moonlife
Posts: 30
Joined: 26 Sep 2016, 08:22

How to send a bot to another room?

Postby moonlife » 18 Jun 2021, 19:10

Hi,

I've created a simple bot system for my game. I trigger the bot manually by Javascript at start, creating a new Smartfox API connection for it, and joining it to a room. After that, the bot is being handled by Java extension at the background.
After 30 seconds, the SFS connection of the bot times out and bot disconnects from SmartFox Server automatically. From now on, we don't have a User object for that bot on the SFS.
In the ROOM_VARIABLES_UPDATE event in Java extension, everytime when it's bot's turn, the event makes a move by bot's behalf, so bot keeps playing.

Everything works as expected until here. Now here is my problem:

Now, I want to send the bot to another room. But I can't grab it by a User object in order to use sfsApi.joinRoom() function, because it has no SFS connection now. So what can I do to join that bot to another room? Shall I create an SFS API connection and create a User object for it in the ROOM_VARIABLES_UPDATE in Java extension? If so, I can't imagine a way to that.

Thanks for any ideas.
User avatar
Lapo
Site Admin
Posts: 22068
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to send a bot to another room?

Postby Lapo » 19 Jun 2021, 09:50

Hi,
if the client side connection is dropped the User will be removed, so you won't be able to join that User anywhere as it doesn't exist in the server anymore.

You could either keep the connection alive from client side by sending a small "ping" message at fixed intervals (e.g. 60 seconds) or instead use server side NPCs which don't require a physical client connection.

We have a series of articles that explore all the details on how to implement NPCs in SmartFoxServer, see here:
https://smartfoxserver.com/blog/ways-of ... -game-p-1/
https://smartfoxserver.com/blog/ways-of ... -game-p-2/

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 35 guests