• Help
  • Title screen player.save() does not save data to the MongoDB

Have you deployed the newest version? I see only rc.3 version which is the previous one

Normally 4.0.0-rc.4 is released

Hmm, I see on github this rc.4 tag, but here: https://www.npmjs.com/search?q=rpgjs it is not available, might be npm issue.
I can't either install this version because npm could not find it.

npm update                   13:43:08
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @rpgjs/types@^4.0.0-rc.4.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

    dominx99 strange, because some packages are well up to date. I've republished @rpgjs/types

      Samarium

      I successfully updated dependencies,
      but unfortunately, issue persists.
      I prepared a branch if you want to reproduce: title-screen-integration

      I save data on level-up (to gain level just kill 2 mobs with C button):

          onLevelUp(player: RpgPlayer, leveledUpBy: number) {
              player.showAnimation('level-up', 'default');
      
              player.allRecovery();
      
              player.save();
          },

      Then I refresh the page, login in and I am getting the same error: An error has occurred without any error in console :/


      I have this dynamic database for items with custom properties:

      import { v4 } from 'uuid';
      import Shield from './../../../item/Shield';
      import { RpgPlayer } from '@rpgjs/server';
      
      export default function CircleShield() {
          @Shield({
              id: v4(),
              name: 'Shield',
              graphic: 'shield',
              price: 100,
              pdef: Math.round(Math.random() * 5) + 3,
          })
          class CircleShield {
          }
      
          return CircleShield;
      }

      and also I added custom properties for player:

      declare module '@rpgjs/server' {
          export interface RpgPlayer {
              inventoryGui?: Gui;
              isInventoryOpened: boolean;
      
              profileGui?: Gui;
              profileGuiOpened: boolean;
      
              inventory?: Backpacks,
          }
      }
        17 days later

        dominx99

        I have no problem even testing your game. It saves well.

        What version of mongodb do you have?

          Samarium

          It's docker image of mongo:6-jammy
          it's inside my docker-compose.yml

          But where did you put player.save()?
          like this?

              onLevelUp(player: RpgPlayer, leveledUpBy: number) {
                  player.save();
          
                  player.showAnimation('level-up', 'default');
          
                  player.allRecovery();
              },

          Hmm, I can understand that. Animations don't use synchronization but just make a call to the client (socket.emit). And so the call to the client is faster than synchronization, so the animation takes place before the event appears on the client side (and is therefore not displayed).

          You could say it's a bug, yes.

          But I think it's easily solved:

          // create event 
          // [...]
          server.send() // force synchronization with you can also use player.server to access the server
          // event.showAnimation(...)