微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Sequelize 模型中创建临时对象?

如何解决如何在 Sequelize 模型中创建临时对象?

大家好,我正在创建一些程序,当程序加载时,它需要从数据库中加载所有项目并将游戏对象分配给它们,游戏中未保存在数据库中的临时对象 照片:https://i.imgur.com/34y7yaQ.png 我 console.log(this),那个对象和我的游戏对象在那里,但后来不是。 当我尝试 Instance.object 时,它是未定义的,他没有被分配。

我怎样才能做到这一点,或者是否有任何方法可以在模型中定义不应该保存的对象?提前谢谢你!

MODEL(我把它加为 VIRTUAL,还是什么都没有)

frp.Items = frp.Database.define('Item',{
      id: { type: DataTypes.INTEGER,autoIncrement: true,primaryKey: true },Item: { type: DataTypes.STRING },Quantity: { type: DataTypes.INTEGER,defaultValue: 1 },Entity: { type: DataTypes.INTEGER,defaultValue: -1 },Owner: { type: DataTypes.STRING,defaultValue: 0 },isWeapon: { type: DataTypes.TEXT,defaultValue: false },Ammo: { type: DataTypes.INTEGER,Last_Owner: { type: DataTypes.INTEGER,Position: {
         type: DataTypes.TEXT,defaultValue: null,get: function () { return JSON.parse(this.getDataValue('Position')); },set: function (value) { this.setDataValue('Position',JSON.stringify(value)); }
      },Rotation: {
         type: DataTypes.TEXT,get: function () { return JSON.parse(this.getDataValue('Rotation')); },set: function (value) { this.setDataValue('Rotation',Dimension: { type: DataTypes.INTEGER,GameObject: { 
         type: DataTypes.VIRTUAL,set: function (x) { 
            this.setDataValue('GameObject',x);
         },}
   },{
      timestamps: true,underscrored: true,createdAt: "Created_Date",updatedAt: "Update_Date",}
);

功能

frp.Items.prototype.Refresh = function () {
   if (this.Entity == ItemEntities.Ground) {
      const Position = this.Position;
      const Rotation = this.Rotation;
      console.log(Position);
      this.GameObject = mp.objects.new(ItemRegistry[this.Item].hash,new mp.Vector3(Position.x,Position.y,Position.z),{
         rotation: new mp.Vector3(Rotation.x,Rotation.y,Rotation.z),alpha: 255,dimension: this.Dimension
      });
      this.GameObject.Item = this.id;

      console.log('Turilo game object ' + this.GameObject.Item);
   
   } else {
      if (this.GameObject) {
         this.GameObject.destroy();
      }
   }
};

正在加载

(async () => {

   frp.Items.sync();

   const Items = await frp.Items.findAll();
   Items.forEach((Item) => {
      Item.Refresh();
   });

   setTimeout(async () => {
      const objs = await frp.Items.findAll();
      objs.forEach((obj) => { 
         console.log(obj.GameObject) // RETURN UNDEFINED
      })
   },5000);


   frp.Main.Terminal(3,Items.length + ' Items Loaded !');
})();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?