Jump to content

Data


gordonramp
 Share

Recommended Posts

I know this as a major topic and I'm probably not the best one to bring it up but I will anyway because everyone is going to have to look at it sooner or later. Josh has posted an input console and I'm sure it's not the only one. Now what to do with the data from that and other sources. Starting with simple solutions.. Is it possible to write to a text file and also read it using Lua from the LE. I come from DBPro and in that language it is. It's also possible to write to the Windows Registry. Then there's Xml, and .ini files or purpose built 3rd-parties like sqlite3. So has anyone been exploring this and come up with any simple examples of using Lua to write and read data for use in the LE?

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

alrighty..

 

Well I am looking at using the cfg file for settings graphics for my game testing, instead of hard coding it into the start up file every time.

 

So I would have

 

[GraphicsSettings]

GraphicsWidth=

GraphicsHeight=

etc....

 

so I got

GameSettings=io.open("graphics.cfg")
.......

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

I added this Lua into the LE example1 and it runs with no errors but no text appears on the screen. Anyone have a clue as to why?

 

print(io.open("newinput", "w"))--write
print(io.open("newinput", "r"))--read
DrawText(newinput,0,10)--draw

 

Update:

Don't bother.. I get it.

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Here is some example code which writes and reads data to and from a text file. Open the ScriptEditor in the LE.SDK folder and place this code in it. Run it and a text file (my.txt) will be created in the same folder. Then the code will read the text file and write the contents to the screen. Note: If the Output content is changed, then the previous content in the text file is overwritten.

 

--Register abstract path
RegisterAbstractPath("")

--Set graphics mode
if Graphics(1024,768)==0 then
Notify("Failed to set graphics mode.",1)
return
end

world=CreateWorld()
if world==nil then
Notify("Failed to initialize engine.",1)
return
end

gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),1+2+4+8)

camera=CreateCamera()
camera:SetPosition(Vec3(0,0,-2))

light=CreateSpotLight(10)
light:SetRotation(Vec3(45,55,0))
light:SetPosition(Vec3(5,5,-5))

material=LoadMaterial("abstract::cobblestones.mat")

mesh=CreateCube()
mesh:Paint(material)

ground=CreateCube()
ground:SetScale(Vec3(10.0,1.0,10.0))
ground:SetPosition(Vec3(0.0,-2.0,0.0))
ground:Paint(material)

light=CreateDirectionalLight()
light:SetRotation(Vec3(45,45,45))

---------------------------------------------------------
--Create a text file and write data to it

io.output(io.open("my.txt","w"))
io.write("21")
io.close()

---------------------------------------------------------

while AppTerminate()==0 do

mesh:Turn(Vec3(AppSpeed()*0.5,AppSpeed()*0.5,AppSpeed()*0.5))

UpdateAppTime()
world:Update(AppSpeed())

SetBuffer(gbuffer)
world:Render()
SetBuffer(BackBuffer())
world:RenderLights(gbuffer)

----------------------------------------------------------
--Open the text file and write it's context to the screen

file = io.open("my.txt","r")
for line in file:lines() do
DrawText(line,0,20) 
end
file:close()

-----------------------------------------------------------

DrawText(UPS(),0,0)

Flip(0)
end

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...