Jump to content
Leadwerks Community

Recommended Posts

Posted

Depending on how much data you plan to handle, have you considered CSV files? It's pretty much a fancy text file that has been formatted with commas.

It's kind of a poor mans database solution, but at least you won't need any external libraries or apps to read and write data, plus you can always import the data to a SQL database in the future if need be.

There's lots of tutorials and code samples readily available around the web.

 

Posted

Thanks, but I mean How to use database in Leadwerks :D just dont know where to start. I have bunch of weapons and want to store their parameters (rate of fire, model path ...) to a database, any kind of database.

Talking about CSV files, how can I use them ?

Posted
5 minutes ago, Thirsty Panther said:

Couldn't you just use a table for your data storage?

yes, I am using table, but in the future my game data will be much more complex . therefore I need a database, this helps me easier to manage data too

  • Like 1
Posted
12 hours ago, tipforeveryone said:

Thanks, but I mean How to use database in Leadwerks :D just dont know where to start. I have bunch of weapons and want to store their parameters (rate of fire, model path ...) to a database, any kind of database.

Talking about CSV files, how can I use them ?

CSV files are great for small amounts of data, but flexible enough to be used in large games as well. I've seen them used in several major titles -  Armed Assault (Operation Flashpoint) used it to contain unit/weapon data among other things.

Here's some instructions on how to create a CSV file - it's really easy:

https://www.computerhope.com/issues/ch001356.htm

And here's a Lua code sample that shows how to insert data from a CSV file into a table and vice-versa:

http://nocurve.com/2014/03/05/simple-csv-read-and-write-using-lua/

CSVs make a good stepping stone towards learning and using SQL DBs but, I haven't tried using LUA and SQL together 'yet' to make any good tutorial recommendations.

 

 

  • Thanks 1
Posted

I looked at this for a few mins the other day, since I made the original post, and since that original file isn't in the post (is it anywhere? I can't find it on my side) someone would have to create this DLL again. Once that's done it's really easy to work with if you have sql experience. Using a database is generally just easier (once it's setup) if you're doing a lot of querying, updating, & inserting but this sounds like you just need a config file that has a nice editor. I have a json library I got from somewhere that turns lua tables into json and the other way around too, plus I know there are a bunch of json editors out there that give a nice tool for visually working with that data. Perhaps that would be helpful?

  • Thanks 1
  • 1 month later...
Posted

would this be the right path to success?

Get Sqlite3 here: https://www.sqlite.org/download.html
Get DLL here: https://www.dll-files.com/lua5.1.dll.html
Rename Lua5.1.dll to sqlite3.dll

regsvr32 C:\Windows\System32\sqlite3.dll

Directory of C:\Temp
<DIR> luasql
lua5.1.exe
sqlite3.dll
hello.lua

require "luasql.sqlite3"

env = luasql.sqlite3()
conn = env:connect("test.sqlite")

assert(conn:execute("create table if not exists tbl1(one varchar(10), two smallint)"))
assert(conn:execute("insert into tbl1 values('hello!',10)"))
assert(conn:execute("insert into tbl1 values('goodbye',20)"))

cursor = assert(conn:execute("select * from tbl1"))
row = {}
while cursor:fetch(row) do
    print(table.concat(row, '|'))
end

cursor:close()
conn:close()

env:close()
 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...