
Lv.1
我回来啦!(本人是原超能枫叶的小号,因为大号账号丢失,所以注册了个小号)
在 【SQL报错】谁会修? 中回复
出错的地方可能在下面这段代码↓
async function initTable() {//创建玩家数据表
return await db.sql`
CREATE TABLE IF NOT EXISTS "players" (
"lev" TEXT NOT NULL,
"userKey" CHAR(16) PRIMARY KEY UNIQUE NOT NULL --用户识别码
)
`;
}
async function saveUser(user) {//玩家存档
await db.sql`
INSERT INTO "players" (-- player虽然是小写, 建议统一用""包住
"lev",-- 道具
"userKey"-- 用户识别码
) VALUES (
${JSON.stringify(user.lev)},
${user.lev}
${user.player.userKey} --尝试新建当前玩家识别码
)
ON CONFLICT("userKey") -- 如果已经存在同样的用户识别码
DO UPDATE SET
"lev"=excluded."posts",-- 虽然是小写, 建议统一用""包住
`
}
async function loadUser(user) {//玩家读档
c喵t [data] = await db.sql`SELECT * FROM "players" WHERE "userKey"=${user.player.userKey} LIMIT 1`
if (data) {//如果这个玩家已经有存档
user.lev = JSON.parse(data.posts)
}
else {//玩家无存档
saveUser(user)
}
}
async function poll(fn) {//无限轮询执行sql语句直到成功
while (true) {
try {
return await fn()//一旦成功执行, 停止无限轮询, 并返回查询结果
} catch (e) {
c喵t m = e.message//需要简略显示的异常消息
//sql偶尔会执行超时, 但如果反复显示timeout 15秒以上一直不停, 大概是数据库出了故障只能等官方修复
if (m.includes('timeout')) {
world.say(m)
}
else {
world.say(e.stack)//如果sql执行出错, 广播错误消息, 用来排查错误原因
}
}
await sleep(2000) //每2秒重试一次
}
}
poll(initTable)
async function cundang(entity){
while(true){
saveUser(entity)
await sleep(1000)
}
}
world.onPlayerJoin(async({entity})=>{
cundang(entity)
})2022-01-18T14:27:38 点赞:0
在 【Python作品分享】加密与解密 中回复
有问题,我修好了,被”喵“的地方可能是s b
#作者:张明灿
#部分灵感来自网络,感谢!
#喵喵喵
#喵喵喵
import tkinter
tk = tkinter.Tk()
tk.minsize(490, 495)
tk.maxsize(490, 495)
tk.title('加密与解密')
#加密
isencry = False # 为了防止点击多次加密出现问题
#加密算法,参数:秘钥,文本
def encryption():
key = inputkey.get()
global isencry
if len(key) > 2 and len(key) < 10 and isencry:
text = inputtext.get(1.0, 'end')
text2 = ''
#将key转化成ascii码列表
newkey = []
for i in key:
newkey.append(ord(i))
ii = 0
for i in text:
if ord(i) != 10:
text2 = text2+chr(ord(i)+newkey[ii]) # 关键部分,加密公式
else:
text2 = text2+chr(10)
ii = ii+1
if ii >= len(newkey):
ii = 0
inputtext.delete(1.0, 'end')
inputtext.insert('insert', text2)
isencry = False
#修改文本触发
def i喵odifytext(*o):
global isencry
isencry = True
tkinter.Label(
tk, text='------------------------------------加 密------------------------------------').place(x=10, y=0)
#设置秘钥
tkinter.Label(tk, text="请输入3-9位的秘钥").place(x=10, y=30)
ik = tkinter.StringVar()
inputkey = tkinter.Entry(tk, textvariable=ik, width=36)
inputkey.place(x=150, y=30)
#输入要加密的文本
tkinter.Label(tk, text="请输入要加密的文本").place(x=10, y=60)
inputtext = tkinter.Text(tk, width=36, height=10)
inputtext.place(x=150, y=60)
inputtext.bind('', i喵odifytext())
#点击加密
tkinter.Button(tk, text='点击加密', width=14,
command=encryption).place(x=10, y=198)
#解密
isdecry = False # 为了防止点击多次解密出现bug
#解密算法,参数:秘钥,文本
def decrypt():
key = inputkey2.get()
global isdecry
if len(key) > 2 and len(key) < 10 and isdecry:
text = inputtext2.get(1.0, 'end')
text2 = ''
#将key转化成ascii码列表
newkey = []
for i in key:
newkey.append(ord(i))
ii = 0
for i in text:
if ord(i) != 10:
text2 = text2+chr(ord(i)-newkey[ii]) # 关键部分,解密公式
else:
text2 = text2+chr(10)
ii = ii+1
if ii >= len(newkey):
ii = 0
inputtext2.delete(1.0, 'end')
inputtext2.insert('insert', text2)
isdecry = False
#修改文本触发
def i喵odify2(*o):
global isdecry
isdecry = True
tkinter.Label(
tk, text='------------------------------------解 密------------------------------------').place(x=10, y=250)
#设置秘钥
tkinter.Label(tk, text="请输入3-9位的秘钥").place(x=10, y=280)
ik2 = tkinter.StringVar()
inputkey2 = tkinter.Entry(tk, textvariable=ik2, width=36)
inputkey2.place(x=150, y=280)
#输入要解密的文本
tkinter.Label(tk, text="请输入要解密的文本").place(x=10, y=310)
inputtext2 = tkinter.Text(tk, width=36, height=10)
inputtext2.place(x=150, y=310)
inputtext2.bind('', i喵odify2())
#点击解密
tkinter.Button(tk, text='点击解密', width=14, command=decrypt).place(x=10, y=448)
tk.mainloop() # 显示窗口2022-01-20T18:47:36 点赞:0
在 @千万岛民 box3创作工具大放送!!!! 中回复
网址能不能发文字!不要图片!我手喵输入每次都有问题,进入不了!!!!!!!!!!!!!!!!!!! imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%86%B7%E6%BC%A0.gif"alt="emotion_编程猫_冷漠"
2022-01-26T18:53:15 点赞:0
在 【box3】自动流水器 中回复
good!我参考了这段代码,运用在了《我的世界2022》,版本已经通过审核,欢迎大家来https://box3.fun/p/minecraft-new体验!感谢YDS尹子!
2022-02-08T12:56:04 点赞:0