IsCursorShowing: Difference between revisions
(Adding new and more lifelike examples, clarifying the grammar, simplifying the page for beginners.) |
Fernando187 (talk | contribs) m (nevermind) Tag: Manual revert |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
{{Server client function}} | {{Server client function}} | ||
{{Note|This function only handles the cursor state set by the [[showCursor]] function, ignoring it if the console, chatbox, or menu is open.}} | {{Note|This function only handles the cursor state set by the [[showCursor]] function, ignoring it if the console, chatbox, or menu is open.}} | ||
{{Note|If you use this function on the server side, keep in mind that it only detects the [[showCursor]] function executed on the server side and does not detect the function executed on the client side.}} | {{Note|If you use this function on the server-side, keep in mind that it only detects the [[showCursor]] function executed on the server-side and does not detect the function executed on the client-side.}} | ||
==Purpose== | ==Purpose== | ||
Line 20: | Line 20: | ||
bool isCursorShowing ( ) | bool isCursorShowing ( ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===No Arguments=== | |||
On the client-side, this function doesn't require any arguments because it gets the cursor state of the [[localPlayer]]. | |||
</section> | </section> | ||
Latest revision as of 15:09, 6 November 2024
Purpose
This function determines the state of a player's cursor.
Syntax
bool isCursorShowing ( player playerElement )
Required Arguments
- playerElement: The player from whom we want to retrieve the cursor state.
bool isCursorShowing ( )
No Arguments
On the client-side, this function doesn't require any arguments because it gets the cursor state of the localPlayer.
Returns
Returns true if the player's cursor is visible, and false if it is not.
Example
This example creates a function to set the state of the player's cursor using the showCursor function.
function toggleCursor(playerElement) if playerElement and isElement(playerElement) then -- Check whether the given element exists local cursorState = isCursorShowing(playerElement) -- Retrieve the state of the player's cursor local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state showCursor(playerElement, cursorStateOpposite) -- Setting the new cursor state end end
This example creates a function that gets the state of the player's cursor and outputs it to the chatbox using the outputChatBox function.
function outputCursor(playerElement) if playerElement and isElement(playerElement) then -- Check whether the given element exists local cursorState = isCursorShowing(playerElement) -- Retrieve the state of the player's cursor local cursorStateText = cursorState and "visible" or "hidden" -- Calculate the context from the boolean variable. outputChatBox("Your cursor is " .. cursorStateText .. ".", playerElement) -- Output the text in the chatbox according to the cursor state. end end
This example creates a function to set the state of the player's cursor using the showCursor function.
function toggleCursor() local cursorState = isCursorShowing() -- Retrieve the state of the player's cursor local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state showCursor(cursorStateOpposite) -- Setting the new cursor state end
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
function toggleCursor() showCursor(not isCursorShowing()) end
This example creates a function that allows the player to change the state of the cursor using the showCursor and bindKey functions.
function toggleCursor() local cursorState = isCursorShowing() -- Retrieve the state of the player's cursor local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state showCursor(cursorStateOpposite) -- Setting the new cursor state end bindKey("m", "down", toggleCursor) -- Assigning our toggleCursor function to the 'm' key press.
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
bindKey("m", "down", function() showCursor(not isCursorShowing()) end )