gordonramp Posted January 6, 2010 Share Posted January 6, 2010 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? Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
Canardia Posted January 6, 2010 Share Posted January 6, 2010 Reading/writing text and binary files seems very easy in LUA: http://www.lua.org/pil/21.2.html Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 6, 2010 Share Posted January 6, 2010 Does anyone know how to seach a file with Lua, to find specific fields or data? Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
Niosop Posted January 6, 2010 Share Posted January 6, 2010 Pretty much the same as with any other language. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 6, 2010 Share Posted January 6, 2010 lol. ok then. Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
Niosop Posted January 6, 2010 Share Posted January 6, 2010 If you give a more specific example we can give a more specific answer. How are the fields or data laid out? What are you searching for? Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 7, 2010 Share Posted January 7, 2010 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") ....... Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
gordonramp Posted January 7, 2010 Author Share Posted January 7, 2010 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. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
gordonramp Posted January 7, 2010 Author Share Posted January 7, 2010 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 Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
Recommended Posts
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.