Hi, Jeff and I have been trying to figure out all day how to create a object-based volume slider (and other sliders as well) in our settings menu, with no luck. We are new to this engine and lua, and I was hoping that someone could point us in the right direction.
We saw that the suggestion a couple years ago was to use a single frame animation loop to do this, but we thought that for our purposes, object based would be better. However, if the animation loop would be better, we are open to suggestions.
Our basic thought process was that we would add the slider thumb (handle, hereafter referred to as H-Thumb as that is how it is named in the script) to the scene as an object, create a polygon around it, and then attach the following script to it. What I am trying to do with the script is to find the cursor x value, and match the H-Thumb x value to it within the xMin and xMax constraints, which would be the edges of the slider area.
cursorPos = getCursorPos()
xMin = 755
xMax = 1326
hThumb = getObject("Objects[H-Thumb]"):getPoint(VObjectPosition)
function onMouseEvent(eventType, mousePosition)
if eventType == eEvtMouseLeftButtonHolding then
-- Dragging function
if cursorPos.x < xMin then
hThumb:setValue(x, xMin)
elseif cursorPos.x > xMax
hThumb:setValue(x, xMax)
else
hThumb:setValue(x, cursorPos.x)
end
getObject("Objects[H-Thumb]"):setPoint(hThumb)
print("Cursor Position is" .. cursorPos.x)
print("H-Thumb Position is" .. hThumb.x)
end
end
registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseLeftButtonHolding})
Is this the right way to go about it? Or is there a different/better way? The syntax is really confusing to me and there is very limited documentation, so I am having trouble determining when and where I should use the code I find.
Thanks,
Charlie