Jump to content

Lua Suggestion (General Function Structure + Camera Data)


EasternGamer
 Share

Recommended Posts

Intro

With the recent dev-blogs, I feel like there's been a change in attitude with Lua. Before, we basically never got changes to it or the changes were very minimal/incomplete. (*cough* character orientation *cough*)
But, now that we're adding a bunch of functions to Lua, so much so that it's starting to get cluttered with really long function names, I think a general structure change should occur. A perfect example is camera data.

Structure Change

The core unit, control unit and system basically are filled to the brim with functions that don't really related to them, especially system.
 
So, here I go with what I believe should happen:
The creation of a "Construct" default slot. (No links required)
The creation of a "Player" default slot. (No links required)
The creation of a "Database" default slot. (No links required)

The creation of a "Elements" default slot. (No links required)

Construct Slot (moved to)

This slot will handle everything to do with the construct, and only the construct. As the first dev-blog has shown, a fair number of things are irrelevant of the core, thus it doesn't quite make sense that we should still access the core for them.

For example, world orientation of the construct is irrelevant to the core, and even ordinary orientation is irrelevant to the core since it is based off the orientation unit, a gyro or core.

However, data which is more core-related remains, like direct calculations/measurements that you would imagine the core making (velocity, acceleration etc.).

 

Player Slot (moved to)

This slot will handle everything to do with the master player, the player who has executed the control unit. As you can guess, a fair number of functions are placed on the unit because of this. But, it sort of makes little sense beyond the fact that the player activated, not to mention to access any player related info, they want to prefix every function with MasterPlayer, a perfect example of how absurdly long it is getting is unit.getMasterPlayerWorldForward(), now tack on camera to it... unit.getMasterPlayerCameraWorldForward(). You get the point.

 

Database Slot (moved to)

This will consolidate any thing that essentially accesses a database, static or otherwise, for instance getting the player name, position, etc. It will be similar to the Lua version in our files, but be entirely made of native code, instead of Lua. This should help with Database.lua's semi-redundancy and inefficiency, aside from code length contraction.
 

Elements Slot (moved to)

This will consolidate any general element function that is normally accessed by the core. This will remove the need to basically prefix stuff with getElementDATAById(uid)
Instead, you will simple say getDATAById(uid) or getDATA(uid)

 

Keys

  • Bad Name* (Italics, suffixed by one or more light yellow asterisks, name requires a change for consistency reasons)
  •  🆕 Dev Blog Addition (Bold, prefixed by "New" emoji)
  • moved to (Colour coded, moved to another slot)
  • Suggested Addition (Bold, green)


Core

  • getData()
  • getConstructMass()
  • getConstructIMass()
  • getConstructCrossSection()
  • getMaxKinematicsParametersAlongAxis(taglist,crefaxis)
  • getConstructWorldPos()
  • getConstructId()
  •  🆕 getConstructName()
  •  🆕 getOrientationUnitId()
  • getWorldAirFrictionAngularAcceleration()
  • getWorldAirFrictionAcceleration()
  • spawnNumberSticker(nb, x, y, z, orientation)
  • spawnArrowSticker(x, y, z, orientation)
  • deleteSticker(index)
  • moveSticker(index, x, y, z)
  • rotateSticker(index, angle_x, angle_y, angle_z)
  • getElementIdList()
  • getElementNameById(uid)
  • getElementTypeById(uid)
  • getElementHitPointsById(uid)
  • getElementMaxHitPointsById(uid)
  • getElementMassById(uid)
  • getElementPositionById(uid)
  • 🆕 getElementForwardById(uid)
  • 🆕 getElementUpById(uid)
  • 🆕 getElementRightById(uid)
  • getElementIndustryStatus(uid)*
  • getElementTagsById(uid)
  • getSchematicInfo(schematicId)
  • getAltitude()
  •  🆕 getCurrentPlanetId()
  • g()**
  • getWorldGravity()***
  • getWorldVertical()****
  • getAngularVelocity()
  • getWorldAngularVelocity()
  • getAngularAcceleration()
  • getWorldAngularAcceleraton()
  • getVelocity()
  • getWorldVelocity()
  •  🆕 getAbsoluteVelocity()
  •  🆕 getWorldAbsoluteVelocity()*****
  • getWorldAcceleration()
  • getConstructWorldOrientationForward()
  • getConstructWorldOrientationRight()
  • getConstructWorldOrientationUp()
  • getConstructOrientationForward()
  • getConstructOrientationRight()
  • getConstructOrientationUp()
  • getPvPTimer()
  • getPlayersOnBoard()******
  • getDockedConstructs()*******
  • isPlayerBoarded(pid)
  • isConstructDocked(pid)
  • forceDeboard(pid)
  • forceUndock(cid)
  • getBoardedPlayerMass(pid)
  • getDockedConstructMass(cid)
  • getParent()
  • getCloseParents()
  • getClosestParents()
  •  🆕 getParentPosition()
  •  🆕 getParentWorldPosition()
  •  🆕 getParentForward()
  •  🆕 getParentUp()
  •  🆕 getParentRight()
  •  🆕 getParentWorldForward()
  •  🆕 getParentWorldUp()
  •  🆕 getParentWorldRight()
  • dock(pid)
  • undock()
  • setDockingMode(mode)
  • getDockingMode()
  • getCoreStress()
  • getMaxCoreStress()
  • getCoreStressRatio()
  • All Events

*getElementIndustryStatus() -> getElementIndustryStatusById()
**g() -> getLocalConstructGravityIntensity()

***getWorldGravity() -> getConstructWorldGravity()

****getWorldVertical() -> getWorldGravity()

*****getWorldAbsoluteVelocity() -> getAbsoluteWorldVelocity()  (Swapping the Absolute Prefix with the World prefix sounds better and is probably more consistent)

******getBoardedPlayerIds()

*******getDockedConstructIds()

 

System

  • getActionKeyName(actionName)
  • showScreen(bool)
  • setScreen(content)
  • createWidgetPanel(label)
  • destroyWidgetPanel(panelId)
  • createWidget(panelId, type)
  • destroyWidget(widgetId)
  • createData(dataJson)
  • destroyData(dataId)
  • updateData(dataId, dataJson)
  • addDataToWidget(dataId, widgetId)
  • removeDataFromWidget(dataId, widgetId)
  • getMouseWheel()
  • getMouseDeltaX()
  • getMouseDeltaY()
  • getMousePosX()
  • getMousePosY()
  • getThrottleInputFromMouseWheel()
  • getControlDeviceForwardInput()*
  • getControlDeviceYawInput()
  • getControlDeviceRightLeftInput()**
  • lockView(state)
  • isViewLocked()
  • freeze(bool)
  • isFrozen()
  • getTime()
  • getActionUpdateDeltaTime()
  • getPlayerName(pid)
  • getPlayerWorldPos(pid)
  •   🆕 getOrganizationName(oid)
  •   🆕 getOrganizationTag(oid)
  • getWaypointFromPlayerPos()
  • setWaypoint(waypointStr)
  • getScreenHeight()
  • getScreenWidth()
  • getFov()
  • print(msg)
  • logInfo(msg)
  • logWarning(msg)
  • logError(msg)
  • All Events

*getControlDeviceForwardInput ->getControlDevicePitchInput

**getControlDeviceRightLeftInput ->getControlDeviceRollInput

 

ControlUnit

  • exit()
  • setTimer(timerTagId, period)
  • stopTimer(timerTagId)
  • getAtmosphereDensity()
  • getClosestPlanetInfluence()
  • 🆕 getMasterPlayerPosition()
  • 🆕 getMasterPlayerWorldPosition()
  • 🆕 getMasterPlayerWorldForward()
  • 🆕 getMasterPlayerWorldUp()
  • 🆕 getMasterPlayerWorldRight()
  • 🆕 getMasterPlayerForward()
  • 🆕 getMasterPlayerUp()
  • 🆕 getMasterPlayerRight()
  • getMasterPlayerId()
  • getMasterPlayerMass()
  • getMasterPlayerParent()
  • 🆕 getMasterPlayerOrgIds()
  • setEngineCommand(...)
  • setEngineThrust(taglist, thrust)
  • setAxisCommandValue(axis, commandValue)
  • getAxisCommandValue(axis)
  • setupAxisCommandProperties(axis, commandType, targetSpeedRanges)
  • setupControlMasterModeProperties(controlMasterModeId, displayName)
  • getControlMasterModeId()
  • cancelCurrentControlMasterMode()
  • isAnyLandingGearExtended()
  • extendLandingGears()
  • retractLandingGears()
  • isMouseControlActivated()
  • isMouseDirectControlActivated()
  • isMouseVirtualJoystickActivated()
  • isAnyHeadlightSwitchedOn()
  • switchOnHeadlights()
  • switchOffHeadlights()
  • isRemoteControlled()
  • activateGroundEngineAltitudeStabilization(targetAltitude)*
  • getSurfaceEngineAltitudeStabilization()*
  • deactivateGroundEngineAltitudeStabilization()*
  • computeGroundEngineAltitudeStabilizationCapabilities()*
  • getThrottle()
  • setSignalIn(plug, state)
  • getSignalIn(plug)
  • All Events

*I got no idea what to replace those with, but the names are just weird, what's a surface engine, ground engine? Function name is super long.

 

Construct

  • getWorldOrientationForward()
  • getWorldOrientationRight()
  • getWorldOrientationUp()
  • getOrientationForward()
  • getOrientationRight()
  • getOrientationUp()
  •  getWorldPos()
  • getId()
  • 🆕 getName()
  • 🆕 getOrientationUnitId()
  • getMass()
  • getIMass()
  • getCrossSection()
  • getLocalGravityIntensity()

 

Elements

  •  getIdList()
  • getNameById(uid)
  • getTypeById(uid)
  • getHitPointsById(uid)
  • getMaxHitPointsById(uid)
  • getMassById(uid)
  • getPositionById(uid)
  • 🆕 getForwardById(uid)
  • 🆕 getUpById(uid)
  • 🆕 getRightById(uid)
  • getIndustryStatusById(uid)
  • getTagsById(uid)
  • getElementById(uid)

 

Player

  • getId()
  • getMass()
  • getParent()
  • 🆕 getOrgIds()
  • lockView(state)
  • isViewLocked()
  • freeze(bool)
  • isFrozen()
  • getFov()
  • getHorizontalFov(bool)
  • getVerticalFov(bool)
  • getHeadlampState()
  • setHeadlampState(bool)
  • isSeated()
  • getSeatId()
  • getCameraView()
  • getCameraWorldForward()
  • getCameraWorldUp()
  • getCameraWorldRight()
  • getCameraWorldPos()
  • getCameraLocalForward()
  • getCameraLocalUp()
  • getCameraLocalRight()
  • getCameraLocalPos()
  • 🆕 getBodyPosition()
  • 🆕 getBodyWorldPosition()
  • 🆕 getBodyWorldForward()
  • 🆕 getBodyWorldUp()
  • 🆕 getBodyWorldRight()
  • 🆕 getBodyForward()
  • 🆕 getBodyUp()
  • 🆕 getBodyRight()

 

Database

  •  getPlayerName(pid)
  • getPlayerWorldPos(pid)
  • 🆕 getOrganizationName(oid)
  • 🆕 getOrganizationTag(oid)
  • getSchematicInfo(schematicId)
  • getPlayerById(pid)
  • getMasterPlayer()
  • getOrganization(oid)
  • getConstruct(cid)

 

 

 

Camera Data Explanation

The camera data is pretty straight forward. I made an code example and explanation before this mess, I'll just paste that here lol.

 

local player = player --> A tab which virtually represents the "player", it holds player related events and functions.



local isSeated = player.isSeated() --> Returns true or false if the player is seated or not.
local seatId = player.getSeatId() --> Returns the player seat ID if seated, otherwise nil.

local headlampState = player.getHeadlampState() --> Returns the boolean of the avatar headlamp, on or off.
player.setHeadlampState(not headlampState) --> Inverts the headlamp state.

local camView = player.getCameraView() --> Returns 0 for first-person, 1 for third-person and 2 for fixed third-person.
-- Consideration to have is that you can get into third person while using the normal avatar using an emoji.
-- Why it is useful is so you can change the HUD you intend on using depending on if you're in those seperate views and if you should listen to mouse input for UI, etc.

local camWorldUp = player.getCameraWorldUp() --> Returns the camera up vector in world coodinates.
local camWorldForward = player.getCameraWorldForward() --> Returns the camera forward vector in world coodinates.
local camWorldRight = player.getCameraWorldRight() --> Returns the camera right vector in world coodinates.

local camLocalUp = player.getCameraLocalUp() --> Returns the camera up vector in local coodinates, relative to the build grid.
local camLocalForward = player.getCameraLocalForward() --> Returns the camera forward vector in local coodinates, relative to the build grid.
local camLocalRight = player.getCameraLocalRight() --> Returns the camera right vector in local coodinates, relative to the build grid.


local camLocalPos = player.getCameraLocalPos() --> Returns the camera position in local coordinates relative to the build-grid (construct) center.
local camWorldPos = player.getCameraWorldPos() --> Returns the camera position in world coordiantes.
--<! Optionally, you could add a relative world position function which is relative to the construct center, but in world coordinates. Though, I feel it would be very niche !>--

--- Lastly,
local camHFov = player.getCameraHorizontalFov(true/false) --> Returns the horizontal fov with a boolean parameter to determine if it is returned as a radian or degree format.
local camVFov = player.getCameraVerticalFov(true/false) --> Returns the vertical fov with a boolean parameter to determine if it is returned as a radian or degree format.

 

 

Final Structure (No Formatting, mainly for glancing to see roughly the impact)

 

Core

  • getData()
  • getMaxKinematicsParametersAlongAxis(taglist,crefaxis)
  • getWorldAirFrictionAngularAcceleration()
  • getWorldAirFrictionAcceleration()
  • spawnNumberSticker(nb, x, y, z, orientation)
  • spawnArrowSticker(x, y, z, orientation)
  • deleteSticker(index)
  • moveSticker(index, x, y, z)
  • rotateSticker(index, angle_x, angle_y, angle_z)
  • getAltitude()
  •  getCurrentPlanetId()
  • getConstructWorldGravity()
  • getWorldGravity()
  • getAngularVelocity()
  • getWorldAngularVelocity()
  • getAngularAcceleration()
  • getWorldAngularAcceleraton()
  • getVelocity()
  • getWorldVelocity()
  •  getAbsoluteVelocity()
  • getAbsoluteWorldVelocity()
  • getWorldAcceleration()
  • getPvPTimer()
  • getBoardedPlayerIds()
  • getDockedConstructIds()
  • isPlayerBoarded(pid)
  • isConstructDocked(pid)
  • forceDeboard(pid)
  • forceUndock(cid)
  • getBoardedPlayerMass(pid)
  • getDockedConstructMass(cid)
  • getParent()
  • getCloseParents()
  • getClosestParents()
  • getParentPosition()
  • getParentWorldPosition()
  • getParentForward()
  • getParentUp()
  • getParentRight()
  • getParentWorldForward()
  • getParentWorldUp()
  • getParentWorldRight()
  • dock(pid)
  • undock()
  • setDockingMode(mode)
  • getDockingMode()
  • getCoreStress()
  • getMaxCoreStress()
  • getCoreStressRatio()
  • All Events

 

System

  • getActionKeyName(actionName)
  • showScreen(bool)
  • setScreen(content)
  • createWidgetPanel(label)
  • destroyWidgetPanel(panelId)
  • createWidget(panelId, type)
  • destroyWidget(widgetId)
  • createData(dataJson)
  • destroyData(dataId)
  • updateData(dataId, dataJson)
  • addDataToWidget(dataId, widgetId)
  • removeDataFromWidget(dataId, widgetId)
  • getMouseWheel()
  • getMouseDeltaX()
  • getMouseDeltaY()
  • getMousePosX()
  • getMousePosY()
  • getThrottleInputFromMouseWheel()
  • getControlDevicePitchInput()
  • getControlDeviceYawInput()
  • getControlDeviceRollInput()
  • getTime()
  • getActionUpdateDeltaTime()
  • getWaypointFromPlayerPos()
  • setWaypoint(waypointStr)
  • getScreenHeight()
  • getScreenWidth()
  • print(msg)
  • logInfo(msg)
  • logWarning(msg)
  • logError(msg)
  • All Events

 

ControlUnit

  • exit()
  • setTimer(timerTagId, period)
  • stopTimer(timerTagId)
  • getAtmosphereDensity()
  • getClosestPlanetInfluence()
  • setEngineCommand(...)
  • setEngineThrust(taglist, thrust)
  • setAxisCommandValue(axis, commandValue)
  • getAxisCommandValue(axis)
  • setupAxisCommandProperties(axis, commandType, targetSpeedRanges)
  • setupControlMasterModeProperties(controlMasterModeId, displayName)
  • getControlMasterModeId()
  • cancelCurrentControlMasterMode()
  • isAnyLandingGearExtended()
  • extendLandingGears()
  • retractLandingGears()
  • isMouseControlActivated()
  • isMouseDirectControlActivated()
  • isMouseVirtualJoystickActivated()
  • isAnyHeadlightSwitchedOn()
  • switchOnHeadlights()
  • switchOffHeadlights()
  • isRemoteControlled()
  • activateGroundEngineAltitudeStabilization(targetAltitude)
  • getSurfaceEngineAltitudeStabilization()
  • deactivateGroundEngineAltitudeStabilization()
  • computeGroundEngineAltitudeStabilizationCapabilities()
  • getThrottle()
  • setSignalIn(plug, state)
  • getSignalIn(plug)
  • All Events

 

Construct

  • getWorldOrientationForward()
  • getWorldOrientationRight()
  • getWorldOrientationUp()
  • getOrientationForward()
  • getOrientationRight()
  • getOrientationUp()
  • getWorldPos()
  • getId()
  • getName()
  • getOrientationUnitId()
  • getMass()
  • getIMass()
  • getCrossSection()
  • getLocalGravityIntensity()

 

Elements

  •  getIdList()
  • getNameById(uid)
  • getTypeById(uid)
  • getHitPointsById(uid)
  • getMaxHitPointsById(uid)
  • getMassById(uid)
  • getPositionById(uid)
  • getForwardById(uid)
  • getUpById(uid)
  • getRightById(uid)
  • getIndustryStatusById(uid)
  • getTagsById(uid)
  • getElementById(uid)

 

Player

  • getId()
  • getMass()
  • getParent()
  • getOrgIds()
  • lockView(state)
  • isViewLocked()
  • freeze(bool)
  • isFrozen()
  • getHorizontalFov(bool)
  • getVerticalFov(bool)
  • getHeadlampState()
  • setHeadlampState(bool)
  • isSeated()
  • getSeatId()
  • getCameraView()
  • getCameraWorldForward()
  • getCameraWorldUp()
  • getCameraWorldRight()
  • getCameraWorldPos()
  • getCameraLocalForward()
  • getCameraLocalUp()
  • getCameraLocalRight()
  • getCameraLocalPos()
  • getBodyPosition()
  • getBodyWorldPosition()
  • getBodyWorldForward()
  • getBodyWorldUp()
  • getBodyWorldRight()
  • getBodyForward()
  • getBodyUp()
  • getBodyRight()

 

Database

  • getPlayerName(pid)
  • getPlayerWorldPos(pid)
  • getOrganizationName(oid)
  • getOrganizationTag(oid)
  • getSchematicInfo(schematicId)
  • getPlayerById(pid)
  • getMasterPlayer()
  • getOrganization(oid)
  • getConstruct(cid)

 

 

 

Ending Notes

It has taken me literally the entire day doing this, and even then I feel like I've missed a lot because I was literally looking at the entirety of Lua.
I was planning on explaining all the changes and stuff, but my head is about to explode from doing this the entire day so not gonna. Lol.

Tbh, if they implemented even a single one of these slots, I would be happy. I don't expect most of it to change.
I would also, personally, like if these changes came out gradually, if any. I think if camera angles are added though, we must at least get the player slot, or similar global variable because of how long the variable names will end up getting.

 

Obligatory @NQ-Ligo and @NQ-Deckard, I wish you find this helpful, even if you don't add even 1% of it xD

Oh, and oops. Kinda broke the "one idea" rule... it's kinda a super idea though. Hope whoever od

Link to comment
Share on other sites

Hello @EasternGamer!

 

That was quite the read.

 

Although we do already have very similar plans on the drawing board, it is unlikely that this will happen soon as it will likely have to go hand in hand with a larger Lua change for which we simply do not have an ETA at this time. And it's also not something that can be implemented at any point as it involves some major changes that would mean refactoring and "fixing" just about every single Lua script that currently exists in the game.

 

As such, although we agree with the idea and would eventually like to do something along these lines. It is very unlikely it will be before release.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...