猫史档案馆


【帮忙】please!求助!

用户:xie_sansxie_sans查看:2 回复:6 评论:2 创建时间:2021-02-09T16:36:16


着哪里错了?请大佬们帮忙改一下

function test(entity,level){
    const a=Math.random(100)
    const b=Math.random(100)//What're you doing?
    if(level==1){
        for(var i=1;i<=5;i++){
            const sele= await entity.player.dialog({
            type:Box3DialogType.SELECT,
            content:a+'+'+b+'=?',
            title:'考试!',
            options:[a+b,a-b,Math.random(100)]
        })
        if(sele==0){
            text(entity,'下一题!','~答对喽~')
        }else{
            text(entity,'Oops!答错喽~智商-1')
            entity.iq-=1
            break
        }
        }
        
    }
}


回复

上一页1 页 / 共 1下一页
霸道的疾风雀3KNp霸道的疾风雀3KNp

//不知道

点赞0


评论


SKQASKQA

1.await只适用于异步函数

2.此函数的参数为entity和level,根据函数内容,level应为数值类型的,在调用的时候应当使用数值类型的数据

点赞0


评论


async_functionasync_function

Math.random(100)
/*改为*/
Math.random()*100
/*如果原意是 获取随机100个0~1小数的和 的话,就改成这样*/

点赞0


评论


async_functionasync_function

//还有函数用到了await,要将function改为async function

点赞0


评论


async_functionasync_function

//还有,在循环体
for(var i=1;i<=5;i++){
    const sele= await entity.player.dialog({
    type:Box3DialogType.SELECT,
    content:a+'+'+b+'=?',
    title:'考试!',
    options:[a+b,a-b,Math.random(100)]
})
/*中,sele为代表await entity.player.dialog常量,要调用的话要改为index(详情见下面的代码)*/
if(sele==0){
    text(entity,'下一题!','~答对喽~')
}
//改为
if(sele.index==0){
    text(entity,'下一题!','~答对喽~')
}

/*还有,答对和答错都函数回调,不就喵循环了?*/
/*and如果sele的值为null怎么办?*/

点赞0


评论


SKQASKQA

async function text(entity,level){
//1.await只适用于异步函数,应改成异步函数 2.函数名于下方的“text”不一致
    c喵t a=Math.floor(Math.random()*100)
    c喵t b=Math.floor(Math.random()*100)
//random函数不需要参数,向下取整(0到1随机×100)即为从1~100随机整数
    if(level==1){
        for(var i=1;i<=5;i++){
            c喵t sele= await entity.player.dialog({
                type:Box3DialogType.SELECT,
                content:a+'+'+b+'=?',
                title:'考试!',
                opti喵:[a+b,a-b,Math.floor(Math.random()*100)]
//同上
            })
            if(!sele.index){return}
//应增补:如果玩家点了屏幕的其他区域则返回
            if(sele.index==0){
//sele变量为玩家出现的对话框,使用index可以判断玩家点击的选项值
                text(entity,1)
//参数不对应
            }else{
                text(entity,1)
//同上
                entity.iq-=1
                break
            }
        }
        
    }
}

点赞0


评论