I created a sliding interface (Inventory in this case) script that I thought I would share as yet another way to do the deed. It uses an array of functions to act as a Finite State Machine.
The bolded values in the script (p.y<=640 and p.y>=696) depend on the size of your inventory interface graphic.
My Interface has an Absolute displacement and a position of : 191,
696. The 696 (y value) is what will be changing in order to slide the inventory.
--[[
********************************************************************************
INVENTORY
********************************************************************************
]]--
local inventory_States = {[1] = function () end, -- Holding state
[2] = function () -- RaisingState
local inventory = getObject("Interfaces[inventory]")
local p = inventory:getPoint(VInterfaceOffset)
if <b>p.y<=640</b> then
getObject("Values[inventory_state]"):setValue(VValueInt, 1)
getObject("Conditions[inventory_lowered]"):setValue(VConditionValue, true)
else
p.y= p.y-2
inventory:setValue(VInterfaceOffset,p)
end
end,
[3] = function () -- Lowering State
local inventory = getObject("Interfaces[inventory]")
local p = inventory:getPoint(VInterfaceOffset)
if <b>p.y>=696</b> then
getObject("Values[inventory_state]"):setValue(VValueInt, 1)
getObject("Conditions[inventory_lowered]"):setValue(VConditionValue, false)
else
p.y= p.y+2
inventory:setValue(VInterfaceOffset,p)
end
end
}
--[[
********************************************************************************
HANDLERS
********************************************************************************
]]--
function onMainLoop()
-- Update Inventory Interface
local inventory_state = getObject("Values[inventory_state]"):getInt(VValueInt)
inventory_States[inventory_state]()
end
registerEventHandler("mainLoop", "onMainLoop")
In the Inventory interface, I created a Value called:
inventory_state with a default value of 1. This starts the inventory in the Holding State. And a Condition called
inventory_lowered is set to true.
A button was added to the inventory interface (in my game it is a tab at the top of the inventory interface) where I wanted the mouse cursor to hover over and cause the inventory to raise using a Cursor Enters Button Area action. In that action, I set the value of inventory_state to 2 putting the inventory in the Raising state.
An Action on Leaving the interface (under Properties in V5), sets the inventory_state to 3 putting the inventory in the Lowering State.
The script will stop moving the inventory and enter into a Holding State when the position has been reached.
For added control, I created a Key Action (E [released]) in the game settings that toggles the inventory state between raising and lowering using the inventory_lowered condition to determine which state to switch to. This allows you to interupt the lowering or raising of the inventory and seamlessly switch states back and forth.
This may not be the best way to do a sliding inventory but I hadn't seen this approach used before so I thought I would share. If you are interested in a video tutorial on how I did this, let me know.
Thanks.