Jump to content

Search the Community

Showing results for tags 'LUA'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Blogs

  • Development Blog
  • Canardian's Blog
  • Beyond Civilization Blog Ext
  • Tyler's Blog
  • macklebee's Blog
  • B-Byrnes' Blog
  • Marleys Ghost's Blog
  • omid3098's Blog
  • Richardsimpo123456's Blog
  • DJDD's Blog
  • Rick's Blog
  • --
  • xtreampb's Blog
  • Economically Disadvantaged
  • klepto2's Blog
  • Old Blog
  • Chris Paulson's Blog
  • Davaris' Blog
  • nil
  • Rekindled Phoenix's Blog
  • Flexman's Blog
  • Kattemaksu Online
  • Marcousik's Creations Blog
  • EVE LBS Studio
  • Rendering puzzles
  • Screen Size Utility
  • Niosop's Blog
  • 1299 RTS Game Project
  • Blitzbat's Blog
  • gordonramp's Blog
  • Andy Gilbert's Blog
  • Marcus' Blog
  • JornAggror Blog
  • diedir's Blog
  • wayneg's Blog
  • Masterxilo's Blog
  • Dave Lee's Blog
  • peubuy's blog
  • OD Arts -Leadwerks Blog
  • The progression......
  • Ultra Software Company Blog
  • The Progression
  • Pancake's Blog
  • Test Blog
  • BLaBZ Blog
  • Pure³d's Blog
  • dreamhead Blog
  • RVL's Blog
  • DB's Blog
  • Toxin Games Development Blog
  • CombatHelo Blog (RSS Import)
  • Foolish's Blog
  • ZioRed's Corner
  • Toxin Games Twitter
  • Shard - Third Initiative
  • Shard's Blog
  • Soamp's Blog
  • Soamp's Blog
  • Laurens' Blog
  • JT`s warehouse district
  • Kennar's Blog
  • KiteFuchs' Blog
  • KiteFuchs' Blog
  • Rachel's Dev-Blog
  • Eagle's Blog
  • zaphos' Blog
  • please delete this blog
  • Afke's Blog
  • Richard Simpson
  • knowledgegranted's Blog
  • EdzUp(GD)'s Blog
  • aGameLife's Kelasel MMORPG Blog
  • tournamentdan's Blog
  • Beyond Civilization Blog
  • smashthewindow
  • AnniXa's Blog
  • AnniXa's Blog
  • Elemental Development
  • DigitalHax Blog
  • Aria's Blog
  • Strogg76's Blog
  • Clackdor's Blog
  • Leadwerks Project Status
  • simpleprogrammer's Blog
  • Pathfinding in LE.2.x
  • Naughty Alien's Blog
  • smashthewindow's Blog
  • Ali Salehi's Blog
  • Jardar's Blog
  • Chris Vossen's Development Blog
  • Scarlet Thread Studios' Blog
  • Kronos' Blog
  • Benton's Blog
  • ChrisV's Blog
  • tjheldna's Blog
  • shadmar's Blog
  • 3D Masons, LLC
  • Andy Gilbert's Enviro Models
  • ParaToxic's Blog
  • NarkLord's Blog
  • ChrisMAN's Blog
  • ChrisMAN's Blog
  • CGMan's Blog
  • The Game
  • Chris Tutorials
  • Leadwerks 3 Experience
  • An Alien Saga
  • klepto2 & Leadwerks 3
  • Inside the mind of eternal insomniac
  • josk's Blog
  • Shader Development in Leadwerks 3.1
  • 3D Coat : Column game making of
  • Einlander's Blog
  • Ginger George's Blog
  • I have a problem
  • Michael_J's Blog
  • nasamydifol's Blog
  • Digman's Blog
  • noesisGUI
  • SavageDogg38's Blog
  • Built from Ruins
  • Remaining Days
  • test_external_blog
  • The Hunt For Food Blog
  • Crazy Minnow Studio
  • CrazyMinnowStudio
  • Guppy's Blog
  • Playing Online
  • Evayr's Blog
  • DerRidda's Blog
  • Karl's Blog
  • whiterabbit's Blog
  • Tinyboss Games
  • abendkleider's Blog
  • sacguccireplica's Blog
  • Arena
  • Imchasinyou's Blog
  • xtom's Blog
  • Lua is better than you think.
  • mdgunn's Blog
  • Crime Closer
  • lxFirebal69xl's Blog
  • Wedmer's Blog
  • Lockdown, going forward.
  • Pump-Action Captain
  • Igor's Blog
  • Dead Anyway
  • Runenrise and more
  • reepblue's Blog
  • Slippy's Corner
  • LUA Musings
  • severjack's Blog
  • mikeporter's Blog
  • miko93's Blog
  • Megalocerous' Blog
  • lxFirebal69xl's Blog
  • aiaf's Blog
  • Lostghbear's Blog
  • echo $BLOG_NAME > blog_title.tmpl
  • johnadam111's Blog
  • Dwarf Beard
  • burgelkat's Blog
  • Charrua's Blog
  • peterpaul's Blog
  • joshmathews' Blog
  • Martin Kearl's Blog
  • Brutile's blog
  • tipforeveryone's Blog
  • Glushchenko Blog
  • Express Lab Games Blog
  • Blueapples' Blog
  • DooMAGE's Blog
  • Structura devblog
  • UltraEngine - Experiences, add-ons and other Stuff
  • martyj's Blog
  • Dragonfreak's Blog
  • Brutile's Blog
  • assigmenthelp
  • Case Study Assignment Help
  • How to deal with bad grade ?
  • How to deal with bad grade ?
  • GameDev Blog
  • devcjohnson's Blog
  • devcjohnson's Blog
  • THE WHAT? Blog
  • The Demurian Scribe
  • GUI Editor
  • GUI Tutorial
  • noob_shaders
  • The Seventh World
  • Phodex Games Blog
  • Leadwerks VS Source 2
  • Work in Progress - Scifi PBR Media
  • [C++] First Player game start
  • The Blog of Yue
  • Snowboarding Development Blog
  • Ocean: Rendering in Leadwerks 4
  • Game Ready Maps
  • Ultra App Kit (Advanced Custom Widgets)
  • Poking around
  • Blender tutorials
  • Usefull Scripts & Components
  • Thirsty Panther
  • Ultimate Action Game Controller
  • Ultra Tutorials

Forums

  • Software
    • General Discussion
    • Programming
    • Game Artwork
    • Showcase
    • Suggestion Box
    • Bug Reports
  • Addons
    • Extensions & Plugins
    • Components
    • Addon Development
  • Platforms
    • Windows
    • Linux
    • macOS

Categories

  • Streams and Events
  • Tutorials
  • Games
  • Work in Progress

Categories

  • Components
  • Effects
  • Extensions
  • Materials
    • Asphalt
    • Brick
    • Concrete
    • Debris
    • Effects
    • Fabric
    • Ground
    • Marble
    • Metal
    • Organic
    • Plaster
    • Rock
    • Roof
    • Sand
    • Snow
    • Surface Imperfections
    • Tile
    • Wood
  • Models
    • Animals & Creatures
    • Architecture
    • Food
    • Machinery
    • Plants and Vegetation
    • Props
    • Vehicles
    • Tools
  • Scenes
  • Skyboxes
  • Sound
  • Tools

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location

  1. Prerequisites https://www.ultraengine.com/learn/luasetup?lang=lua Also Lua extension is quite useful for VS Code, if you don't mind Tencent. Map Create a simple map call start.ultra with a brush as floor and a Empty aka pivot with FPSPlayer component How to do it: Now you can press "F5" in the editor, or select "Game" then "run" to run your game to just made map: You can add skybox in Edit > World Settings (at top buttons in the Editor) by choosing skybox.dds from Materials\Environment\Default Main menu, loading screen and GUI Create a simple menu with couple brushes and camera and name this map menu.ultra Now open main.lua. For that open Project tab in top right corner, select root project folder and double click on Open the VSCode.bat file. If this fails make sure you have setup Visual Studio Code correctly https://www.ultraengine.com/learn/luasetup?lang=lua Select all i nfile and delete it from VS Code. Now paste there folllow code with just a Loading screen, almost without anything else and save: -- local before variable means it will be avaiable only in current scope (inside script, funtion, cycle or condition body) -- loading screen vars local loadingWorld = nil local loadingCamera = nil local loadingText = nil local loadingBackground = nil -- for using in main loop local currentWorld = nil local currentUi = nil local displays = GetDisplays() -- You can WINDOW_FULLSCREEN to styles to make game fullscreen, 3rd and 4th are resolution size window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR) -- Create a framebuffer, needed for rendering framebuffer = CreateFramebuffer(window) font = LoadFont("Fonts/arial.ttf"); loadingWorld = CreateWorld(); local centerX = framebuffer:GetSize().x * 0.5 local centerY = framebuffer:GetSize().y * 0.5 local labelHeight = framebuffer:GetSize().y * 0.2 loadingBackground = CreateSprite(loadingWorld, framebuffer.size.x, framebuffer.size.y) loadingBackground:SetColor(0.2, 0.2, 0.2); loadingBackground:SetRenderLayers(2); loadingText = CreateSprite(loadingWorld, font, "LOADING", labelHeight, TEXT_CENTER | TEXT_MIDDLE) loadingText:SetPosition(centerX, centerY + labelHeight * 0.5, 0) -- 0 layer - no render, 1 - default render, we will use 2 for UI and sprites loadingText:SetRenderLayers(2) -- Creating camera for sprites, which needs to be orthographic (2D) for UI and sprites if they used as UI loadingCamera = CreateCamera(loadingWorld, PROJECTION_ORTHOGRAPHIC); loadingCamera:SetPosition(centerX, centerY, 0); -- camera render layer should match with stuff that you want to be visible for this camera. RenderLayers is a bit mask, so you can combine few layers, but probably you don't need it in most cases loadingCamera:SetRenderLayers(2) currentWorld = loadingWorld -- simple minimum game loop while window:Closed() == false do -- Garbage collection step collectgarbage() -- getting all events from queue - input, UI etc. while (PeekEvent()) do local event = WaitEvent() -- You need to do it for UI in 3D scene if (currentUi) then currentUi:ProcessEvent(event) end end if (currentWorld) then -- Update game logic (positions, components etc.). By default 60 HZ and not depends on framerate if you have 60+ FPS currentWorld:Update() -- 2nd param is VSync (true by default), 3rd is fps limit. Can by changed dynamically. currentWorld:Render(framebuffer) end end Now if we start a game we will see this loading screen: And once we have a screen we can create a menu to load in. Create MainMenu.lua in Source folder. To do it in Visual Studio Code select "File" then select "New file". Type in "MainMenu.lua" and hit return. A dialog box will open asking where you want to save this file. It should open in the source folder by default but if it dosen't navigate to the source folder and hit return. Paste in the following content for this file and save: local function NewGameButtonCallback(Event, Extra) --this overload currently is not working --EmitEvent(EVENT_GAME_START, nil, 0, 0, 0, 0, 0, nil, "start.ultra") EmitEvent(EVENT_GAME_START) return true end local function ExitButtonCallback(Event, Extra) --to close application os.exit() return true end local function InitMainMenu(mainMenu) mainMenu.world = CreateWorld(); mainMenu.scene = LoadMap(mainMenu.world, "Maps/menu.ultra") --Create user interface local frameSize = framebuffer:GetSize(); mainMenu.ui = CreateInterface(mainMenu.world, font, frameSize) mainMenu.ui:SetRenderLayers(2); --to make backgrount transparent mainMenu.ui.background:SetColor(0.0, 0.0, 0.0, 0.0) --Create camera for GUI mainMenu.uiCamera = CreateCamera(mainMenu.world, PROJECTION_ORTHOGRAPHIC) mainMenu.uiCamera:SetPosition(frameSize.x * 0.5, frameSize.y * 0.5, 0); mainMenu.uiCamera:SetRenderLayers(2); --for correct rendering above 3D scene mainMenu.uiCamera:SetClearMode(CLEAR_DEPTH); --Menu buttons local newGameButton = CreateButton("New game", frameSize.x / 2 - 100, 125, 200, 50, mainMenu.ui.background); ListenEvent(EVENT_WIDGETACTION, newGameButton, NewGameButtonCallback); local exitButton = CreateButton("Exit", frameSize.x / 2 - 100, 200, 200, 50, mainMenu.ui.background); ListenEvent(EVENT_WIDGETACTION, exitButton, ExitButtonCallback); end --functions should be declared after another function that this fucntion uses function CreateMainMenu() local mainMenu = {} InitMainMenu(mainMenu) return mainMenu end Let's get back to main.lua. We need to import main menu script and custom event ids to top: import "Source/MainMenu.lua" --custom events ids EVENT_GAME_START = 1001 EVENT_MAIN_MENU = 1002 Now add after "local currentUi = nil" menu var and callback fuctions for events: framebuffer = nil local menu = nil local function StartGameEventCallback(Event, Extra) --nothing just for now return true; end --function should be declared after vars that this function uses local function MainMenuEventCallback(Event, Extra) menu = CreateMainMenu(); --switching current render and update targets for loop currentWorld = menu.world; currentUi = menu.ui; return true; end Put this above main loop: --to show Loading screen before Main Menu loadingWorld:Render(framebuffer); --ListenEvent are needed to do something in callback function when specific even from specfic source (or not, if 2nd param is nil) emitted ListenEvent(EVENT_GAME_START, nil, StartGameEventCallback); ListenEvent(EVENT_MAIN_MENU, nil, MainMenuEventCallback); --let's try it out! EmitEvent(EVENT_MAIN_MENU) Just in case if something one wrong, current main.lua main.lua We need to modify FPSPlayer component just a little bit. Via Editor you can find it by selecting "Project" ( Top right of the editor screen), select "Source", select "Components", select "Player". Double click "FPSPlayer.lua". Add to its top to other vars a new one (24th line to be precisely) FPSPlayer.doResetMousePosition = true And new condition for mouse position reset in FPSPlayer.lua in Update() at 286 line or find thine line with Ctrl-F and past to search field "window:SetMousePosition(cx, cy)" if doResetMousePosition then window:SetMousePosition(cx, cy) end One big thing left - a game to play. Add Game.lua to project at Source folder: local function GameMenuButtonCallback(Event, Extra) if (KEY_ESCAPE == Event.data and Extra) then local game = Extra local isHidden = game.menuPanel:GetHidden() game.menuPanel:SetHidden(not isHidden) if isHidden then window:SetCursor(CURSOR_DEFAULT) else window:SetCursor(CURSOR_NONE) end if (game.player ~= nil) then --to stop cursor reset to center when menu on game.player.doResetMousePosition = not isHidden end end return false end local function MainMenuButtonCallback(Event, Extra) EmitEvent(EVENT_MAIN_MENU) return true end local function ExitButtonCallback(Event, Extra) os.exit() return true end local function InitGame(game, mapPath) game.world = CreateWorld(); game.scene = LoadScene(game.world, mapPath) for k, entity in pairs(game.scene.entities) do local foundPlayer = entity:GetComponent("FPSPlayer") if (foundPlayer ~= nil) then game.player = foundPlayer; break; end end --Create user interface for game menu local frameSize = framebuffer:GetSize() game.ui = CreateInterface(game.world, font, frameSize) game.ui:SetRenderLayers(2) game.ui.background:SetColor(0.0, 0.0, 0.0, 0.0) game.uiCamera = CreateCamera(game.world, PROJECTION_ORTHOGRAPHIC) game.uiCamera:SetPosition(frameSize.x * 0.5, frameSize.y * 0.5, 0) game.uiCamera:SetRenderLayers(2); game.uiCamera:SetClearMode(CLEAR_DEPTH); --widgets are stays without extra pointers because parent widet, game.ui.background in this case, keep them --to remove widget you should do widget:SetParent(nil) game.menuPanel = CreatePanel(frameSize.x / 2 - 150, frameSize.y / 2 - 125 / 2, 300, 250, game.ui.background) local menuButton = CreateButton("Main menu", 50, 50, 200, 50, game.menuPanel); ListenEvent(EVENT_WIDGETACTION, menuButton, MainMenuButtonCallback); local exitButton = CreateButton("Exit", 50, 150, 200, 50, game.menuPanel); ListenEvent(EVENT_WIDGETACTION, exitButton, ExitButtonCallback); --we don't need game menu on screen while playing game.menuPanel:SetHidden(true); --and we will need it once hitting Esc button ListenEvent(EVENT_KEYUP, window, GameMenuButtonCallback, game); end --functions should be declared after another function that this fucntion uses function CreateGame(mapPath) local game = {} InitGame(game, mapPath) return game end Add new Game include and global var to main.lua: import "Source/Game.lua" local game = nil Update function callbacks at 24 line: local function StartGameEventCallback(Event, Extra) --destroying a main menu menu = nil --to show loading screen loadingWorld:Render(framebuffer) if Event.text ~= nil and Event.text ~= "" then --in lua .. used for string concatenation game = CreateGame("Maps/" .. Event.text); else game = CreateGame("Maps/start.ultra"); end --switching current render and update targets for loop currentWorld = game.world currentUi = game.ui return true; end --function should be declared after vars that this function uses local function MainMenuEventCallback(Event, Extra) --destroying a game instance if one existed game = nil --to show loading screen loadingWorld:Render(framebuffer) menu = CreateMainMenu() --switching current render and update targets for loop currentWorld = menu.world; currentUi = menu.ui; return true; end And in the end we have a game with own menu: All created and modified classes: LuaMenuGameLoad.zip Repository: https://github.com/Dreikblack/LuaTutorialProject/tree/menu-loading-screen-and-gui
  2. In this tutorial we will make a newcomponent, which will be moving an entity to way points and movement start will be activated by trigger zone Let's start with making WayPoint component: In the Ultra Editor click plus button in Project tab: Now open Visual Studio Code. Open WayPoint.json "properties" is a list of component's fields avaible for edit in the Editor "name" - actual name of property that will be used in code later "label" - just a name to display in the Editor "value" - initial value that property will have after map load by default. Can be changed in the Editor for specific entity. "options" - allows to choose int value in Combo Box in the Editor. First option - 0 value Default value here also defines type of this property. New component made via editor have all possible types. Replace WayPoint.json content with: { "component": { "properties": [ { "name": "nextPoint", "label": "Next point", "value": null }, { "name": "doStayOnPoint", "label": "Do stay on point", "value": false } ] } } nextPoint - another WayPoint, where platform will move to once reach this one doStayOnPoint - wait for command before moving to next WayPoint Take a note that the Editor sees only json which could be same for LUA and C++ projects which allows to work on same map even if people have different engine versions (Pro/Standard) or make a level before programming components. Replace WayPoint.lua content with: WayPoint = {} -- name should always match class name for correct component work WayPoint.name = "WayPoint" WayPoint.nextPoint = nil -- wait for command before moving to next WayPoint WayPoint.doStayOnPoint = false -- Start is called when Load() of all components was called already function WayPoint:Start() end -- will be called on map load function WayPoint:Load(properties, binstream, scene, flags, extra) -- internally entity saves in the Editor as String unique id -- can be empty if this way point is final if type(properties.nextPoint) == "string" then for _, entity in ipairs(scene.entities) do if properties.nextPoint == entity:GetUuid() then self.nextPoint = entity break end end -- self.nextPoint = scene:GetEntity(properties.nextPoint) if type(properties.doStayOnPoint) == "boolean" then self.doStayOnPoint = properties.doStayOnPoint end end return true end -- Can be used to save current component state on map save function WayPoint:Save(properties, binstream, scene, flags, extra) if self.nextPoint ~= nil then properties.nextPoint = self.nextPoint:GetUuid() properties.doStayOnPoint = self.doStayOnPoint; end return true end -- Can be used to get copy of this component function WayPoint:Copy() local t = {} local k local v for k, v in pairs(self) do t[k] = v end return t end -- needed for correct work, when loaded from a map RegisterComponent("WayPoint", WayPoint) return WayPoint Let's create our floating object component and call it WayMover WayMover.json: { "component": { "properties": [ { "name": "moveSpeed", "label": "Move Speed", "value": 4.0 }, { "name": "nextPoint", "label": "Next point", "value": null }, { "name": "doDeleteAfterMovement", "label": "Del after move", "value": false } ], "inputs": [ { "name": "DoMove" } ], "outputs": [ { "name": "EndMove" } ] } } moveSpeed - how fast entity will move to way point doDeleteAfterMovement - auto remove entity when it's reach final waypoint. Can be used for door, that goes into walls or floor inputs - it's commands for components, that usually triggered by another components via flowgrough outputs - commands that component sends to other components inputs via FireOutputs("EndMove"); in the component code WayMover.lua: WayMover = {} -- name should always match class name for correct component work WayMover.name = "WayMover" WayMover.moveSpeed = 4.0 WayMover.isMoving = false WayMover.nextPoint = nil WayMover.scene = nil function WayMover:Copy() local t = {} local k local v for k, v in pairs(self) do t[k] = v end return t end -- will be called on map load function WayMover:Load(properties, binstream, scene, flags, extra) if type(properties.moveSpeed) == "number" then self.moveSpeed = properties.moveSpeed end if type(properties.isMoving) == "boolean" then self.isMoving = properties.isMoving end if type(properties.doDeleteAfterMovement) == "boolean" then self.doDeleteAfterMovement = properties.doDeleteAfterMovement end if type(properties.nextPoint) == "string" then for _, entity in ipairs(scene.entities) do if properties.nextPoint == entity:GetUuid() then self.nextPoint = entity break end end -- self.nextPoint = scene:GetEntity(properties.nextPoint) -- need scene for removing entity on doDeleteAfterMovement condition self.scene = scene return true end end -- Can be used to save current component state on map save function WayMover:Save(properties, binstream, scene, flags, extra) if self.nextPoint ~= nil then properties.nextPoint = self.nextPoint:GetUuid() properties.doStayOnPoint = self.doStayOnPoint; end properties.moveSpeed = self.moveSpeed; properties.isMoving = self.isMoving; properties.doDeleteAfterMovement = self.doDeleteAfterMovement; return true end function WayMover:DoMove() self.isMoving = true end function WayMover:MoveEnd() local doStay = false if (self.nextPoint ~= nil) then doStay = self.nextPoint:GetComponent("WayPoint").doStayOnPoint self.nextPoint = self.nextPoint:GetComponent("WayPoint").nextPoint end if (doStay or self.nextPoint == nil) then self.isMoving = false; self:FireOutputs("EndMove") -- deleting entity if need to, after reaching final way point if (not doStay and self.nextPoint == nil and self.doDeleteAfterMovement and self.scene ~= nil) then --commented out this code for now until bind for RemoveEntity will added --self.scene:RemoveEntity(self.entity) end end end function WayMover:Update() if (not self.isMoving) then return; end local wayPoint = self.nextPoint if (self.entity == nil or wayPoint == nil) then return end --60 HZ game loop, change to own value if different to keep same final speed local speed = self.moveSpeed / 60.0 local targetPosition = wayPoint:GetPosition(true) --moving to point with same speed directly to point no matter which axis local pos = self.entity:GetPosition(true); local distanceX = Abs(targetPosition.x - pos.x); local distanceY = Abs(targetPosition.y - pos.y); local distanceZ = Abs(targetPosition.z - pos.z); local biggestDelta = distanceZ; if (distanceX > distanceY and distanceX > distanceZ) then biggestDelta = distanceX; elseif (distanceY > distanceX and distanceY > distanceZ) then biggestDelta = distanceY; end local moveX = MoveTowards(pos.x, targetPosition.x, speed * (distanceX / biggestDelta)); local moveY = MoveTowards(pos.y, targetPosition.y, speed * (distanceY / biggestDelta)); local moveZ = MoveTowards(pos.z, targetPosition.z, speed * (distanceZ / biggestDelta)); self.entity:SetPosition(moveX, moveY, moveZ) if (self.entity:GetPosition(true) == targetPosition) then self:MoveEnd() end end -- needed for correct work, when loaded from a map RegisterComponent("WayMover", WayMover) return WayMover Now we can use just made component in practice. One of things that can be made is door or secret wall activated by player actions and this door will move a little bit inward and then to the side inside of wall. After that invisible now door will be removed. Create a walls with a empty place between them. Create couple of Empty/pivots and attach WayPoints to them. First WayPoint place a same place where door will be, but offset a bit deep into. In Scene tab grab and drag 2nd WayPoint to Nex Point field of 1st WayPoint. Place 2nd WayPoint insde of the wall. Create a door between walls. Attach WayMover component to it. Grab and drag 1st WayPoint to door's WayMover Next Point field. Enable "Del after Move" in WayMover component Create a box before door, make its collision type a trigger: Add Collision Trigger component to it. Open Flowgraph (2nd button at left side of the Editor). Drag and Drop trigger and door to it from Scene tab. In different order, but same result in video format: Result should looks something like that in game: In fast debug mode it might crash at this moment for unkown reason. Use Full Debug or Run mode. Project files: LuaExample2.zip Repository: https://github.com/Dreikblack/LuaTutorialProject/tree/2-making-and-using-components
  3. LuaExample2.zip 1. Run in Fast debug mode 2. Hit start game btn in menu 3. Just after first frame of map apps closes without error notifications or new errors in debug console btw i have strange errors on map load in any debug mode like: Error: Failed to load scene "Path/ProjectName" Deleting prefab "Path/ProjectName" Loading prefab "Path/ProjectName" Error: Failed to load sound "Sound/Impact/bodypunch3.wav"
  4. If do something like that in lua script: EmitEvent(EVENT_WIDGETACTION, nil, 0, 0, 0, 0, 0, nil, "start.ultra")
  5. Josh

    Color Changer

    This uses the Quake light animation presets to add some interesting color modulation to any entity. ColorChanger.zip The following presets are available: Normal Flicker Slow Strong Pulse Candle 1 Fast Strobe Gentle Pulse 1 Flicker 2 Candle 2 Candle 3 Slow Strobe Flourescent Flicker Slow Pulse Todo: The candle presents don't look right to me, but I'm not sure what they are supposed to look like. I remember them as being a gentle flicker. There is no interpolation between the nearest two values, it just grabs one single value, so it's not very smooth. I guess this is appropriate for the strobe effects, but not for others.
  6. I've been spending the past few days trying to figure out how to add SDL2 to Leadwerks, as it has an additional Lua binding that would be nice to have. Not to mention the gamepad support (which is the main reason because just adding XInput only would give support for XBox 360 and Dualshock 3 controllers). Not having any experience with an engine like Leadwerks, application building, or libraries has severely impacted my ability to figure out what to do in my current situation. I know I need to include the library and expose it to Lua, but I don't know how to do that, and I don't know how to actually add it to the engine either. I've taken a look at some resources online, such as lazyfoo, and it hasn't really helped me understand. Any help or other resources that could be passed along to me would be greatly appreciated. Thanks!
  7. Here the current Camera Dolly Component i created. It consists of 2 Components. The Camera Dolly Component itself. The Camera Dolly Event Component. Usage Extract and place it into your `Souce/Components` directory. Add a Camera to your Scene. Add a "Empty" Node to your scene that will contain the Camera Spline Path. Add "Empty" Nodes inside this CameraPath node that defines the path the camera will move along. (takes the rotation into account as well as long as no "Point Camera At" node is selected. Name each "Empty" Node path point "p1", "p2", "p3" and so forth. (subject to change) and order the nodes accordingly. At the end this should look something like this in your Scene list: In the Camera itself with the CameraDolly component added, select the CameraPath node and optionally a node where the camera should point at. If you want to do something as soon as the Camera reaches a point along the path, add the CameraDollyEvent Component to one of the path nodes and add it to the Flowgraph. Todo and known issues The order of nodes in the Editor is not always the same as returned by the API (see https://www.ultraengine.com/community/topic/65647-moving-entities-in-editor-looses-order-and-cannot-be-moved-to-top/ ) Its difficult to determine the rotation of points without visualisation. Its difficult to guess the path the camera takes along the spline without visualisation. Movement speed is not yet Update thread independent. (unlikely but possible, still thanks to Josh for adding `World:GetSpeed()`). Rotation might not work (see https://www.ultraengine.com/community/topic/65628-lua-entitygetrotation-always-returns-vec3-000/ ) Download CameraDolly.zip
  8. Tried: GetComponent("Mover") GetComponent(Mover) GetComponent<Mover>() This example also not working https://www.ultraengine.com/learn/Entity_GetComponent?lang=lua require "Components/Motion/Mover" --Get the displays local displays = GetDisplays() --Create a window local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR) --Create a framebuffer local framebuffer = CreateFramebuffer(window) --Create a world local world = CreateWorld() --Create a camera local camera = CreateCamera(world) camera:SetClearColor(0.125) camera:SetPosition(0, 0, -2) --Create a light local light = CreateBoxLight(world) light:SetRotation(45, 35, 0) light:SetColor(2) light:SetRange(-5, 5) --Create a model local box = CreateBox(world) box:SetColor(0,0,1) --Add a component for automatic motion local component = box:AddComponent(Mover) component.rotationspeed.y = -2 box.mover.rotationspeed.x = 2 local componentTest = box:GetComponent("Mover") if (componentTest ~= nil) then Print("Success") end while window:KeyDown(KEY_ESCAPE) == false and window:Closed() == false do --Update the world world:Update() --Render the world to the framebuffer world:Render(framebuffer) end
  9. Editor in lua project open Save As window when i click Run or Debug Game Last update in Steam beta branch
  10. 1. New game 2. Esc to call menu 3. Press Main menu 4. Continue game 5. If no app is froze yet do paragraph 2 again. Usually it happens at 2nd continue game but often happen at 1st too, Same approach works for me in main C++ project, game.lua globals.lua main.lua
  11. Josh

    AmbientNoise

    Plays a sound continuously or intermittently. AmbientNoise.zip
  12. Josh

    MatchRotation

    This component will copy the rotation of another entity, with adjustable smoothing. MatchRotation.zip
  13. Here's a new lib that i just finished that will allow game controller support for Lua fans! EDIT: Source: https://onedrive.live.com/redir?resid=1653f4923c37f970!278&authkey=!ABW8a3PdvzR_8cE&ithint=file%2czip Binaries (dll & so): https://onedrive.live.com/redir?resid=1653f4923c37f970!284&authkey=!AM0p2lTBH1mMSzk&ithint=file%2czip A lua example is provided, you can simply overwrite your existing App.lua with mine on a new test project. * Note: Lua sandbox must be disabled to use libs. Unfortunately i don't have linux installed so i couldn't compile it for that platform and I was able to compile it under Linux but i didn't get the chance to test it as i don't have the sdl2 binary libs. I included the full source should anyone want to re-compile it. Those that don't want to, simply copy LuaGamePad.dll file where your game executable is. You'll need to copy SDL2.DLL there as well, it's included. Tested with: - Logitech Rumblepad - Xbox 360 controller (XInput) Cheers!
  14. Hi there team, time no see... I'm still working on the v4.0 Update for my Steam game. And one of the addons inside this update, was the option of drive an Opel Kadett car... And here is my question about... I have develop the mirror effect with a Camera using RenderTarget option on a Texture, and then the script: Script.TexturaProyecta=""--string "Textura" function Script:Start() local tex=Texture:Load("Materials/MisTexturas/Camaras_Texturas/"..self.TexturaProyecta..".tex") self.entity:SetRenderTarget(tex) end This works fine, but i've got a problem with the final image... Is there a way for make MIRRORED the image on the mirror? I've tried mirroring the texture, or using 2 cameras, but nothing works for me. I've got the same problem on another map: Many thanks in advance for your help.
  15. Hello team, I'm going crazy with this bull****-idea... Is there any LUA command that allows us to obtain the name of the map we are on? I want to store the map name we are playing in a String variable, and then execute an IF to validate that value so that: - If I am in the map bull****.map a variable has "OK" text. - If I am in the map bullface.map the previous variable has "NotOK" text. (sight) I am unable to get the map name to save it in the global variable. And I don't know why... I have created a script where I enter manually the name... But that script (despite being assigned to a pivot in the map that is executed when the map is loaded) is not able to modify the value of the global variable defined in main.lua I have tried to use the mapfile variable used in main.lua of the project, but still don't know how to use it to get the name of the map we are on... This question may seem simple, but it's really driving me crazy.
  16. Hi everyone, I'm currently encountering an issue with a Pick operation in my Lua code and I'm hoping someone can help me figure out what I'm missing. Here's the context: I have a player controller, which is essentially a pivot that creates a light and a camera. The player controller doesn't involve any movement, the mouse position on the screen simply influences the camera rotation. I also have an enemy that randomly spawns and passes in front of the light, down a corridor. I want to check two things - if the light is on, and if the enemy crosses the light's path. If both conditions are met, I want to call a method from the player script to the enemy script. Here's the relevant part of my player controller code which handles the light being on and the Pick operation: function Script:UpdateWorld() [...] if not self.flashlight:Hidden() then local pickInfo = PickInfo() local i**** = self.entity.world:Pick( self.entity:GetPosition(), self.lightRayEnd:GetPosition(), pickInfo, .25, false, Collision.Character ) if i**** and pickInfo.entity:GetKeyValue("classname") == "npc_nurse" then pickInfo.entity.script:SetPlayerIsShiningLight() end end end The flashlight check works as expected. However, I'm having trouble with the Pick method. It seems to correctly pick up the enemy when it crosses the ray's path. But it also appears to pick up another entity. I've simplified my map to include only a floor for the enemy to walk on and the basic set-up for the player controller. I've confirmed that the KeyValue is being correctly set in the enemy script (in the Start method), and that the collision is set to Character. Through debugging (I've removed all the console debug statements from the code above for clarity), I found that when I test for the pick position, it returns 0,0,0. To make sure I wasn't missing something in my calculations, I created another pivot to mark the end of the raycast (self.lightRayEnd). Does anyone have any idea what I could be doing wrong, or what might be causing this issue? I appreciate any input or suggestions. Thanks!
  17. How do I end a Leadwerks program using a script. I would to like to end the program when the quit button is pressed but can't work out how to do this. Also should I release all entities and sounds before closing or doesn't it matter. Thanks in advance.
  18. 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.
  19. Just some background: i am making a game for a research project for school. I have no prior experience with coding so I'm a bit dumb Here's my question: How do i code in my animations? there are a lot of little things out there but they don't help me, i would appreciate it if someone were to explain it to me for my specific case. i have all of the animations done, i made them in blender. so far the only code i have is from these two posts, however i've moved the camera so that it is from a third person view: this whole animation thing has really been demotivating as i just dont know what i need so it would be nice to move past this to something equally as painful to find out. btw whilst researching i found there is very little helpful information out there anymore. there are countless posts where there are videos and websites linked however there they are either taken down or private, which is annoying because they could be helpful. either way, thank you for reading, i hope you understand what i mean and hope you might help me. Honestly all i need is a step-by-step (kind of) guide to how i get my animations to show for all my characters.
  20. can someone please help me i made a inventory for my game but when you place items in the inventory the image does not show i have gone over and over cant cant find the error. can anyone do me a working inventory script please :-) would appreciate it.
  21. so I try to get the center of the screen and find the mouse position and then find the difference then using ATan(change in y/ change in x) to find the angle the object must rotate to and set the angle to that, the only issue is when the mouse x is <= 0 the object flips (so lets say the right side of the object was facing the mouse it then becomes the left side) I assume this issue is to do with the fact that ATan(change in y/change in x)=ATan(-change in y/-change in x) but here is my code:
  22. During development of Leadwerks Game Engine, there was some debate on whether we should allow multiple scripts per entity or just associate a single script with an entity. My first iteration of the scripting system actually used multiple scripts, but after using it to develop the Darkness Awaits example I saw a lot of problems with this. Each script used a different classname to store its variables and functions in, so you ended up with code like this: function Script:HurtEnemy(amount) if self.enemy ~= nil then if self.enemy.healthmanager ~= nil then if type(self.enemy.healthmanager.TakeDamage)=="function" then self.enemy.healthmanager.TakeDamage(amount) end end end end I felt this hurt script interoperability because you had to have a bunch of prefixes like healthmanager, ammomanager, etc. I settled on using a single script, which I still feel was the better choice between these two options: function Script:HurtEnemy(amount) if self.enemy ~= nil then if type(self.enemy.TakeDamage)=="function" then self.enemy.TakeDamage(amount) end end end Scripting in Turbo Game Engine is a bit different. First of all, all values and functions are attached to the entity itself, so there is no "script" table. When you access the "self" variable in a script function you are using the entity object itself. Here is a simple script that makes an entity spin around its Y axis: function Entity:Update() self:Turn(0,0.1,0) end Through some magic that is only possible due to the extreme flexibility of Lua, I have managed to devise a system for multiple script attachments that makes sense. There is no "component" or "script" objects itself, adding a script to an entity just executes some code that attached values and functions to an entity. Adding a script to an entity can be done in C++ as follows: model->AttachScript("Scripts/Objects/spin.lua"); Or in Lua itself: model:AttachScript("Scripts/Objects/spin.lua"); Note there is no concept of "removing" a script, because a script just executes a bit of code that adds values and functions to the entity. Let's say we have two scripts named "makeHealth100 and "makeHealth75". MakeHealth100.lua Entity.health=100 MakeHealth75.lua Entity.health=75 Now if you were to run the code below, which attaches the two scripts, the health value would first be set to 100, and then the second script would set the same value to 75, resulting in the number 75 being printed out: model->AttachScript("Scripts/Objects/MakeHealth100.lua"); model->AttachScript("Scripts/Objects/MakeHealth75.lua"); Print(entity->GetNumber("health")); Simple enough, right? The key point here is that with multiple scripts, variables are shared between scripts. If one scripts sets a variable to a value that conflicts with another script, the two scripts won't work as expected. However, it also means that two scripts can easily share values to work together and create new functionality, like this health regeneration script that could be added to work with any other scripts that treat the value "health" as a number. HealthRegen.lua Entity.healthregendelay = 1000 function Entity:Start() self.healthregenupdatetime = CurrentTime() end function Entity:Update() if self.health > 0 then if CurrentTime() - self.healthregenupdatetime > self.healthregendelay then self.health = self.health + 1 self.health = Min(self.health,100) end end end What about functions? Won't adding a script to an entity overwrite any functions it already has attached to it? If I treated functions the same way, then each entity could only have one function for each name, and there would be very little point in having multiple scripts! That's why I implemented a special system that copies any added functions into an internal table. If two functions with the same name are declared in two different scripts, they will both be copied into an internal table and executed. For example, you can add both scripts below to an entity to make it both spin and make the color pulse: Spin.lua function Entity:Update() self:Turn(0,0.1,0) end Pulse.lua function Entity:Update() local i = Sin(CurrentTime()) * 0.5 + 0.5 self:SetColor(i,i,i) end When the engine calls the Update() function, both copies of the function will be called, in the order they were added. But wait, there's more. The engine will add each function into an internal table, but it also creates a dummy function that iterates through the table and executes each copy of the function. This means when you call functions in Lua, the same multi-execution feature will be available. Let's consider a theoretical bullet script that causes damage when the bullet collides with something: function Entity:Collision(entity,position,normal,speed) if type(entity.TakeDamage) == "function" then entity:TakeDamage(20) end end If you have two (or more) different TakeDamage functions on different scripts attached to that entity, all of them would get called, in order. What if a function returns a value, like below?: function Entity:Update() if self.target ~= nil then if self.target:GetHealth() <= 0 then self.target = nil --stop chasing if dead end end end If multiple functions are attached that return values, then all the return values are returned. To grab multiple returned values, you can set up multiple variables like this: function foo() return 1,2,3 end a, b, c = foo() print(a) --1 print(b) --2 print(c) --3 But a more practical usage would be to create a table from the returned values like so: function foo() return 1,2,3 end t = { foo() } print(t[1]) --1 print(t[2]) --2 print(t[3]) --3 How could this be used? Let's say you had a script that was used to visually debug AI scripts. It did this by checking to see what an entity's target enemy was, by calling a GetTarget() function, and then creating a sprite and aligning it to make a line going from the AI entity to its target it was attacking: function Entity:UpdateDisplay() local target = self:GetTarget() self.sprite = CreateSprite() local p1 = self.entity:GetPosition() local p2 = target:GetPosition() self.sprite:SetPosition((p1 + p2) * 0.5) self.sprite:AlignToVector(p2 - p1) self.sprite:SetSize(0.1,(p2-p1):Length()) end Now let's imagine we had a tank with a main gun as well as an anti-aircraft gun that would ward off attacks from above, like this beauty I found on Turbosquid: Let's imagine we have two different scripts we attach to the tank. One handles AI for driving and shooting the main turret, while the other just manages the little machine gun. Both the scripts have a GetTarget() function, as the tank may be attacking two different enemies at once. We can easily modify our AI debugging script to handle multiple returned values as follows: function Entity:UpdateDisplay() local targets = { self:GetTarget() } --all returned values get put into a table for n,target in ipairs(targets) do local sprite = CreateSprite() self.sprites.insert(sprite) local p1 = self.entity:GetPosition() local p2 = target:GetPosition() sprite:SetPosition((p1 + p2) * 0.5) sprite:AlignToVector(p2 - p1) sprite:SetSize(0.1,(p2-p1):Length()) end end However, any scripts that are not set up to account for multiple returned values from a function will simply use the first returned value, and proceed as normal. This system supports both easy mix and match behavior with multiple scripts, but keeps the script code simple and easy to use. Scripts have easy interoperability by default, but if you want to make your function and variable names unique to the script it is easy to do so. Let me know if you have any other ideas for scripting in Turbo Game Engine.
  23. Tell me how to get a similar result, for bending fishing rods under load?
  24. khotan

    Fracture ?

    Can i create a fracture sim based with voronoi in Leadwerks that control over on vertices or edges ? is it possible ? Lua or C++?
  25. How do I tell if a variable is odd or even using Lua? % is used in other languages is it the same with Leadwerks?
×
×
  • Create New...