猫史档案馆


神岛的神奇事件(啊其实是个求助)

用户:NysidlaNysidla查看:3 回复:3 评论:3 创建时间:2022-10-21T14:44:40


首先历遍了所有的箱子

for(const b of world.querySelectorAll('.箱子')){
    b.inbox = {'喵子弹':0,'喵子弹':0,'医疗包':0,'手雷':0}
    b.enableInteract = true
    b.interactRadius = 2
    b.interactHint = '箱子'
}

随后就开始搞交互了……

b.inbox['喵子弹'] += selection

出错了)))))))

问题在哪里呢~

+=

+=会直接成为这样:

原本0喵子弹,加上100和1喵子弹就是()

真不错)))

center_image

我一直改……

最后灵光一闪(脑袋坏了),改成了这样:

b.inbox['喵子弹'] =+ selection

改好了)))))

后来又写了玩家拿出子弹,这下子各种方法都没办法了:

...+=.../...=...+.../...=+.../...+.../...=...+=...

后面两个瞎想的。。。。。。。

所以你们怎么么看()

全部代码:

for(const b of world.querySelectorAll('.箱子')){
        b.inbox = {'喵子弹':0,'喵子弹':0,'医疗包':0,'手雷':0}
        b.enableInteract = true
        b.interactRadius = 2
        b.interactHint = '箱子'
        b.onInteract(async({entity}) => {
            while(1){
                const selection = await entity.player.dialog({
                    type:Box3DialogType.SELECT,
                    title:'箱子',
                    content:`此箱子可以存放和拿走消耗品,敌方也可以打开!\n\n喵子弹${b.inbox['喵子弹']}\n喵子弹${b.inbox['喵子弹']}\n医疗包${b.inbox['医疗包']}\n手雷${b.inbox['手雷']}`,
                    options:['放入','拿出','退出']
                })
                if(!selection || selection == null){break}
                if(selection && selection.value=='退出'){break}
                if(selection){
                    if(selection.value=='放入'){
                        while(1){
                            const selection = await entity.player.dialog({
                                type:Box3DialogType.SELECT,
                                title:'放入',
                                content:`你有:\n${entity.m1}发喵子弹\n${entity.tps}发喵子弹\n${entity.medicalkits}个医疗包\n${entity.grenade}个手雷`,
                                options:['放入喵子弹','放入喵子弹','放入医疗包','放入手雷','返回']
                            })
                            if(!selection || selection == null){break}
                            if(selection && selection.value=='返回'){break}
                            if(selection){
                                while(1){
                                    if(selection.value == '放入喵子弹'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.INPUT,
                                            title:'放入喵子弹',
                                            content:`${entity.m1}发喵子弹`
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection > entity.m1){
                                            entity.player.directMessage('子弹数量不够!')
                                        }
                                        if(!selection <= 0 && selection <= entity.m1){
                                            b.inbox['喵子弹'] += selection
                                            entity.m1 -= selection
                                            entity.player.directMessage('放入成功!')
                                            break
                                        }
                                    }
                                    if(selection.value == '放入喵子弹'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.INPUT,
                                            title:'放入喵子弹',
                                            content:`${entity.tps}发喵子弹`,
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection > entity.tps){
                                            entity.player.directMessage('子弹数量不够!')
                                        }
                                        if(!selection <= 0 && selection <= entity.tps){
                                            b.inbox['喵子弹'] =+ selection
                                            entity.tps -= selection
                                            entity.player.directMessage('放入成功!')
                                            break
                                        }
                                    }
                                    if(selection.value == '放入医疗包'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.INPUT,
                                            title:'放入医疗包',
                                            content:`${entity.medicalkits}个医疗包`,
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection > entity.medicalkits){
                                            entity.player.directMessage('医疗包数量不够!')
                                        }
                                        if(!selection <= 0 && selection <= entity.medicalkits){
                                            b.inbox['医疗包'] =+ selection
                                            entity.medicalkits -= selection
                                            entity.player.directMessage('放入成功!')
                                            break
                                        }
                                    }
                                    if(selection.value == '放入手雷'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.INPUT,
                                            title:'放入手雷',
                                            content:`${entity.grenade}个手雷`,
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection > entity.grenade){
                                            entity.player.directMessage('手雷数量不够!')
                                        }
                                        if(!selection <= 0 && selection <= entity.grenade){
                                            b.inbox['手雷'] =+ selection
                                            entity.grenade -= selection
                                            entity.player.directMessage('放入成功!')
                                            break
                                        }
                                    }
                                    if(!selection || selection == null){break}
                                }
                            }
                        }
                    }
                    if(selection.value=='拿出'){
                        while(1){
                            const selection = await entity.player.dialog({
                                type:Box3DialogType.SELECT,
                                title:'拿出',
                                content:`喵子弹${b.inbox['喵子弹']}\n喵子弹${b.inbox['喵子弹']}\n医疗包${b.inbox['医疗包']}\n手雷${b.inbox['手雷']}`,
                                options:['拿出喵子弹','拿出喵子弹','拿出医疗包','拿出手雷','返回']
                            })
                            if(!selection || selection == null){break}
                            if(selection && selection.value=='返回'){break}
                            if(selection){
                                while(1){
                                    if(selection.value == '拿出喵子弹'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.SELECT,
                                            title:'拿出喵子弹',
                                            content:`有${b.inbox['喵子弹']}发喵子弹`,
                                            options:['拿出全部','拿出一些','返回']
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection && selection.value=='返回'){break}
                                        if(selection){
                                            if(selection.value == '拿出全部'){
                                                entity.m1 = entity.m1 += b.inbox['喵子弹']
                                                b.inbox['喵子弹'] = 0
                                                entity.player.directMessage('成功拿出!')
                                            }
                                            else if(selection.value == '拿出一些'){
                                                const selection = await entity.player.dialog({
                                                    type:Box3DialogType.INPUT,
                                                    title:'拿出一些',
                                                    content:`拿出多少?`
                                                })
                                                if(!selection || selection == null){break}
                                                if(selection > b.inbox['喵子弹']){
                                                    entity.player.directMessage('箱子里没有这么多!')
                                                }
                                                if(selection <= b.inbox['喵子弹'] && !selection <= 0){
                                                    entity.m1 = entity.m1 += selection
                                                    b.inbox['喵子弹'] -= selection
                                                    entity.player.directMessage('成功拿出!')
                                                }
                                            }
                                        }
                                    }
                                    if(selection.value == '拿出喵子弹'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.SELECT,
                                            title:'拿出喵子弹',
                                            content:`有${b.inbox['喵子弹']}发喵子弹`,
                                            options:['拿出全部','拿出一些','返回']
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection && selection.value=='返回'){break}
                                        if(selection){
                                            if(selection.value == '拿出全部'){
                                                entity.tps += b.inbox['喵子弹']
                                                b.inbox['喵子弹'] = 0
                                                entity.player.directMessage('成功拿出!')
                                            }
                                            else if(selection.value == '拿出一些'){
                                                const selection = await entity.player.dialog({
                                                    type:Box3DialogType.INPUT,
                                                    title:'拿出一些',
                                                    content:`拿出多少?`
                                                })
                                                if(!selection || selection == null){break}
                                                if(selection > b.inbox['喵子弹']){
                                                    entity.player.directMessage('箱子里没有这么多!')
                                                }
                                                if(selection <= b.inbox['喵子弹'] && !selection <= 0){
                                                    entity.tps += selection
                                                    b.inbox['喵子弹'] -= selection
                                                    entity.player.directMessage('成功拿出!')
                                                }
                                            }
                                        }
                                    }
                                    if(selection.value == '拿出医疗包'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.SELECT,
                                            title:'拿出医疗包',
                                            content:`有${b.inbox['医疗包']}个医疗包`,
                                            options:['拿出全部','拿出一些','返回']
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection && selection.value=='返回'){break}
                                        if(selection){
                                            if(selection.value == '拿出全部'){
                                                entity.medicalkits += b.inbox['医疗包']
                                                b.inbox['医疗包'] = 0
                                                entity.player.directMessage('成功拿出!')
                                            }
                                            else if(selection.value == '拿出一些'){
                                                const selection = await entity.player.dialog({
                                                    type:Box3DialogType.INPUT,
                                                    title:'拿出一些',
                                                    content:`拿出多少?`
                                                })
                                                if(!selection || selection == null){break}
                                                if(selection > b.inbox['医疗包']){
                                                    entity.player.directMessage('箱子里没有这么多!')
                                                }
                                                if(selection <= b.inbox['医疗包'] && !selection <= 0){
                                                    entity.medicalkits += selection
                                                    b.inbox['医疗包'] -= selection
                                                    entity.player.directMessage('成功拿出!')
                                                }
                                            }
                                        }
                                    }
                                    if(selection.value == '拿出手雷'){
                                        const selection = await entity.player.dialog({
                                            type:Box3DialogType.SELECT,
                                            title:'拿出手雷',
                                            content:`有${b.inbox['手雷']}个手雷`,
                                            options:['拿出全部','拿出一些','返回']
                                        })
                                        if(!selection || selection == null){break}
                                        if(selection && selection.value=='返回'){break}
                                        if(selection){
                                            if(selection.value == '拿出全部'){
                                                entity.grenade += b.inbox['手雷']
                                                b.inbox['手雷'] = 0
                                                entity.player.directMessage('成功拿出!')
                                            }
                                            else if(selection.value == '拿出一些'){
                                                const selection = await entity.player.dialog({
                                                    type:Box3DialogType.INPUT,
                                                    title:'拿出一些',
                                                    content:`拿出多少?`
                                                })
                                                if(!selection || selection == null){break}
                                                if(selection > b.inbox['手雷']){
                                                    entity.player.directMessage('箱子里没有这么多!')
                                                }
                                                if(selection <= b.inbox['手雷'] && !selection <= 0){
                                                    entity.grenade += selection
                                                    b.inbox['手雷'] -= selection
                                                    entity.player.directMessage('成功拿出!')
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        })
    }

顺便看看别的错误()()()()()

问代码为什么这么**,一是懒(bushi,二是不会(aduiduidui


回复

上一页1 页 / 共 1下一页
NysidlaNysidla

喵:喵//子//弹

点赞0


评论


NysidlaNysidla

啊不对,后面一个瞎想的()

点赞0


评论


呵呵0486呵呵0486

加的不是数字是字符串(要把字符串搞成数字()

+= selection * 1

大概就是这样(

点赞0


评论