猫史档案馆


萌新大佬

萌新大佬

Lv.1

一个普通的编程小白

获赞:784收藏:262浏览:65251作品收藏:773

签名:阿巴阿巴阿巴 这年头谁在社区混() 快来你岛

回复帖子评论
上一页8 页 / 共 19下一页

代码岛3.0,再见! 中回复

吓死,还以为出岛四了

2022-05-20T13:43:49 点赞:0

【求助】双斜杠 中回复

还有一个补充一下

~> const a=/a/;a
<~ /a/

这是什么牛马啊啊啊对象不是因该返回[Object object]吗????

2022-05-20T15:34:10 点赞:0

【求助】双斜杠 中回复

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa×∞

2022-05-20T15:35:54 点赞:0

一个小问题 中回复

喵喵d

2022-05-23T13:27:05 点赞:0

【实用教程】如何在帖子里打出特效字?让你的帖子档次上增! 中回复

收藏

2022-05-23T13:41:16 点赞:0

【地图招聘】马云编程猫招人一起做图了,有兴趣的快来看看吧!!! 中回复

萌新大佬_两年半_代码师_https://box3.codemao.cn/u/mxdlorzorz地下城通过了,俩超1k,带一个呗

2022-05-27T09:18:32 点赞:0

神岛实名认证的bug! (吉吉喵勿进!) 中回复

姓名:实名认证监管员

身份证号:000000000000000001

校验通过

2022-05-27T13:36:32 点赞:0

奇怪的API又增加了 中回复

dddddd

2022-05-30T10:11:30 点赞:0

【水】岛三的案子-1 中回复

目前喵者已康复

2022-05-31T11:27:26 点赞:1

【水】岛三的案子-2 中回复

 

2022-06-01T16:04:46 点赞:0

【水】岛三的案子-2 中回复

  ————————————————————————密封线———————————————————————— 上一期(https://shequ.cod喵/community/463184)的答案是: 我,跟尹子聊天的时候起了冲突,我开了他的enableDamage并让他hurt了100,并抢走了他的头套。尹子死后不甘心,于是假装红色方块流了一地。 那么这一期也同样是一个很水的案子,大家不妨来看看 尹子竟然消失了! 可以看见,聊天框里有尹子,但是我们却看不见他!        嫌疑人1:SKQA路卡_把名玩没了 口供:我只不过在挂机而已,而且编程猫皮肤我也有,干啥惦记着尹子啊?    嫌疑人2:萌新大佬 口供:尹子变消失了,对我也没好处啊,而且我像是会干那种事的人吗?我当时就是在和尹子讨论代码,切了一下屏,尹子就消失了!    嫌疑人3:Kindheit 口供:我就是个大建筑屑啊!我连代码都不会,甚至都没有控制台权限,怎么可能干这种事!    大家来猜一猜谁是罪魁祸首吧!有能力者可以尝试一下复原作案代码

2022-06-01T16:07:51 点赞:0

【水】岛三的案子-2 中回复

center_image

 

2022-06-01T16:08:46 点赞:0

【box3】遇到吉吉了!happy! 中回复

啥时候啊,我咋不在

2022-06-02T09:05:09 点赞:0

【教程】背包教程(自带SQL) 中回复

吃排版大师是吧,三个贴的排版都吃了

2022-06-02T11:55:42 点赞:0

【教程】背包教程(自带SQL) 中回复

constInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 constrows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 constnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 constructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(constiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要喵回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(constiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 constp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', options:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } } 代码👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆

2022-06-02T11:56:03 点赞:0

【教程】背包教程(自带SQL) 中回复

constInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 constrows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 constnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 constructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(constiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要喵回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(constiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 constp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', options:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } }

2022-06-02T11:56:41 点赞:0

【教程】背包教程(自带SQL) 中回复

constInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 constrows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 constnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 constructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(constiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要喵回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(constiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 constp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', options:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } }

2022-06-02T11:58:09 点赞:0

【教程】背包教程(自带SQL) 中回复

constInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 constrows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 constnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 constructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(constiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要喵回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(constiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 constp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', options:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } }

2022-06-02T11:59:17 点赞:0

【教程】背包教程(自带SQL) 中回复

c喵tInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 c喵trows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 c喵tnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 c喵tructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(c喵tiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要加 returnthis.thing[item];//返回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(c喵tiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 c喵tp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', opti喵:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } }

2022-06-02T12:00:42 点赞:0

【教程】背包教程(自带SQL) 中回复

我就不信有人能在这里成功排版!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2022-06-02T13:46:35 点赞:0

【教程】背包教程(自带SQL) 中回复

编程猫吞排版功能 orz orz orz orz orz orz

2022-06-02T16:37:30 点赞:0

【教程】背包教程(自带SQL) 中回复

constInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 constrows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 constnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 constructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(constiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要加 returnthis.thing[item];//返回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(constiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 constp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', options:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } }

2022-06-03T09:50:20 点赞:0

【教程】背包教程(自带SQL) 中回复

constInitCap=10;//这里写背包的初始容量 db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL,--这里存userKey recordTEXTNOTNULL--这里存背包 )`//建立sql world.onPlayerJoin(async({entity})=>{//当玩家进入地图 functioninit(){//建立初始背包 entity.bag=newBag(entity,{/*如果有初始物品在这里写*/},InitCap);//初始背包的构造 } if(entity.player.userKey){//如果玩家非游客 constrows=awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`;//获取玩家数据的那一行 if(rows&&!rows.length){//如果这一行不存在 init();//那么建立初始背包 db.sql`INSERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;//将初始背包插入sql }else{//如果玩家有数据 constnow=JSON.parse(rows[0].record);//将读取到的数据临时存放在now entity.bag=newBag(entity,now.thing,now.capacity);//将now拆分开并建立玩家的背包 } }elseinit();//游客玩家直接建立新背包 }) world.onPlayerLeave(({entity})=>{ entity.bag.save();//玩家离开时保存 }) classBag{//创建背包类 constructor(owner=newBox3Entity,thing={},capacity=0){//构造函数 this.owner=owner; this.thing=thing; this.capacity=capacity; this.now=0; for(constiofObject.keys(this.thing)){ this.now+=this.thing[i]; }//now是物品数量 this.saveObject={ thing:this.thing, capacity:this.capacity }//sql存档的时候存这个 } save(){//保存 if(!this.owner.player.userKey)return;//如果游客账号就不保存 db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;//保存 } add(item='',num=1){//添加物品,默认添加一个 if(this.now+num>this.capacity)returnundefined;//如果数量数量超过了就返回undefined if(!!this.thing[item]){//如果此物品存过 this.thing[item]+=num;//增加num this.saveObject.thing[item]+=num;//保存对象也要同步 }else{//如果没存过 this.thing[item]=num;//直接赋值 this.saveObject.thing[item]=num;//直接赋值 } this.now+=num;//物品的数量也要加 returnthis.thing[item];//返回物品数量 } del(item='',num=1){//删除物品,默认减少一个 if(!this.thing[item])returnNaN;//如果此物品不存在直接返回NaN(NotaNumber) if(this.thing[item]<num)returnundefined;//如果不够减就返回undefuned this.thing[item]-=num;//减去相应的量 this.saveObject.thing[item]-=num;//同步保存对象 this.now-=num;//当前物品数也要减 returnthis.thing[item];//返回数量 } setCap(cap=0){//设置容量 if(cap<this.now)returnundefined;//如果背包里的物品比目标容量多则返回undefiend this.capacity=cap;//直接设置容量 returnthis.capacity;//返回值 } asyncshow(){//对玩家展示背包 varop=[]; for(constiofObject.keys(this.thing)){ op.push(`${i}×${this.thing[i]}`); }//将物品×数量放进选项列表 constp=awaitthis.owner.player.dialog({//建立对话框 type:Box3DialogType.SELECT, title:'背包',//具体细节如标题,内容等自己改 content:'以下是你的背包', options:op, }); returnthis.thing[Object.keys(this.thing)[op.indexOf(p)]];//返回选择了的物品 } }

2022-06-03T09:51:17 点赞:0

求代码!!!!! 中回复

awaitsleep不就好了()()评论区都是屑()()()我也是屑()()

2022-06-03T13:31:35 点赞:0

用代码也能制作音乐!代码师转行音效师?音乐编辑器不会用,数字简谱就能搞定! 中回复

请教一下,黑键因咋弄(欸我就是故意挑毛病的)

2022-06-03T15:59:13 点赞:1

Box3 鼠标指针位置 中回复

岛三没必要检测这个吧(而且也没有

2022-06-03T16:58:41 点赞:0

大家猜猜如何做到的 中回复

内个叫什么什么,对就是那个

2022-06-04T10:26:20 点赞:0

如图,请问这是什么编程语言? 中回复

我:这不c++嘛,喵哪里来的C语法,喵这if后面不接括号是啥,作者你写错了吧,喵这来了个冒号加pass这是把python拉进来了??不是吧我丢,这html里面注释了js????哦我想通了,你在整活

2022-06-06T07:53:41 点赞:1

[Box3]控制台必备代码(氵了但没有完全氵的氵贴) 中回复

众所周知,world某些变量只读,所以world不能改的

2022-06-06T07:58:34 点赞:0

这已经是代码岛的极限了 中回复

众所周知,有个东西叫flySpeed

2022-06-06T09:47:39 点赞:0