How to make a replacement image when you click on Gui button& - lua

I can not understand how to change the image when you press the button

To change an image label's image you must first have the explorer tab open in roblox, to do this look at the top bar on your roblox game editor. Go into view and select explorer on the left of the top bar.
Now do as I do.
Add a screenGUI into the starterGUI folder
Into the screenGUI add a frame
And into the frame add the following items
a LocalScript
a TextButton
and a ImageLabel
Inside the localscript put this script
local label = script.Parent.ImageLabel
local frame = script.Parent
frame.TextButton.MouseButton1Click:Connect(function(click)
label.Image = "rbxassetid://284402785" --change this to whatever image you want but keep the quotation marks
end)
You can change the normal asset in the image label to whatever you want.

Related

How to create a Button that works like a Tool button?

I'm trying to create a button that works exactly like when I click on rectangle Tool on Tools bar. Meaning I don't want it to create a rectangle by just pressing the button, I'm not gonna use Objectcreate() function. Instead, I want it to wait for the user to push the mouse button on chart and drag it to create a rectangle. Just like when you choose the rectangle tool and the cursor-shape changes.
I've looked the WndObj.mqh, Wnd.mqh and Rect.mqh and couldn't figure it out how does this work.
I appreciate if anyone can tell me how to do it
enter image description here
enter image description here

Lua clicking button makes it disappear

I'm a scripting newbie and I'm trying to make a button that when you click it disappears I have a local script as the child of a text button, this is the code I'm using.
local button = script.Parent
local function onButtonActivated()
print("Button activated!")
game.StarterGui.ScreenGui.TextButton.Transparency = 1
end
How do I make it so that the computer does the function when the button is clicked?
Check out the docs for TextButtons.
You simply need to connect your code to the Activated signal of the button.
button.Activated:Connect(onButtonActivated)
On a separate note, there's an issue with your function as well. You are modifying the button template that is in StarterGui, not the one that the player sees. UI elements are copied from StarterGui into each player's PlayerGui when the Player spawns.
To access the actual button you are trying to turn invisible, you can use relative paths, like how you defined the button variable, or give the full path to the button.
local button = script.Parent
local function onButtonActivated()
button.Transparency = 1
-- or
local player = game.Players.LocalPlayer
local btn = player.PlayerGui.ScreenGui.TextButton
btn.Transparency = 1
end
button.Activated:Connect(onButtonActivated)
There are a few ways to check if a button is clicked.
The main way is UIButton.Activated. It works the exact same as MouseButton1Click.
Something around the lines of:
button.Activated:Connect(onButtonActivated);
If this helped, you should accept either my answer or Kylaaa's answer.
try this
first make all the onButtonActivated
then instead of transperency use:
button.Visible = false
it works for me

Use mouse and keyboard at the same time

Is it possibile to use mouse and mouse at the same time?
I have to select a few row in windows program. You can make in by holding <> and mouse.click on window element.
Sure, it's possible. I prepared an example for you.
Open File Explorer window (for example Desktop folder) and make sure you have some files/folders there. window command will bring the window to the front.
Choose Insert/Mouse Position from the menu, click any file/folder in the File Explorer and choose "Yes" in the "Absolute position?" dialog that will be shown after you click on something on the screen.
Argument type with the value down means that the mouse button will be held pressed. Argument button with the value right means that it will be the right mouse button.
Use keyboard command to press SHIFT and add down keyword which means that the Shift button will be held pressed.
Then, "unclick" the right mouse button and "unclick" SHIFT like below by using the up keyword.
window ✱Desktop✱
mouse.click position ⟦point⟧653⫽608 relative false type down button right
keyboard ⋘SHIFT down⋙
mouse.click position ⟦point⟧653⫽608 relative false type up button right
keyboard ⋘SHIFT up⋙
You can see that the automation works if a context menu appears with more options, for example "Copy as path".
You can do similar with your windows program.

Hammerspoon: drawing a line in the title bar of a window

I am trying to draw a red line in the title bar of a focused window. For this, I created code similar to the following (it is meant to be a minimal example):
function foo()
f = hs.window.focusedWindow():frame()
line = hs.drawing.line(hs.geometry.point(f.x, f.y),hs.geometry.point(f.w,f.y))
line:setStrokeWidth(10)
line:setStrokeColor(hs.drawing.color.red)
line:show()
end
If I enter this into the Hammerspoon Console, followed by
foo()
it draws a line outside the window, not on the title bar, if the Console is placed in the right half of the display. Please see the attached screenshot. In fact, the position and length of the red line change, depending on the location of the Console window, and the desired red line can be drawn on the title bar, if the Console is in the left half of the display. I totally got confused. What is wrong with the code?
Can anyone help?
EDIT
More photos are added. Note that setStrokeWith(30) is used.
As is, the code will place the bar windows width away from the left side of the screen. The seemingly fixed position is because the window width is the same. Use:
hs.geometry.point(f.x + f.w, f.y)
To place the second point as on offset from the first.

Cursor change on mouseclick

I have a simple custom cursor code that loads a cursor from my Content folder to a Texutre2D, and then simply draws it on Draw. How can I program the image to change when I hold right click and then switch back to default when I release right click?
You have to load both your textures in two Texture2D variables, then simply check in your Update the state of the right button.
if (mouse.RightButton == ButtonState.Pressed)
cursorTexture = pressedTexture;
else
cursorTexture = releasedTexture;
Of course, cursorTexture is the one you have to draw.

Resources