猫史档案馆


变量为什么会自动变化?

用户:帅气的导弹鲨leZl帅气的导弹鲨leZl查看:3 回复:3 评论:3 创建时间:2022-08-15T20:37:42


world.onPlayerJoin(async({entity})=>{     entity.position.copy(one.position)     entity.num = 1     main(entity)      })

 

const one = world.querySelector("#出生点-1") const two = world.querySelector("#出生点-2") const three = world.querySelector("#出生点-3")

 

one.collides = true; one.fixed = true; two.collides = true; two.fixed = true; three.fixed = true; three.collides = true;

 

world.onEntityContact(async({entity, other})=>{     if (entity.id == "出生点-2"){         entity.num = 2         other.player.directMessage("存档成功")         console.log(entity.num)     }     if (entity.id == "出生点-3"){         entity.num = 3         other.player.directMessage("存档成功")         console.log(entity.num)     }     if (entity.id == "出生点-1"){         entity.num = 1         other.player.directMessage("存档成功")         console.log(entity.num)     } })



world.onVoxelContact(({entity, voxel})=>{     const voxelName = voxels.name(voxel)     if (voxelName === "lava02"){         if (entity.num = 1){             entity.position.copy(one.position)         }         if (entity.num = 2){             entity.position.copy(two.position)         }         if (entity.num = 3){             entity.position.copy(three.position)         }     } })   为什么在玩家碰到方块“lava02”的时候,变量entity.num会自动变成"3",为什么?


回复

上一页1 页 / 共 1下一页
codewyxcodewyx

entity.num = 2;entity.num = 3× entity.num== 2;entity.num ==3√ =是赋值,==才是比较等于 可以从这里学习:www.w3school.com.cn/js/js_operators.asp

点赞0


评论


AostinAostin

看不懂啊~~~~~

点赞0


评论


芜湖咸鱼芜湖咸鱼

js的特性,自动类型转换。判断的时候 == 会自动转换,而 === 则不会。因此 "12"==12 成立 但是 "12"===12 不成立

点赞0


评论