TextButton not opening Frame - lua

So I have a simple text button inside of a ScreenGui with the following lua code.
local Button = script.Parent
local Frame = script.Parent.Parent.Frame
function onClick()
if Frame.Visible == false then
Frame.Visible = true
elseif Frame.Visible == true then
Frame.Visible = false
end
end
Button.MouseButton1Click:Connect(onClick)
However, when I click on the button, the frame does not show up.
The frame is set to not be visible by default.
The button is set to active, visible and selectable.

Try with a clean script changing the Frame to visible. To check if your syntax is correct. I.e.:
local Frame = script.Parent.Parent.Frame
Frame.Visible = true
If it still doesn't work, try removing the elseif. I've had issues with scripts before just not liking the elseif command. You can just put else and it will do exactly the same job.

If you add in print("Testing") right after the function starts:
function onClick()
print("Testing")
if Frame.Visible == false then
and then run the code to make sure your onClick() function is actually being called.
If the code it called it'll print "Testing" and if it doesn't print then you know your code was just never run.

I'm a bit stupid. Upon posting this question, I attempted to do some more reaserach. I found out that it might be the type of script causing it, and it was. You need to use a localscript for things like these.
Thanks anyways!

Just as a note, when you're doing logic like:
if button.Visible == true then button.Visible = false
You can simplify the code by writing
button.Visible = not button.Visible
I would answer the rest of the question, but you've already accepted one!

Related

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

ToggleButton on_state programmatically?

I'm making ToggleButtons programmatically and I want to set the on_state method, but it doesn't seem to work:
tbutton = uix.togglebutton.ToggleButton(multiline=True,markup=True,text=text,group="g",size_hint=(1,None))
tbutton.bind(on_state=self.my_function)
def my_function(self,*args):
print "TEST"
If I press the button nothing seems to work.
You should bind state - not on_state ...
tbutton.bind(state=self.my_function)
That it :)

How to change the visibility of a TextField (native library), i.e. make it invisible, in Corona SDK

Is it possible to make a TextField (for the Corona SDK native library) invisible? If so, then how? The isVisible property does not seem to work.
For example, if I create a TextField instance like this:
local textIngrediente1 = native.newTextField(...)
when I try to make it invisible by setting the isVisible property like so:
textIngredient1.isVisible = false
it has no effect on the visibility of the TextField.
native.newTextField() does honor the .isVisible property. I just tested it. You likely have an error if you copy and pasted your code:
--local textIngrediente1 = native.newTextField(...)
-- textIngredient1.isVisible = false
In one you use textIngrediente1
In the other you use textIngredient1 (no extra e)
You can't use the isVisible, and alpha properties except for display objects..
But you can set your textField off the screen and then change the x,y coordinates when you need to show the textField..
local text= native.newTextField( ... )
text.x = -100
text.y = -100
then when you need to use or show the textField object
text.x = 100
text.y = 100
I think this will do the trick
According to the Corona documentation, TextField objects inherit properties from NativeDisplayObjects which inherit properties from DisplayObjects, including the isVisible property, so (as long as there are no typos ;-) ) this will control the visibility of the TextField.

Hidden buttons Capybara

I am trying to test a hidden button in capybara but so far have not been able to get it to work without the following error.
undefined method `click_on' for [#<Capybara::Element tag="button">]
Could someone possibly suggest the correct syntax to do so.
The call is below:
When(/^I tap on the play button$/) do
expect(page).to have_selector('.playback', visible: false)
page.all('.playback').click_link
Ok so going from the comments/answers. Here is what I would do:
Unhide the button.
Make the spec pass. #tridadc 's answer should work.
Mark the test as pending/TODO
Put the button back to hidden.
When the button is ready and visible, change the test from pending to active.
If your button is hidden, I think you need to do this:
find(".playback", visible: false).click
You can also try
Capybara.ignore_hidden_elements = false
find(".playback").click
Capybara.ignore_hidden_elements = true

Corona Sdk: storyboard API and object alpha (opacity)

i am having troubles changing an object alpha in a storyboard corona application.
When the page is loaded, the object has a default alpha of 0 (it is invisible).
Then, by clicking on a button, his alpha is set to 1 (it becomes visible).
If i leave the page, move to another storyboard page, and then get back, the object is still visible, even though i set his alpha back to 0 again with this code both in the function that gets me back to other pages:
local function gotoHomefun()
if objectname then
objectname.alpha = 0
end
storyboard.gotoScene( "home", "crossFade", 400 )
return true
end
and in the destroyScene event:
function scene:destroyScene( event )
local group = self.view
if objectname then
objectname.alpha = 0
objectname :removeSelf()
objectname = nil
end
display.remove( group )
group = nil
end
I really don't know if im doing something wrong, or i found a bug.
Any help would be really appreciated! Thanks!
Do you call the removeScene or purgeScene from other scene??
if not then your scene won't be removed unless it is a low memory situation. Try setting executing the current code in the exitScene event which gets called whenever the view is changed to new scene.
Refer to this doc for the event specific detail -
Storyboard Lifecycle Events

Resources