Jardar Posted January 3, 2012 Share Posted January 3, 2012 So I have a start.lua file that loads beautifully, everything seems to work, but once i started getting into moving something around inside of the game world, I notice the keyboard isnt working when running the app. I have no idea why this would be, however, I hope someone could point it out for me. Please keep in mind that this is the first I see of LUA and my first return to Leadwerks in a couple of years, so any other pointers would be greatly appreciated as well. Code(start.lua): --Function for creating our blocks local function createBlock(object) local block = CreateCube() block:SetScale( Vec3(1,1,1) ) block:SetPosition( object.coords ) block:Paint(object.material) return block end --Function to place our physics bodies on blocks local function createPhy(object) local body = CreateBodyBox(1,1,1) body:SetPosition( object.coords ) body:SetMass(0) body:SetCollisionType(COLLISION_SCENE) return body end --Function for creating our world local function createWorld(materials) --our world size local worldSize = Vec2( 1024,2 ) --our empty world object local worldObject = {} --Fill our world for y = 1, worldSize.y do worldObject.y = {} for x = 1, worldSize.x do local xcoord = -1*(worldSize.x/2)+x local ycoord = -1*worldSize.y+y local block = { coords = Vec3( xcoord, ycoord, 0 ), material = materials.dirt } --Insert our block block.entity = createBlock(block) block.phy = createPhy(block) worldObject.y.x = block end end return worldObject end --[[ Here our actual game starts ]]-- --Register the abstract path RegisterAbstractPath("") --Set the graphics mode Graphics(800, 600, 32) --Create a framework object fw = CreateFramework() --set the camera local camera = fw.main.camera camera:SetPosition( Vec3(0,3,-10) ) --Create Light local light = CreatePointLight(10) light:SetPosition( Vec3(2, 6, -3) ) --Load our materials --DIRTY HACK need better execution for easier debugging local materials = {} materials.dirt = LoadMaterial("abstract::dirt.mat") --Generate our world createWorld(materials) --Create a character body controller = CreateController(2, 0.45, 0.5, 45) controller:SetMass(1) controller:SetCollisionType(COLLISION_CHARACTER) controller:SetPosition( Vec3(0,4,0) ) --create a cylinder for our controller local playerMesh = CreateCube() playerMesh:SetScale( Vec3(1, 2, 1) ) playerMesh:SetPosition( controller ) playerMesh:Move( Vec3(0, 0.5, 0) ) playerMesh:SetParent(controller) --define movement move = 0 local jump = 0 --attach camera to controller camera:SetParent(controller) DebugLights(1) DebugPhysics(1) --define collisions Collisions(COLLISION_CHARACTER, COLLISION_SCENE, 1) --Main loop while AppTerminate() == 0 do --Movement move = KeyDown(KEY_D)-KeyDown(KEY_A) print(move) --jump = KeyHit(KEY_SPACE)*10 --Update Controllers controller:Update(0, move, move, jump, 40, 10) --Update world fw:Update() --Render world fw:Render() --Flip the buffers Flip(0) end Quote Win7: 3.4GHz i7, 16Gb RAM DDR3, Radeon HD 6970 2048MB Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2012 Share Posted January 3, 2012 Try including require("scripts/constants/keycodes") at the top. There are some extra scripts to get some constants and other functions in the scripts folder and subfolders you might want to check out. Quote Link to comment Share on other sites More sharing options...
Jardar Posted January 3, 2012 Author Share Posted January 3, 2012 That deffinately helped Rick, thanks Quote Win7: 3.4GHz i7, 16Gb RAM DDR3, Radeon HD 6970 2048MB 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.