lab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ key = "t1", com = "text", x = 10, y = 10, width = 20, height = 12, text_size = 12, text_color = 0xff000000 },
{ key = "b1", com = "button", x = 200, y = 10, width = 50, height = 12, on_click = on_click_button, on_mouse_enter = on_mouse_enter, on_mouse_leavel = on_mouse_leave },

ui.get_text(key)
ui.get_button(key)
ui.get(key)
doc.get(key)
doc.get(key).update("hello")
doc.get(key).increase("click-count", 1)
doc.get(key).register_on_button_clicked(function()
sync.send("request-upload")
end)

sync.register("request-upload", function()
http.send_post("server.save-user-data", {
id = player.get_local_id()
})
end)

http.on_receive('post', 'server.save-user-data', function(request)
db.open()
local tb = db.open_table('user-data')
tb.write('pid = %g', request.data.pid, function(data)
return {
id = request.data.pid,
level = request.data.level,
point = request.data.point,
}
end)
db.close()
end)

http.on_receive('post', 'server.load-user-data', function(request)
db.open()
local tb = db.open_table('user-data')
local data = tb.read('pid = %g', request.data.pid)
db.close()
return http.response({
message = "load-user-data",
data = {
id = data.id,
level = data.level,
point = data.point,
}
})
end)