diff --git a/packages/@dcl/sdk-commands/src/logic/bundle.ts b/packages/@dcl/sdk-commands/src/logic/bundle.ts index 01654551f..c1a5bfc5b 100644 --- a/packages/@dcl/sdk-commands/src/logic/bundle.ts +++ b/packages/@dcl/sdk-commands/src/logic/bundle.ts @@ -85,11 +85,16 @@ for (const path in compositeFromLoader) { if ((entrypoint as any).main !== undefined) { function _INTERNAL_startup_system() { - const maybePromise = (entrypoint as any).main() - if (maybePromise && typeof maybePromise === 'object' && typeof (maybePromise as unknown as Promise).then === 'function') { - maybePromise.catch(console.error) + try { + const maybePromise = (entrypoint as any).main() + if (maybePromise && typeof maybePromise === 'object' && typeof (maybePromise as unknown as Promise).then === 'function') { + maybePromise.catch(console.error) + } + } catch (e) { + console.error(e) + } finally { + engine.removeSystem(_INTERNAL_startup_system) } - engine.removeSystem(_INTERNAL_startup_system) } engine.addSystem(_INTERNAL_startup_system, Infinity) } diff --git a/packages/@dcl/sdk/src/network/entities.ts b/packages/@dcl/sdk/src/network/entities.ts index 61df9bb5a..64183ee39 100644 --- a/packages/@dcl/sdk/src/network/entities.ts +++ b/packages/@dcl/sdk/src/network/entities.ts @@ -43,7 +43,7 @@ export function entityUtils(engine: IEngine, profile: IProfile) { let componentsIdsMutable = [...componentIds] // Profile not initialized if (!profile?.networkId) { - throw new Error('Profile not initialized. Called syncEntity inside the main() function.') + throw new Error('Profile not initialized. Call syncEntity inside the main() function.') } // We use the networkId generated by the user address to identify this entity through the network diff --git a/packages/@dcl/sdk/src/players/index.ts b/packages/@dcl/sdk/src/players/index.ts index 149e3a23b..a6956c203 100644 --- a/packages/@dcl/sdk/src/players/index.ts +++ b/packages/@dcl/sdk/src/players/index.ts @@ -29,8 +29,8 @@ function definePlayerHelper(engine: IEngine) { const AvatarBase = defineAvatarBase(engine) const playerEntities = new Map() - let onEnterSceneCb: ((player: GetPlayerDataRes) => void) | undefined = undefined - let onLeaveSceneCb: ((userId: string) => void) | undefined = undefined + const onEnterSceneCb: ((player: GetPlayerDataRes) => void)[] = [] + const onLeaveSceneCb: ((userId: string) => void)[] = [] engine.addSystem(() => { const players = Array.from(engine.getEntitiesWith(PlayerIdentityData, AvatarBase)) @@ -41,14 +41,14 @@ function definePlayerHelper(engine: IEngine) { playerEntities.set(entity, identity.address) // Call onEnter callback - if (onEnterSceneCb) { - onEnterSceneCb(getPlayer({ userId: identity.address })!) + if (onEnterSceneCb.length) { + onEnterSceneCb.forEach(($) => $(getPlayer({ userId: identity.address })!)) } // Check for changes/remove callbacks AvatarBase.onChange(entity, (value) => { - if (!value && onLeaveSceneCb && playerEntities.get(entity)) { - onLeaveSceneCb(playerEntities.get(entity)!) + if (!value && onLeaveSceneCb.length && playerEntities.get(entity)) { + onLeaveSceneCb.forEach(($) => $(playerEntities.get(entity)!)) playerEntities.delete(entity) } }) @@ -58,10 +58,10 @@ function definePlayerHelper(engine: IEngine) { return { onEnterScene(cb: (player: GetPlayerDataRes) => void) { - onEnterSceneCb = cb + onEnterSceneCb.push(cb) }, onLeaveScene(cb: (userId: string) => void) { - onLeaveSceneCb = cb + onLeaveSceneCb.push(cb) }, /** * Returns the info of the player if it's in the scene.