Jump to content

Search the Community

Showing results for tags 'lua'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Categories

  • Models
    • Animals
    • Barriers
    • Characters
    • Containers
    • Environments
    • Furniture
    • Props
    • Rocks
    • Vegetation
    • Vehicles
    • Weapons
  • Materials
    • Brick
    • Cartoon
    • Decals
    • Dirt
    • Grass
    • Industrial
    • Medieval
    • Metal
    • Plastic
    • Plaster
    • Rock
    • SciFi
    • Sky
    • Signs
    • Tile
    • Stone
    • Walls
    • Wood
  • Plugins
  • Scripts
    • GUI
    • Object
    • Utilities
  • Shaders
    • Post-Processing Effects
    • Surface
  • Sounds
    • Ambience
    • Effects
    • Music
  • Tools
  • BATTLE LEAGUE's Assets
  • BATTLE LEAGUE's Mods

Blogs

There are no results to display.

There are no results to display.

Forums

  • Leadwerks
    • Technical Assistance
    • General Discussion
    • Programming
    • Game Art
    • Suggestion Box
    • Bug Reports
  • Platforms
    • Windows
    • Mac
    • Linux
  • Community
    • Showcase
    • Promotion
    • Off-topic
  • BATTLE LEAGUE's Topics
  • Vec-Tec's Releases
  • Vec-Tec's Topics
  • Forth's Development
  • Forth's Game design
  • Forth's Graphics
  • Forth's Documentation
  • Forth's TODO
  • Forth's IMPORTANT
  • Forth's Screenshots
  • The uncertain world's Game Design
  • The uncertain world's Programming
  • The uncertain world's TODO
  • The uncertain world's Graphics
  • The uncertain world's Screenshots
  • Muerte's Discussion

Categories

  • Records
  • Entity
  • Command Reference
  • Vec3
  • Vec4
  • Script Reference
  • Shader
  • Index
  • Material
  • Object
  • Buffer
  • Asset
  • Font
  • Shape
  • Sound
  • Texture
  • App
  • Context
  • Model
  • Light
  • DirectionalLight
  • PointLight
  • SpotLight
  • Attractor
  • Camera
  • Emitter
  • Listener
  • Pivot
  • Bone
  • Sprite
  • FileSystem
  • Key
  • Source
  • Surface
  • Math
  • AABB
  • dVec3
  • Mat3
  • Mat4
  • Plane
  • Transform
  • Vec2
  • Vec3
  • Vec4
  • Mutex
  • Prefab
  • PickInfo
  • Map
  • Stream
  • System
  • Thread
  • Time
  • Window
  • World
  • Driver
  • SoundDriver
  • GraphicsDriver
  • PhysicsDriver
  • OpenGL2GraphicsDriver
  • OpenGLES2GraphicsDriver
  • OpenALSoundDriver
  • NewtonDynamicsPhysicsDriver
  • Draw
  • Color
  • Blend
  • Joint
  • Debug
  • Component
  • Steamworks
  • LensFlare
  • Vehicle
  • Decal
  • Quat
  • Leaderboard
  • Probe
  • Analytics

Categories

  • Games

Product Groups

  • Software
  • Gear

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


Interests

Found 362 results

  1. Goodday everyone! I have this random question which i have been wondering for a while now. Considering next week is my exams which i'll proudly show my created small game made with leadwerks Now the question, i noticed as soon as it gets standalone exported, it opens a console screen with the game. Now this isn't a huge problem.. But i think it'll look neater without I have tried to follow up this post a bit: http://www.leadwerks.com/werkspace/topic/6445-le3-hide-dos-screen/ However, i got a bit confused and it doesn't seem to work (Perhaps because it was le3 and not le4?) Anyone got any suggestion / tip / method for me to solve this? Thanks in advance!
  2. Hi there, I was wondering how I can do animated sprite sheets for explosions, fx effecs and waterfalls? Have searched around the forums and haven't found anything. Thanks in common. Dennis
  3. I'm having a problem getting the Cos of an angle. My code is local tum = Cos(Angle) And I get the error "attempt to call global 'Cos' (a nil value)" Things I have tried: - Lower case c for cos - Brackets around Cos(Angle) - Same error occurs if I use Sin or Tan etc - Used a script variable ie Self.tum instead of local What am I doing wrong?
  4. At first thought this was an issue with mono vs stereo sounds, but tracked down the issue to Source:SetRange(). Whenever the range of a mono sound is set to 1.0 or below, it will play at full volume no matter how far away the source is from the listener. Using a slightly modified version of the Source:SetRange lua example, the sound will play when the range is greater than 2 (which is the distance from source to listener) and when the range is equal or less than 1.0: function App:Start() self.window = Window:Create("Source SetRange Issue",0,0,400,300) self.context = Context:Create(self.window) local sound = Sound:Load("Sound/doors/fdn_door_automatic_servo_driven_close_short_05.wav") self.source = Source:Create() self.source:SetSound(sound) sound:Release() self.source:SetLoopMode(true) self.source:Play() self.source:SetPosition(Vec3(0,0,2)) local listener = Listener:Create() listener:SetPosition(0,0,0) range = 0.1 toggle = 0.005 return true end function App:Loop() if self.window:Closed() or self.window:KeyHit(Key.Escape) then return false end range = range + toggle if range>=3 then toggle = -0.005 end if range<=0 then toggle = 0.005 end self.source:SetRange(range) Time:Update() self.context:SetColor(0,0,0) self.context:Clear() self.context:SetColor(1,1,1) self.context:SetBlendMode(Blend.Alpha) self.context:DrawText(string.format("Range: %.2f",range),0,2) self.context:Sync(true) return true end
  5. I'm in the process of making my first game, so i went to Leadwerks and started creating things. The problem comes when I want to make that a door opens when 2 pressure plates are activated. So, i wrote this code to create a "switch" that requires 2 inputs to output a signal to the door (in the flowgraph editor), but it doesn't work... function Script:Start() bool1 = false bool2 = false end function Script:Input1() --in bool1 = true end function Script:Input2() --in bool2 = true end if (bool1 == true and bool2 == true) then self.component:CallOutputs("Output") end what i'm doing wrong? i'm very new in programming
  6. SpEcIeS

    MonsterAI

    This morning I started up a fresh "Advanced First-Person Shooter" project. After the "07-AI and Events.map" was loaded and then ran, immediately an error was generated: Script Error error in function 'SetCollisionType'. argument #3 is 'boolean'; '[no object]' expected. Line 90 Is anyone else producing this error?
  7. I've been staring at this code for way too long and now I need different brains to look at it. This is the beginnings of a 3rd person character controller. I am now working at adding mouse look features but there seems to be a bug when the camera is at specific angles, notable y45 and y270. At those specific locations the camera glitches out. I will give it another try tomorrow, and no I don't want to create a pivot and anchor the camera to it and spin that --[[ Title: Third Person Controller Author: Einlander Start Date: 1-30-2016 Version: .01 Description: Script to control Player in 3rd person with keyboard and mouse Notes: This script is designed to mimic classical 3rd person game controls: *Look with mouse *Move with WASD *Follow Player as they move ]]-- Script.Cam =nil --entity "Camera" Script.moveSpeed = 2.5 --float "Move Speed" Script.speedMultiplier = 1.5 --float "Run Multiplier" Script.strafeSpeed = 4 --float "Strafe Speed" Script.jumpForce = 8 --float "Jump Force" function Script:Start() self.input={} self.unitangle = Vec3() self.anglemagnitude = nil end --[[ function Script:UpdateWorld() end --]] function Script:UpdatePhysics() local movex=0 local movez=0 self.input[0]=0 self.input[1]=0 local playerMovement = Vec3() -- I learned the boolean shortcuts from my years programming on a Casio Graphing Calculator self.input[1] = self.input[1] + ((window:KeyDown(Key.W) and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0)) self.input[0] = self.input[0] - ((window:KeyDown(Key.A) and 1 or 0) - (window:KeyDown(Key.D) and 1 or 0)) playerMovement.z = self.input[1] * self.moveSpeed -- Strafing playerMovement.x = self.input[0] * self.moveSpeed if self.carryingEntity == nil and window:KeyDown(Key.Shift) then playerMovement.z = playerMovement.z * self.speedMultiplier -- Run while Strafed -- playerMovement.x = playerMovement.x * self.speedMultiplier end local jump = 0 if window:KeyHit(Key.Space) and self:IsAirborne() == 0 then jump = self.jumpForce playerMovement = playerMovement * 1.6 end self.entity:SetInput(0, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true) local startpos = Vec3( self.entity:GetPosition(true).x, self.entity:GetPosition(true).y + 5 , self.entity:GetPosition(true).z -5 ) -- y distance to get above players head, z - distance we want from player local endpos = Vec3() -- rotate the starting position (where the camera is at) around the player position if self.rot == nil then self.rot = 0 end self.rot = self.rot+.5 local finalpos = Vec3() finalpos = self:rotateX3D({startpos},self.entity:GetPosition(true) , 0)[1] finalpos = self:rotatePointY({finalpos},self.entity:GetPosition(true) , self.rot)[1] -- when self.rot ~ 45 or 270 it flips just for that 1 angle -- set camera at the final rotated positon self.Cam:SetPosition(finalpos) -- make camera look at player local lookAt = self:LookAt(self.entity:GetPosition(true)) lookAt.z = 0 -- THIS LINE IS IMPORTANT. DO NOT REMOVE IT, IF YOU DO IT WILL CAUSE A JUMP WHEN THE Z ANGLE CHANGES FROM NEGATIVE TO POSITIVE OR VICE VERSA self.Cam:SetRotation(lookAt,true) end function Script:IsAirborne() return self.entity:GetAirborne() and 1 or 0 end function Script:LookAt(lookAt) --http://www.leadwerks.com/werkspace/topic/10191-short-example-of-mathatan2/page__hl__lookat --http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point --http://leadwerks.wikidot.com/wiki:face-entity --// Calculate angle from point A towards point B local tv = lookAt - self.Cam:GetPosition(true) local tRoty = Math:ATan2(tv.x, tv.z) local tRotx = 0 if lookAt.z >= self.Cam:GetPosition(true).z then tRotx = -Math:ATan2(tv.y* Math:Cos(tRoty), tv.z) else tRotx = Math:ATan2(tv.y* Math:Cos(tRoty), -tv.z) end tRotz = Math:ATan2( Math:Cos(tRotx), Math:Sin(tRotx) * Math:Sin(tRoty) ) return Vec3(tRotx,tRoty,tRotz-90) end function Script:Get3dDistance(pointa --[[as vec3--]], pointb--[[as vec3--]]) --[[as float--]] return math.sqrt((pointb.x - pointa.x)^2+ (pointb.y - pointa.y)^2+ (pointb.z - pointa.z)^2) end function Script:Get3dMagnitude(pointa --[[as vec3--]]) --[[as float--]] --http://www.fundza.com/vectors/normalize/ return math.abs(math.sqrt((pointa.x * pointa.x)+ (pointa.y * pointa.y)+ (pointa.z * pointa.z))) end function Script:NormalizeVector(pointa--[[as vec3--]], length--[[as float--]])--[[as vec3--]] --Yes I know leadwerks has these functions built in somewhere, but sometimes you just need to learn what it is you are exactly doing --http://www.fundza.com/vectors/normalize/ pointa.x = pointa.x / math.abs(length) pointa.y = pointa.y / math.abs(length) pointa.z = pointa.z / math.abs(length) return pointa end toRadians = function(degrees) return degrees / 180 * math.pi end function Script:rotatePointY(points, origin, degrees) local pointsout = {} for i = 1, #points do local point = Vec3(points.x,points.y,points.z) local x = origin.x + ( math.cos(toRadians(degrees)) * (point.x - origin.x) - math.sin(toRadians(degrees)) * (point.z - origin.z) ) local z = origin.z + ( math.sin(toRadians(degrees)) * (point.x - origin.x) + math.cos(toRadians(degrees)) * (point.z - origin.z) ) point.x = x point.z = z table.insert(pointsout, point) end return pointsout end function Script:rotatePointZ(points, origin, degrees) local pointsout = {} for i = 1, #points do local point = Vec3(points.x,points.y,points.z) local x = origin.x + ( math.cos(toRadians(degrees)) * (point.x - origin.x) - math.sin(toRadians(degrees)) * (point.y - origin.y) ) local y = origin.y + ( math.sin(toRadians(degrees)) * (point.x - origin.x) + math.cos(toRadians(degrees)) * (point.y - origin.y) ) point.x = x point.y = y table.insert(pointsout, point) end return pointsout end function Script:rotatePointX(points, origin, degrees) local pointsout = {} for i = 1, #points do local point = Vec3(points.x,points.y,points.z) local y = origin.y + ( math.cos(toRadians(degrees)) * (point.y - origin.y) - math.sin(toRadians(degrees)) * (point.z - origin.z) ) local z = origin.z + ( math.sin(toRadians(degrees)) * (point.y - origin.y) + math.cos(toRadians(degrees)) * (point.z - origin.z) ) point.y = y point.z = z table.insert(pointsout, point) end return pointsout end function Script:rotateX3D (points, origin, degrees) local pointsout = {} for i = 1, #points do local point = Vec3(points.x,points.y,points.z) local y = point.y; local z = point.z; point.y = origin.y + (y- origin.y) * math.cos(toRadians(degrees)) - (z - origin.z) * math.sin(toRadians(degrees)); point.z = origin.z + (z- origin.z) * math.cos(toRadians(degrees)) + (y - origin.y) * math.sin(toRadians(degrees)); table.insert(pointsout, point) end return pointsout end function Script:WrapAngle(angle) local currentrotation = angle if currentrotation.x < 0 then currentrotation.x = 359 - math.mod(currentrotation.x , 359) end if currentrotation.y < 0 then currentrotation.y = math.mod(currentrotation.y , 359) currentrotation.y = 359 - math.abs(currentrotation.y) end if currentrotation.z < 0 then currentrotation.z = 359 - math.mod(currentrotation.z , 359) end currentrotation.x = math.mod(currentrotation.x , 359) currentrotation.y = math.mod(currentrotation.y , 359) currentrotation.z = math.mod(currentrotation.z , 359) return currentrotation end --[[ function Script:Collision(entity, position, normal, speed) end --]] --[[ function Script:Draw() end --]] --[[ function Script:DrawEach(camera) end --]] --This function will be called after the world is rendered, before the screen is refreshed. --Use this to perform any 2D drawing you want the entity to display. function Script:PostRender(context) context:SetBlendMode(Blend.Alpha) local pos = self.Cam:GetRotation(true) local outText = "Actual angle" .. pos.x .. "|" ..pos.y .."|" ..pos.z --local outText = self:FaceEntity(self.Cam:GetPosition(true),self.entity:GetPosition(true)).x .."|" .. --self:FaceEntity(self.Cam:GetPosition(true),self.entity:GetPosition(true)).y .."|" .. --self:FaceEntity(self.Cam:GetPosition(true),self.entity:GetPosition(true)).z context:DrawText(outText,0,150) context:DrawText("Distance:" .. self:Get3dDistance(self.Cam:GetPosition(true) , self.entity:GetPosition(true)),0,165) pos = self.unitangle local outText = "unit angle" .. pos.x .. "|" ..pos.y .."|" ..pos.z context:DrawText(outText,0,180) pos = self.Cam:GetPosition(true) local outText = "Cam Position" .. pos.x .. "|" ..pos.y .."|" ..pos.z context:DrawText(outText,0,195) pos = self.entity:GetPosition(true) local outText = "Player Position" .. pos.x .. "|" ..pos.y .."|" ..pos.z context:DrawText(outText,0,210) end --[[ --This function will be called when the entity is deleted. function Script:Detach() end --]] --[[ --This function will be called when the last instance of this script is deleted. function Script:Cleanup() end --]]
  8. I'm inflicting damage the player and I find the "Hurt" script in the fpsplayer script. The first variable is "Damage" which will reduced the players health by that amount. The second is called "distributorOfPain". Does anyone know what this does? Also whats the difference between the "Hurt Script" and the "Take Damage Script". I know that using the "Take Damage Script" doesn't enact the dying script but I don't know why. If you use the take Damage Script the game continues but the player can no longer move.
  9. I'm in the process of debugging a loop which is supposed to vertically scroll some text contained in a table. My loop is verified as looping over the keys in order (ipairs(array) vs pairs(array)) but in the debugger (pictured) the keys appear out of order once we get to "k=10", where it appears after the first index. It's a small thing, but it confused me for a minute before I double-checked the loop again and verified that it is in fact iterating in the correct order. This is literally just a display issue in the debugger. Here's the screenshot of what I'm talking about (nevermind my improperly incremented values): Expected behavior: Keys in "txt_y" table are displayed in order Current behavior: Keys in "txt_y" table are displayed out of order once there are more than 9 keys.
  10. When I use Leadwerks I normally have my game run at desktop resolution windowed. Sometimes I want to see the performance difference in full screen (it's always better). To do this I would normally need to edit main.lua. After a bit of thinking and experimenting I made a short 'hack' that will allow you to hold f5 of f6 to run in full screen instead of windowed. tempwindow=Window:Create("key capture",0,0,1,1,1) context=Context:Create(tempwindow,0) if (tempwindow:KeyDown(Key.F5) or tempwindow:KeyDown(Key.F6))== true then windowstyle=windowstyle+window.FullScreen end Place this after if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end and before window=Window:Create(title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)
  11. I highly encourage some one who wants to make a bit of extra money on the side to spend some time creating a course for Leadwerks on www.udemy.com I am sure that every single one of the people who buy this engine would love a full blown course for the engine as well, to make sure they get the most out of their learning experience. I know I would. So please consider it, I would be the first one to purchase it. Teach LUA scripting and the over all API of Leadwerks in general in the course, that would be fantastic!
  12. I cannot find a way to 'autoscroll' the debug window text. It would be nice if it was possible to set it to 'autoscroll on ouput', so that you can easily see the latest messages that get's printed out. (Running on ubuntu, guessing it's the same on windows, but I have not tested on windows because I do not have that). It's not easy to debug when you debug 'blind' and then have to scroll down and read the output afterwards. Makes it very tricky. Also - the output window on the main editor screen - would be nice if that one also could show the same text as what the output\debug window in the script editor shows. That would make it easier\faster to debug.
  13. It looks like DrawText doesn't like multi-line string literals, it's reading them in as one long line that ends up mostly off of the screen and doesn't respond to escape characters (such as "\n") embedded in the multi-line string in order to try and simulate "wrapping". Either I'm missing some undocumented param or DrawText was only meant to draw a single line of text at a time. Of course, I can write a loop for this, but that incurs a performance penalty, especially with longer bits of text and seems to be a needlessly complex solution. My suggestion is to allow DrawText the ability to handle multi-line strings in LUA or have it renamed to DrawSingleLineText, since that's what it does.
  14. I think I posted this module on the forums in order to help someone a few weeks ago, but I thought It'd get more use if I created a blog post so it doesn't get diluted down in the forums. I've written this event module to make it easy to add keyboard and mouse button binds and it's come in handy to me for quite a few little scripts. Once again excuse the poor spacing as copy and paste here seems to remove my tabs. event.lua -- Event module written by Averice event = {} event.inputBinds = {} event.mouseBinds = {} function event.CheckInput() local succ, err; for key,tab in pairs(event.inputBinds) do if( App.window:KeyHit(key) ) then for k, v in pairs(tab) do if( not v.Held ) then succ, err = pcall(v.Func, unpack(v.Args)); if not succ then print("Event Error[Key]["..k.."]: "..err); end end end end if( App.window:KeyDown(key) ) then for k, v in pairs(tab) do if( v.Held ) then succ, err = pcall(v.Func, unpack(v.Args)); if not succ then print("Event Error[Key]["..k.."]: "..err); end end end end end for but, tab in pairs(event.mouseBinds) do if( App.window:MouseDown(but) ) then for k, v in pairs(tab) do succ, err = pcall(v.Func, unpack(v.Args)); if not succ then print("Event Error[Mouse]["..k.."]: "..err); end end end end end function event.AddInputBind(key, name, held, func, ...) local newInput = { Func = func, Args = {...}, Held = held or false } event.inputBinds[key] = event.inputBinds[key] or {}; event.inputBinds[key][name] = newInput; end function event.AddMouseBind(but, name, func, ...) local newInput = { Func = func, Args = {...} } event.mouseBinds[but] = event.mouseBinds[but] or {} event.mouseBinds[but][name] = newInput; end function event.RemoveInputBind(key, name) if( event.inputBinds[key] and event.inputBinds[key][name] ) then event.inputBinds[key][name] = nil; end end function event.RemoveMouseBind(but, name) if( event.mouseBinds[but] and event.mouseBinds[but][name] ) then event.mouseBinds[but][name] = nil; end end It's usage is really straight forward, you import the script, and in your App.loop you'll put event.CheckInput(); This will check for your binds and run them if needed so you don't have to fill your App.loop with key binds. To add a keyboard bind "event.AddInputBind(key, name, held, function, args); local function printStuff(...) print("Hello", ...); end event.AddInputBind(Key.A, "RandomName", false, printStuff, "How", "are", "you") -- varargs once again. --when the A key is pushed it should output, "Hello How are you"; -- if 'held' is true it will keep printing while it's held. --To remove it we use it's name and key. event.RemoveInputBind(Key.A, "RandomName"); -- Mouse bind functions are the same, just use event.AddMouseBind and event.RemoveMouseBind -- mouse bind functions are considered always held. Add a check to your function if you only -- want it done per click. A quick snippet that I use in my splash screen with my StateManager module to cancel the splash if escape is pushed. event.AddInputBind(Key.Escape, "__SHARDSPLASH", false, function() StateManager:Pop() end);
  15. Hello, I would like to take a JSON file and read its content into a normal Lua string. Even better, I would like to put a JSON text into a Lua table directly, if it's possible. So far, I've found this Lua lib for converting a JSON string into a Lua table and vice versa. However, I don't see how to read a whole file as a string. Thank you in advance! P.S. I know how to read an individual line with this function.
  16. About: This is a short series for the Leadwerks community on the process of creating a simple game using procedural content. This week we implement the map creation process discussed in part 02 then add the mesh generation and a controller to fly around our level. Then we'll have the first iteration of our procedurally generated map. Part 01 Part 02 Starting with the Map class. Map:Create Function...first iteration, no corridors. Simple nested for-loop to generate a room for each cell. Each room is stored in the table Map.Room[] with dimensions, a counter for reference and a cell offset in world units. For our example a cell is a virtual 40x40 space, our example map is made of 4 x 4 cells. We call the function like this... Map:Create (407, 4 , 4 , 40 ) And our function definition is... function Map:Create( seed , xsize , ysize , cellscale , roomscale ) self.xsize = xsize self.ysize = ysize self.seed = seed self.roomscale = roomscale math.randomseed( seed ) if roomscale == nil then roomscale = 1.0 end Map.roomscale = roomscale if cellscale == nil then cellscale = 40.0 end Map.cellscale = cellscale Map.roomheight = 2.0 Print("Creating map, dimensions " .. xsize .. " x " .. ysize) -- table to store our rooms Map.Room = {} -- room counter rcount = 1 for x=1,xsize do for y=1,ysize do if math.random() > 0.2 then self.Room[rcount] = {} local r = self.Room[rcount] r.roomID = rcount r.cellx = x r.celly = y r.x = math.random(cellscale) r.y = math.random(cellscale) r.width = math.ceil( math.random(3 , cellscale ) ) r.length = math.ceil( math.random(3 , cellscale ) ) r.info = string.format("id %.2d cellx %.2d celly %.2d x:%.3d y:%.3d w:%d h:%d", r.roomID , r.cellx , r.celly , r.x , r.y , r.width , r.length ) print(r.info) rcount = rcount+1 end end end self:MakeGeometry() end In the above code to reduce rooms arranged in a solid 'grid' there's a random chance that a cell skips room creation. The cell offset ( r.x and r.y ) serves to add more irregularity to the layout. Map.roomscale and Map.cellscale: bigger number = bigger space. One scales distance between rooms, the other scales the room mesh. After generating the geometry from such an arrangement we get this... I've added a head-up display to show an overhead map and annotations to the screenshot to show how the distribution of rooms work. So far so good. Perhaps worth mentioning the CELLS are ordered top to bottom then left to right. That gives you some idea that the random offset works to radically shift rooms around to avoid being too attached to the grid arrangement. Info: CELL is a term I use to describe a container in virtual space. Before we generate any geometry for our rooms we have all the data we need to display a map (like the one above). Debug overlays or HUDs are handy during early development and can be migrated to a finished game HUD later. All we need right now is some way to check room volumes and positioning, some info and the players position. Later we can use a second camera to draw a top-down view if required. Another feature we want in our HUD is some flag to draw it, a position to move it about the screen and a scale so we can fit the map to the whole screen or just squeeze it into a corner. The following code does all this. X and Y is typically used as a screen-coordinate position to draw an element and s is the size in pixels to fit the map into. If you need to re-size text as well then you need to start rendering these to a buffer but we'll avoid the extra complexity. This is often made easier with OpenGL commands but they are not exposed to Leadwerks LUA scripts (as of 2.5). Drawing the HUD and overhead map function DrawHUD() if App.showhud ~= true then return end SetBlend(2) SetColorf(0.1,0.3,0.1,0.3) DrawText("ROOM DATA",22,22) local c = string.format("RoomCount %d", #Map.Room) DrawText(c,22,60) local x = 40 local y = 80 for n,r in pairs(Map.Room) do DrawText( r.info , x , y ) y = y + 16 end x = 400 y = 80 s = 512 sx = s / (Map.cellscale * Map.xsize) sy = s / (Map.cellscale * Map.ysize) DrawText("OVERHEAD MAP",x,y-20) --DrawLine(x,y,x+s,y) DrawLine(x+s,y,x+s,y+s) DrawLine(x+s,y+s,x,y+s) DrawLine(x,y+s,x,y) for n=0,Map.xsize do DrawLine(x + (n*Map.cellscale*sx) , y , x + (n*Map.cellscale*sx) , y + s) end for n=0,Map.ysize do DrawLine(x , y + (n*Map.cellscale*sy) , x + s , y + (n*Map.cellscale*sy)) end -- sorry for the fiddly math here -- its needed to match the map scale with the HUD display scale for n,r in pairs(Map.Room) do local roomx = x + (( r.x + (r.cellx-1)*Map.cellscale) *sx ) local roomy = y + (( r.y + (r.celly-1)*Map.cellscale) *sy ) DrawRect( roomx , roomy , r.width * sx, r.length * sy ) DrawText(string.format("%.2d",r.roomID), roomx + ((r.width*sx)*0.5)-8 , roomy + ((r.length*sx)*0.5)-9 ) end DrawText(string.format("view co-ords x:%d y:%d", camera.position.x , camera.position.z) , 40, GraphicsHeight() - 20 ) -- player marker cross in yellow SetColorf(0.3,0.3,0.1,0.3) DrawText("X", x + (camera.position.x * sx)-4 , y - (camera.position.z * sy) -8 ) SetBlend(0) end The map size is adjusted by changing "s = 512" to however many pixels across. Objects are scaled and drawn accordingly. Once we start merging rooms this will need some alteration, the overhead camera might be a viable alternative and one we can have some fun with. randomly flagged tile data, looks like a "BallBlazer" level. Tiles and Geometry Rather than write up how it works you can look through the code and tinker with it. The next and penultimate part will cover generating corridors and using "tile" data to merge overlapping rooms and add props like doors. You'll see already there are random light sources assigned to each room, random assortments of props such as columns, crates, particles etc. can be done in a similar fashion. The Code for this article I've attached the full code which creates the room data and geometry (sans no corridors and intelligent tile merging - we'll deal with that in part 04). Don't forget to execute this script using ScriptEditor.exe (or run it with ENGINE.EXE) you will need to make sure the path at the top of START.LUA (MediaDir) points to your Leadwerks SDK location and the default scripts are present (as "required" at the top of the script). You'll find a few bits of code commented out and older functions I used to create meshes. I've left them in for curiosity (learning and laughter). Until part 04, have a good weekend.
  17. I was messing around one day and wanted to have certain objects be weightless. So I came up with this simple code. function Script:UpdatePhysics() self.entity:AddForce(0,self.entity:GetMass()*-world:GetGravity().y,0,true) end Just wanted to share it. You can can control the amount of weightlessness by controlling the amount (%) of gravity used in the calcualtion
  18. What's the difference between Hide and release. I know you can get a hidden entity back with show and you can get a released entity with instance are there any advantages to using either?
  19. Good evening, As Mentioned in the caption - is there a possibility to link Notepad++ to Leadwerks engine so that if I press F5 it "compiles" ? Would be super Awesome! yours Max Aigner
  20. Hello everyone, I know I ask quite some questions the last days - it's just that I have only three days a week to develop my customers needs.. I need a possibility to convert PNG files to TEX files. Because my software will include the customers PNG files in the 3d Scene. Is there a sourcecode for saving in the TEX file format? (or a simple file description of TEX files...?) thank you in advance! - yours Max
  21. hi everyone, I have just tried to implement an DLL into lua with the loadlib command. http://www.lua.org/pil/8.2.html#C-packages they say it should work but it does not Main.lua path = "c:\\windows\\system32\\user32.dll" local GetSystemMetrics = assert(loadlib(path, "GetSystemMetrics")) Error: "Script Error: Attempt to call global 'loadlib' (a nil value) Is there a way of enabling this? It would increase the possibilities of Leadwerks and Lua a Lot and it would allow us to make better leadwerks projects so that leadwerks can get more famous and bought more often!!
  22. Hello! So something weird have started happening in the later updates. It now instantly crashes on local mousePos = App.window:GetMousePosition() With the error MainMenu.lua" : 2 : attempt to index field 'window' (a nil value) To try, I tried creating the window with self.window = Window:Create("Window", 10, 10, 1280, 720, window.Titlebar) Which results in the same error. Suggestions? Thanks!
  23. Can self.component:CallOutput( "something" ) give a return value ? Means that the in-function returns a value that is passed to the CallOutput return Lua1.lua -------------------------------------------------------------------------------- function Script:func() local retval = self.component:CallOutput( "something" ) System:Print( retval ) -- prints "Hello" ? end Lua2.lua --------------------------------------------------------------------------------- function Script:something()--in return "Hello" end
  24. Yes. They used to be here but now they are gone.
  25. Where did the scripting documentation for FlowGraph go? I can't remember how to add parameters with In/Out and was going to check that but the documentation is gone.
×
×
  • Create New...