猫史档案馆


【教程】教你做一个假控制台

用户:萌新大佬萌新大佬查看:3 回复:5 评论:3 创建时间:2022-04-28T19:46:16


一天我在想,控制台只能在编辑模式下调用,那么游戏模式下如果也想使用控制台呢?于是我写了个假控制台 第一步——写出类的构造 classBox3FakeConsole{//假控制台类 constructor(consoleName,initial){//构造函数 this.name=consoleName; this.text=String(initial); } } 第二步——输出 classBox3FakeConsole{ constructor(consoleName,initial){ this.name=consoleName; this.text=String(initial); } log(...args){//可以传多个参数 for(consttofargs){ this.text+=String(t)+''; } this.text+='\n'; } } 第三步——报错 classBox3FakeConsole{ constructor(consoleName,initial){ this.name=consoleName; this.text=String(initial); } log(...args){ for(consttofargs){ this.text+=String(t)+''; } this.text+='\n'; } error(...args){ this.text+='<error\n';//因为岛三没有对话框某些显示特殊颜色的功能,所以只能用特殊符号代替 for(consttofargs){ this.text+=String(t)+''; } this.text+='\nerror>\n'; } } 第四步——完成清空 classBox3FakeConsole{ constructor(consoleName,initial){ this.name=consoleName; this.text=String(initial); } log(...args){ for(consttofargs){ this.text+=String(t)+''; } this.text+='\n'; } error(...args){ this.text+='<error\n' for(consttofargs){ this.text+=String(t)+''; } this.text+='\nerror>\n' } clear(){ this.text='';//直接设为''就好啦! } } 第五步——显示函数 classBox3FakeConsole{ constructor(consoleName,initial){ this.name=consoleName; this.text=String(initial); } log(...args){ for(consttofargs){ this.text+=String(t)+''; } this.text+='\n'; } error(...args){ this.text+='<error\n' for(consttofargs){ this.text+=String(t)+''; } this.text+='\nerror>\n' } clear(){ this.text=''; } asyncshow(entity){//因该不用解释了吧 if(!entity.isPlayer)return; while(true){ constp=awaitentity.player.dialog({ type:Box3DialogType.INPUT, title:this.name, content:this.text, }) if(!p||p==null)break; this.log('~>'+p); try{ this.log('<~'+eval(p)); }catch(e){ this.error('<~'+e); } } } } 调用方法 classBox3FakeConsole{ constructor(consoleName,initial){ this.name=consoleName; this.text=String(initial); } log(...args){ for(consttofargs){ this.text+=String(t)+''; } this.text+='\n'; } error(...args){ this.text+='<error\n' for(consttofargs){ this.text+=String(t)+''; } this.text+='\nerror>\n' } clear(){ this.text=''; } asyncshow(entity){ if(!entity.isPlayer)return; while(true){ constp=awaitentity.player.dialog({ type:Box3DialogType.INPUT, title:this.name, content:this.text, }) if(!p||p==null)break; this.log('~>'+p); try{ this.log('<~'+eval(p)); }catch(e){ this.error('<~'+e); } } } } constmyConsole=newBox3FakeCosole('萌新大佬的控制台','');     敲代码不易,大家帮忙顶一顶,多用一用a imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"  


回复

上一页1 页 / 共 1下一页
萌新大佬萌新大佬

喵 排版被吃了

点赞0


评论


萌新大佬萌新大佬

大家凑合看吧,以下是完整代码

class Box3FakeConsole{
    constructor(consoleName,initial){
        this.name=consoleName;
        this.text=String(initial);
    }
    log(...args){
        for(const t of args){
            this.text+=String(t)+' ';
        }
        this.text+='\n';
    }
    error(...args){
        this.text+='<error\n'
        for(const t of args){
            this.text+=String(t)+' ';
        }
        this.text+='\nerror>\n'
    }
    clear(){
        this.text='';
    }
    async show(entity){
        if(!entity.isPlayer)return;
        while(true){
            const p=await entity.player.dialog({
                type:Box3DialogType.INPUT,
                title:this.name,
                content:this.text,
            })
            if(!p||p==null)break;
            this.log('~> '+p);
            try{
                this.log('<~ '+eval(p));
            }catch(e){
                this.error('<~ '+e);
            }
        }
    }
}

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

所以说该怎么用呢()??

点赞0


评论


编码喵编码喵

还行吧

点赞0


评论


我是派对客我是派对客

哇!

点赞0


评论