With the upcoming Lumberyard Beta 1.8, we’re continuing to respond to customer feedback by making some important changes to the Behavior Context. Significant improvements to the Lumberyard Editor include replacing the existing script context with a new, easier to use reflection context. This change paves the way for exciting future development around TrackView and our new visual and Lua scripting interfaces. Outlined below are some important steps to help you prepare for this migration. As always, we are here to assist you with any questions.
Below is a detailed preview of the steps required for Lumberyard 1.8 migration.
Step 1. Update your engine build
The initial step involves updating the Lumberyard engine as you normally would. Please follow the documented instructions before proceeding.
Step 2. Convert your C++ code from Script Context to BehaviorContext
If you have created any event buses that expose functionality to Lua using the script context, you will need to convert those. There are two parts to this:
- Any EBUS senders you created need to be converted to BehaviorContext handlers.
- Expose the EBUS handlers to Lua using the BehaviorContext in your component’s Reflect method and remove the old AZ_SCRIPTABLE_EBUS macro calls.
Instructions for migrating your event buses will be released with Beta 1.8
Step 3. Convert your LUA script syntax
There are several improvements to Lua syntax that provide better flexibility and more similarity to C++ syntax.
- Instead of senders in Lua you send an event as you would in C++ using Event or Broadcast, depending on which delivery mechanism you want.
-- The old way,using the script context syntax:
self.uiCanvasLuaBusSender = UiCanvasLuaBusSender(self.canvasEntityId)
local entityWithFader = self.uiCanvasLuaBusSender:FindElementById(2)
-- The new and improved Behavior Context syntax:
local entityWithFader = UiCanvasLuaBus.Event.FindElementById(self.canvasEntityId,2)
2.The syntax for handlers now uses a Connect method similar to C++.–The old way, using the script context syntax:
self.uiCanvasNotificationHandler = UiCanvasNotificationLuaBusHandler(self, canvasEntityId)
-- The new and improved Behavior Context syntax:
self.uiCanvasNotificationHandler = UiCanvasNotificationLuaBus.Connect(self, canvasEntityId)
-- Also new: if you do not want to connect immediately: self.uiCanvasNotificationHandler = UiCanvasNotificationLuaBus.CreateHandler(self)
-- then later:
self.uiCanvasNotificationHandler:Connect(canvasEntityId)
- You now create a local instance of your script component and return it at the end of the file.
-- MyScriptFile.lua, old school script context way:
myscriptfile = {} -- This table used to have to be named exactly the same thing as the file name
-- MyScriptFile.lua,new and Improved Way:
local ScriptName = {} -- Name this table whatever you find appropriate
...Your Lua Script Code...
return ScriptName -- The table you return here is the one used by the engine
- Entity references are treated the same as any other property and no longer use a special syntax
-- Old School Script Context Way:
myscriptfile = {
Properties = {
Property = { entity = '' },
}
}
--New and Improved Way:
local ScriptName = {
Properties = {
Property = { default = EntityId() },
AltProp = EntityId(), -- Also works
}
}
return ScriptName
Detailed instructions for migrating Lua scripts will be released with Beta 1.8
We hope this helps you prepare for upgrading your projects to Lumberyard Beta 1.8 as smoothly as possible. Please post an questions, concerns, or comments in this thread and we’ll prioritize providing answers.