问题描述
大家好,我正在创建一些程序,当程序加载时,它需要从数据库中加载所有项目并将游戏对象分配给它们,游戏中未保存在数据库中的临时对象 照片: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 (将#修改为@)