function sign(x) return x>0 and 1 or x<0 and -1 or 0 end function…
- User
function sign(x) return x>0 and 1 or x<0 and -1 or 0 end
function adjustCamSlot(mouseWheelDelta, isShiftDown, isCtrlDown) local step = mouseWheelDelta
codeif isShiftDown then step = step * 3 -- Увеличение шага при удержании Shift elseif isCtrlDown then step = sign(mouseWheelDelta) end print(mouseWheelDelta) print(step) cam_slot = cam_slot + step if cam_slot < 1 then cam_slot = 1 endend
максимально оптимизируй и сократи код, сделай более нейтральными названия переменных привязанных к шифту и ктрлу, потому что модификаторы могут быть перебинжены
- Assistant
To optimize and simplify the code while making variable names more neutral, you can apply the following changes:
luafunction sign(x) return x > 0 and 1 or x < 0 and -1 or 0 end function adjustSlot(mouseDelta, fastModifier, preciseModifier) local step = fastModifier and mouseDelta * 3 or preciseModifier and sign(mouseDelta) or mouseDelta slot = math.max(1, slot + step) endKey Changes:
-
Neutral Variable Names: Changed
isShiftDowntofastModifierandisCtrlDowntopreciseModifierto reflect their roles without specific key binding. -
Single Line Step Calculation: Combined the
if-elseifconditionals into a single line using logical operators to determine thestepvalue.
-