Problem when make a database for equipment

Post Reply
doubleruri
Posts: 2
Joined: Wed Mar 27, 2024 8:19 am

Problem when make a database for equipment

Post by doubleruri »

After 10 years, I come back to MUD~~ :D

Now I don't have much time for find what equipment to wear for different situation.I want make a database to quickly find what I need.(Old information of EQs is post on BBS)
After serveral days scripting for catch information , I meet problem when adding data to SQLite DB...

The identify example is like below: (In Chinese Traditional, I translate and mark with different color in English at right)
物品名稱: 火靈之吻(kiss of salamander) Item: 火靈之吻(kiss of salamander)
物品狀態: 發光 .Flag: Glowing
裝備位置: 盾牌Wear: shield
影響 智力 2 點. Int 2
The problem is
  1. Can I name Table with non-English but other language encoding in UTF-8?
    I create a database

    Code: Select all

    db:create("eqbank", {shield = "名稱","狀態","智力"})
    work and show correct in DB browser. But when I add data in Mudlet, I cannot did it.

    Code: Select all

    local mydb =  db:get_database("eqbank")
    db:add(mydb.Shield, {名稱 = "火靈之吻" ,狀態 = "發光", 智力 = 2})
    db:close(mydb)
    Mudlet says syntax error near symble = and give me a little ladybug XD
    I tried use [[名稱]] and "名稱" '名稱', all are wrong, but I change table name in English, It work!
    I am not a English player, reading 90+ information in mother langue will be more happy.
    Database.jpg
  • 2. How to script correctly and lightly when adding data to database?
    I made a alias for test

    Code: Select all

    pattern: ^dddd$
    code: local mydb = db:get_database("eqbank")
    db:add(mydb.Shield,{Int=15})
    
    Nothing add, Error report is :
    LUA ERROR: when running script writedata (Alias86),
    reason: ...ppData\Local\Mudlet\app-4.17.2\mudlet-lua\lua\DB.lua:780: attempt to index local 'conn'
    (a nil value)

    And put db:create in that will work

    Code: Select all

    pattern: ^dddd$
    code: 
    db:create("eqbank", {shield = "Name","Flag","Int"})
    local mydb = db:get_database("eqbank")
    db:add(mydb.Shield,{Int=15})
    
    my database will be 10 sheets (hands/boots/etc..) , every sheet has 90 column
    If put every db:create code before I add data, script will be more complex.
    How to resolve it??
  • Question3 is : Can I add data in Mudlet table like Cmud?
    I have a data in table:
    i.e.

    Code: Select all

    ItemData = {Name = "shield", Flag = "glow" , Int = 2}
    In Cmud I can use (#new ItemData) to put every data into db (but Cmud is crash too often :? )
    In Mudlet, Is there simple script instead of put every key in table one by one?
    P.S. My colum is same as variants i.e Name = ItemData .Name AC=ItemData .AC

doubleruri
Posts: 2
Joined: Wed Mar 27, 2024 8:19 am

Re: Problem when make a database for equipment

Post by doubleruri »

Answer myself.
It is welcome that anyone rewrite it for more good English reading. :D

1. Can I name Table with non-English but other language encoding in UTF-8?
Today mudlet cannot support it though you can use db broswer application or sqlite to create it.
maybe work on db:create() function can improve it?

2. How to script correctly and lightly when adding data to database?
Cause by not "conn database" yet.
run db:create(database_name,table) can conn yourdatabase.

A small tip is:
If you want to arrange your field by special order,and read in other database browser application with same order.
Add field ONE BY ONE can do that!
So below example code can help you. Write it in button :D
Code: [show] | [select all] lua
local AllName = {"CName","Name","LV","Type","Magic"} 
--field order as you want
local Data1 = {{ }}
for i = 1 ,#(AllName) do
   table.insert(Data1[1], AllName[i])
 --If you need name the sheet.--
   db:create("database_name", {sheet_name = unpack(Data1)})
-- If you don't need name the sheet.--  
-- db:create("database_name",unpack(Data1)) 
   display(Data1[1][i]) --[Debug]Check  which field was create. You can delete it.
end
display("end") --[Debug]Let us know it is done,you can replease it by any you like.
3.Tip about add/update data into database:
A table like :

Code: Select all

Item = {{ Name = "Candy", Type = "Food", LV = "1"}}
Important: There is 2 {{ & }}.

Code: Select all

db:add(sheet,unpack(Item))
If it is a simple table {} ,

Code: Select all

db:add(sheet,Item)
db:add(sheet,{Item})
db:add(sheet,unpack(Item))
ALL Not work. I don't know why XD

Note: db:update() only work on a table has _row_id field.(db:fetch() got it)
db:add() set _row_id nil

This can be used to debug your script.

Post Reply