Client side NPC

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Post by densol »

NPC appers in game room via AdminTool. No errors errors in logs. But SFSEvent.USER_ENTER_ROOM do not fire on client side :(

Here the simple code for adding NPC using JS server extension:

Code: Select all

        var botRoom = getParentRoom();
   	var userCount = botRoom.getSize().getUserCount();

	botName = (Math.random() + 1).toString().substring(7);
	bot = getApi().createNPC(botName, getParentZone(), false);
	
	try {
		getApi().joinRoom(bot,botRoom);
	}
	catch (e)
       {
		trace("JoinRoom Error",e);
	}
Any more suggestions?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Post by Lapo »

If bots are created before the real User joins the Room then there will be no USER_ENTER_ROOM.
The USER_ENTER_ROOM only triggers for Users that join the Room after I have joined.

Can you please describe the sequence of events you're testing, step by step?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Post by densol »

I know that USER_ENTER_ROOM triggers if user already connected to the game room

The sequence is as follows:

User creates a game room, waiting for opponent for 10 seconds (timer starts), if no any opponent connecting then NPC automatically adding to this room (by extension request from client: new SFS2X.ExtensionRequest("addnpc", obj, sfs.lastJoinedRoom))

When another player join game the USER_ENTER_ROOM fires fine, but not for npc (in admin I see that NPC entered)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Post by Lapo »

I am not able to reproduce the problem.
I tested with our standard chat example in Javascript as client, and triggered the creation of an NPC from server side. The User appears in the Room, triggering the expected USER_ENTER_ROOM event.

Unless you have some error on client or server side I wouldn't expect this to fail. Additionally you said you can see the NPC being logged in the server and joined in the Room via the AdminTool which means that your server side code works.

As regards the client side it should work perfectly fine because NPCs are just regular User objects as real players. The only exception to this would be if you were using an MMORoom, which doesn't use the USER_ENTER_ROOM event...
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Post by Lapo »

In any case can you tell us what version of SFS2X are you using, and the version of the client API?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Post by densol »

Thanks Lapo

It is not MMORoom, USER_ENTER_ROOM works on real user join

SFS2X 2.17.0

sfs2x-api-1.7.11.js
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Post by densol »

Have tried last version of client

sfs2x-api-1.7.20.js

All the same
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Post by Lapo »

Thanks,
if you want you can send us a project that reproduces the issue, provided it's a simple example and not an entire project with tons of other dependencies.

You can send it zipped to our support@... email box with a referenct to this forum thread.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
densol
Posts: 14
Joined: 17 Feb 2023, 06:45

Re: Client side NPC

Post by densol »

Sent files to support email
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client side NPC

Post by Lapo »

Thanks, we received it. We'll get back to you
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply