猫史档案馆


又有代码上的问题啦!谁能回复一下

用户:PlumStevenPlumSteven查看:8 回复:4 评论:8 创建时间:2021-08-17T16:25:31


console.clear()
world.onPlayerJoin(({entity}) =>{
    entity.money = 0
    entity.job = ''
    entity.score = 0
})
const npc = world.querySelector('#NPC')
npc.enableInteract = true
npc.interactRadius = 3
npc.fixed = true

world.onInteract(async({entity}) => {
    const selection = await entity.player.dialog({
        type:Box3DialogType.SELECT,
        content:`你有${entity.score}学分,入职老师需60学分`,
        title:npc.id,
        options:['是', '否'],
    })
    if (selection){
        if (selection == '是'){
            if (entity.score >= 60){
                world.say(`${entity.name}入职老师`);
                entity.job = '老师';
            } else{
                entity.player.directMessage('你没有足够学分!!')
            }
        };
    }
})

有个问题,就是我选择“是”之后没了反应(score为0),谁能帮一下我


回复

上一页1 页 / 共 1下一页
天下第一皮卡丘天下第一皮卡丘

不能直接使用

selection

的。

点赞1


评论


PlumStevenPlumSteven

求帮助!

点赞1


评论


忠厚的乌力HYdz忠厚的乌力HYdz

出错时控制台信息发一下

点赞0


评论


七式草莓七式草莓

/*
修复者:元七七

代码存在的问题:
1.“selection == '是'”应该改成“selection.value == '是'”
2.“world.onInteract(...)”应该改成“npc.onInteract(...)”,否则所有实体的互动都会显示对话框
 */

console.clear()
world.onPlayerJoin(({entity}) =>{
    entity.money = 0
    entity.job = ''
    entity.score = 0
})
const npc = world.querySelector('#NPC')
npc.enableInteract = true
npc.interactRadius = 3
npc.fixed = true

npc.onInteract(async({entity}) => {
    const selection = await entity.player.dialog({
        type:Box3DialogType.SELECT,
        content:`你有${entity.score}学分,入职老师需60学分`,
        title:npc.id,
        options:['是', '否']
    })
    if (selection){
        if (selection.value == '是'){
            if (entity.score >= 60){
                world.say(`${entity.name}入职老师`);
                entity.job = '老师';
            } else{
                entity.player.directMessage('你没有足够学分!!')
            }
        };
    }
})

点赞1


评论