I'm creating a little sound that plays when your mouse hovers over the button "White team" but nothing really happens. I'm using the MouseEnter event - user-interface

I have been trying to create a sound every time your mouse leaves and enters this button. The code doesn't really work. I have tried this on a local script and a normal script:
script.Parent.MouseEnter:Connect(function()
local sound = script.Parent.Parent.hit
sound:Play()
end)
script.Parent.MouseEnter:Connect(function()
local soundTwo = script.Parent.Parent.hitS
soundTwo:Play()
end)
```[enter image description here][1]
[1]: https://i.stack.imgur.com/5niz4.png -- The explorer of the game (I used script and local script btw and none of them changed anything, but i do think local script would work better for a gui)

You can try adding the following lines at the top of your code.
if not sound.IsLoaded then sound.Loaded:Wait() end
if not soundTwo.IsLoaded then soundTwo.Loaded:Wait() end
Also, both of your functions are for MouseEnter. Try changing one to MouseLeave.

Related

How can I have a button trigger a function to move the mouse cursor on a timer in C#/visual studio?

I'm building an automatic timer system as a fun silly project for some office chums. It's end user goal is to allow end users to be away from keyboard while still simulating activity to prevent timed applications from changing their statuses to away.
I have the front end of a windows form with two buttons. ON and OFF. When I press on, I want it to begin moving the mouse in 1 minute intervals for a moment. (or click maybe.) and when I select off it stops the action.
I've never really coded much before (I've done basic python stuff so I know what an if statement is, a function, how to declare a variable etc but I've never done anything with a GUI or in c# so this is all new.)
Lastly, I would want to save/export it as an exe for distribution for slackers I mean end users to run and use.
Thanks so much for the help!
Looks like someone is trying to hack their way out to keep their PC active when away from desk :D
//programmatically move the mouse example
PointConverter pc = new PointConverter();
Point pt = new Point();
pt = (Point)pc.ConvertFromString("0, 768");
Cursor.Position = pt;
Ref

Ruby: how to renew the path of an image after image has been changed?

I am trying to build a GUI with ruby Shoes to select a background image for my desktop. As I am struggling with a particular part of my idea I am going to describe just the problem part, the rest works fine.
Here's the code of my ruby Shoes app:
Shoes.app :title => "Images!" do
stack do
#img1 = image "desktop_pic", :width => 200, :height => 100
button "Change image", :margin => 25 do
#img1.path = "/home/njutik/preview_desktop_pic"
end
end
end
Here's what the result looks like when I start my Shoes app:
result_at_beginning
In the background there is a different ruby script running which generates a new background-image and stores it as preview_desktop_pic.
So when I click the Change image-button, the path of #img1 gets adjusted and I see the new image:
result_after_clicking_change_button
That's fine so far. My problem is, that nothing happens when I click the Change image-button again. Of course in the meantime there is already a new image preview_desktop_pic so the code line
#img1.path = "/home/njutik/preview_destkop_pic"
which is executed each time I press the Change image-button should show me a new picture but nothing happens. Even when I delete the preview_desktop_pic from the folder and then press the Change image-button there is still no change at all and all I see is the same picture shown after clicking the Change image-button for the first time.
So my question is: what am I doing wrong and how can I make the Shoes app show the current preview_desktop_pic every time I press the Change image-button?
Any hints would be really great!
Update: After the comment of 7stud I tried to define a singleton method for the button. Like this:
#change_image = button "Change image"
def #change_image.click
#img1.path = "/home/njutik/preview_login_background"
end
#change_image.click
But that did not help - nothing changed.
Then I tried this:
def #img1.reload
#img1.path = "/home/njutik/preview_login_background"
end
button "Change image" do
#img1.reload
end
But this also did not help. I thought that by defining singleton methods I would delete the cache memory.
Any further hints would be really helpful.
I don't think you are doing anything wrong. I think that what you are seeing has to do with image caching, which Shoes uses for efficiency. If ten windows all use the same image, Shoes does not fetch the file from disk (or download the file from the web) for each window. Instead, Shoes caches the image used in the first window, and when the other windows use the same path for the Image, Shoes retrieves the image from the cache. As a result, if the path for your Image doesn't change, it looks like Shoes uses the cached image. It would be nice if an Image in Shoes had a reload() method, which would force Shoes to ignore the cache and go get the image again.
In your app, the first button click works because the Image's path changes from "/desktop_pic" to "/home/njutik/preview_desktop_pic". Subsequent clicks do not change the Image's path.
To change the image, the new image must have a different name than the previous one. I do not know why but it works for me then.

Why isn't my localscript working?

I am basically trying to script a GUI control panel that allows users to accelerate the train with a power lever (in the GUI) and a reverser (Forward, Neutral, Reverse)
I have made two scripts. One is a localscript, the other being a regular script. The regular script enables the GUI on a player's screen when the player sits in the seat. The localscript is what makes the GUI function.
I've scripted the entire thing but only the regular script seems to function, The localscript does not seem to function as it is scripted to. The GUI appears on the screen but when pressed it does nothing.
Here are the contents of the localscript
http://pastebin.com/raw/XnT2Bi2X
Here's are all the objects in the Workspace that is mentioned and relevant to the script:
https://s31.postimg.org/4hd2up2ij/Screen_Shot_2016_06_24_at_11_15_21_AM.png
What are the errors in the localscript that is not allowing the GUI to function as its scripted to?
(I apologize for the long script and thank you for your help in advanced)
Note: The codes are Lua (which are used on the ROBLOX Studio Platform)
First off, thanks for writing out a clear and concise question. Most of the questions under this tag are all over the place :).
I would verify that you LocalScript instance is being properly initialized inside of the Player instance that is sitting down. Looking over your LocalScript's code, I don't see any errors that would cause the GUI not to function (if the LocalScript is being initialized properly), which leads me to believe the LocalScript isn't even running. If you are loading the LocalScript into the player on spawn (so, putting it into the PlayerScripts folder), there's your problem. This would cause the GUI to not be set up properly, as it hasn't been inserted into the players PlayerGui instance yet, so the LocalScript won't be able to hook up the MouseButton1Click events or anything of that sort.
So, make sure that the LocalScript starts running once the player sits in the seat (use the regular Script that displays the GUI to also move a copy of the LocalScript into the player). This will (hopefully) initialize the LocalScript properly, and allow it to hook into the GUI.
If this doesn't work, check your output window for any blatant errors, and post em here.
Cheers!
-widoreu

vb.net : change windows "top" of the screen

I have an application (menu bar) that, when running, puts itself at the top of my screen and everything else that loads, automatically knows to load below that menu bar. Its like the program established a new "top" of the screen and that top starts right below the menu bar. I want to duplicate this functionality in vb.net. Does anyone know how to accomplish this?
Basically, I'm looking for something to tell windows the top of the screen starts below my program. I hope that makes sense.
Thanks.
Check out the following project by Arik Poznanski
http://www.codeproject.com/Articles/3728/C-does-Shell-Part-3
Take this code, compile, and add it to your project as a reference. Then in the form load
Me.Edge = AppBarEdges.Top 'sets the form to dock at the top of the screen
This sets it to the top of the screen with everything else below.

GTK - Don't highlight buttons on select / hover

I'm trying to write a kiosk GUI in ruby/gtk on ubuntu. I'm pretty fluent in ruby, but new to writing GUIs and not great with linux.
I'm using a touch screen, and am using our own images for buttons, e.g.
button_image = Gtk::Image.new(Gdk::Pixbuff.new "images/button_image.png")
#button = Gtk::Button.new
#button.add(button_image)
#button.set_relief(Gtk::RELIEF_NONE)
My issue is that when the buttons are pressed or remain selected (or hovered over, although this is less relevant with a touch screen), gtk shows fat, square borders around them. Obviously it's applying gtk's prelight / selected / active lighting to the buttons. I've tried changing the button properties in various ways, and also tryied hacking apart my theme, and while I can modify how the highlighting looks, I can't seem to completely get rid of it. Changing the color of the highlight via my theme is easy, but if I remove my setting there's still a default I can't get rid of.
Does anyone know if there's a way to stop it, or possibly make it transparent? Thanks in advance!
Sounds like you want to use exactly your image for the whole button, instead of putting an image inside the normal GtkButton - but still use all the normal behavior of the button.
The easiest way to do this is to just override the drawing. If you are on gtk2, connect to the "expose-event" signal, do your drawing there, and return true so that the default handler doesn't get run. If you are on gtk3, connect to the "draw" signal and do the same.
I tried meddling with the drawing as Federico suggested, but found that the most direct way to address this was instead to use an event box rather than a button. Event boxes accept clicks just like buttons, but don't respond to selecting, hovering, etc. In ruby, the code looks like this:
image = Gtk::Image.new("myfile.png")
event_box = Gtk::EventBox.new.add(image)
event_box.visible_window = false
event_box.signal_connect("button_press_event") do
puts "Clicked."
end
Most of this is exactly like a button; the *visible_window* method, obviously, keeps the event box from being visible under the button image.

Resources