Stop a controlling object to move in Corona sdk - coronasdk

I have 2 controls in a space shooter-like game, which are left and right.
The ship does move left and right and when the ship moves to the left of x=40 (far left), it will revert back to x=40 and disable the "move left" function temporarily, BUT my problem is that whenever I move to the far left or the far right of the screen, from the middle of the screen, the ship moves further than x=40(about x=35) then moves back and continues this until I let go of the button.
How can I make it so that when I move the ship to the far left, it stops completely and only lets me to move right?
Here is my code:
function left:touch()
if(car01.x>40 and car01.x<280) then
motionx=-speed;
return false
end
end
left:addEventListener("touch",left)
function left:touch2()
motionx=0;
end
local function movecar(event)
if(car01.x>40 and car01.x<280) then
car01.x=car01.x+motionx
return false
elseif(car01.x==40) then
car01.angularVelocity=0
left:addEventListener("touch2",left)
car01.x=car01.x+motionx
elseif(car01.x<40) then
car01.x=40
end
end
Runtime:addEventListener("enterFrame",movecar)
local function stop(event)
if (event.phase=="ended") then
motionx=0;
return true
end
end
Runtime:addEventListener("touch",stop)

Is is is what you are looking for..?
Create a background(bg), left and right controls(left and right resp.). Then:
local function moveLeft()
if(car01.x>40)then
car01.x = car01.x - 40
end
end
left:addEventListener("tap",moveLeft)
local function moveRight()
if(car01.x<280)then
car01.x = car01.x + 40
end
end
right:addEventListener("tap",moveRight)
Keeo coding....... :)

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

Is it possible to keep the mouse button 2,3,4,5 pressed without holding down the button?

I would like to make a Logitech Lua script where it continuously holds down the mouse buttons for example mouse button 5 without holding it, just have the mouse button turned on until i release it by clicking it once. if anyone could help, it'd be much appreciated.
Open https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
Read through the table of contents or search "press"
Find page 18: PressMouseButton
PressMouseButton The PressMouseButton() function is used to simulate a mouse button press. NOTE: Calling IsMouseButtonPressed
immediately afterwards, will likely return the previous state. It will
take a few milliseconds for the operation to complete.
PressMouseButton( button )
Step #1
Set script.
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg >= 2 and arg <= 5 then
local btn = ({1, 3, 2, 4, 5})[arg]
if IsMouseButtonPressed(btn) then
ReleaseMouseButton(btn)
else
PressMouseButton(btn)
end
elseif event == "PROFILE_DEACTIVATED" then
for btn = 2, 5 do
if IsMouseButtonPressed(btn) then
ReleaseMouseButton(btn)
end
end
end
end
Step #2
Unbind default actions from buttons 2-5 in LGS/GHUB.

Button Keeps Vanishing

My App Basically has a start screen where the user enters how many exercise reps they want to do. I use this as my max variable, and then I have a button which activates a counter mechanism which adds up to max value. When it equals max value, the UI resets and I am meant to get back to Screen 1.
I have been working this problem for over an hour and I can't figure out why my button doesn't reappear when the clicker value = user input(max value).
I have coded it to do so in
ButtonScreen1.hidden = false
UserInputScreen1.hidden = false
LabelScreen1.hidden = false
But the Button won't reappear. But it appears at the start, so it's not a view controller issue to my knowledge.
Images (Top One Is Without Button which Should be Present at the End of the Application) (Bottom One is What It Looks like as it Starts which I am trying to replicate at the End)
For Full Code

Unable to swipe across on iOS simulator

I am having issues trying to use the swipe functionality on the ios app. Currently using Appium v1.3.5 in conjuction with Cucumber/RubyMine v7.04.
I have tried using a range of x, y co-ordinates. However I am still only able to swipe half way and unable to click on the element on screen.
Has anyone come across this issue before?
def self.hide_thread
action = Appium::TouchAction.new
action.press(x: 360, y: 70).move_to(x: 0, y: 70).release
sleep(1)
find_element(:xpath,"//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/UIAButton[1]").click
end
Please error message:
elementId 18 could not be tapped(Selenium::WebDriver::Error::UnknownError)
./features/step_definitions/hidden_threads.rb:82:in `hide_thread'
./features/step_definitions/hidden_threads.rb:102:in `/^Hide the thread$/'
features/hidden_threads.feature:8:in `And Hide the thread'
Then Thread will be hidden # features/step_definitions/hidden_threads.rb:105
for java I found this solution! you try for ruby to pass deltax and deltay instead of end point coordinates and update this answer if needed.
Check This answer
swipe(100,200,10,20,300) => swipe starting from Point (100,200) and end at Point (110,220) which means finger would move Right lower side fro current position
swipe(100,200,-10,20,300) => swipe starting from Point (100,200) and end at Point (90,220) which means finger would move Left lower side from current position
swipe(100,200,10,-20,300)=> swipe starting from Point (100,200) and end at Point (110,180) which means finger would move Right Upper side from current position
swipe(100,200,-10,-20,300)=> swipe starting from Point (100,200) and end at Point (90,180) which means finger would move Left Upper side from current position

Actionscript 3 simple image slider

Thanks in advance for any help. I'm a Noob at actionscript 3, and what I'm trying to do is make a image slider. Basically, there would be a movieClip, acting as a container, and a left and right button. when I click left button, the Container slides left and vise versa.
Now I kind of got things working, the problem is when I press say the left button, the Container moves left,and keeps moving left as many times as I click the left button. But I want it to stop, or loop, at the end of the Container, and I'm not quiet sure how to do this.
I searched all over the net but didn't find anything useful, most of what I found is really complex or heavily reliant on external libraries, and I don't want to just copy and paste code snippets that I don't understand. Can anyone please give alittle insight on how this can be accomplished in actionscript 3.
here is a copy of my code so far
Thanks
-Noob
//leftButton and rightButton are movieClips on the stage
leftButton.addEventListener(MouseEvent.MOUSE_DOWN, moveLeft);
rightButton.addEventListener(MouseEvent.MOUSE_DOWN, moveRight);
//NOTE: thumbContainer is a movieClip on the stage
//Make the mask;
var myMask:MovieClip = new MovieClip();
this.addChild(myMask);
myMask.graphics.beginFill(0x000000);
myMask.graphics.drawRect(6,138,534,144);
myMask.graphics.endFill();
thumbContainer.mask = myMask;
//thumbContainer moves left on button press
function moveLeft(evt:Event):void
{
thumbContainer.x -= myMask.width;
}
//thumbContainer moves right on button press
function moveRight(evt:Event):void
{
thumbContainer.x += myMask.width;
}
Now I kind of got things working, the problem is when I press say the left button, the
Container moves left,and keeps moving left as many times as I click the left button. But I
want it to stop, or loop, at the end of the Container, and I'm not quiet sure how to do
this.
What you have mentioned here is not very clear. From what I understand, you have a container myMask which slides off your parent container thumbContainer when you repeatedly press the left (or right) button.
Assuming this is the problem, allow the myMask container to move left or right, but check each time with the screen resolution width (Maybe have a if statement or something). Hence, move left/right only when the condition is satisfied(there is space for moving left/right)
Hope that helps!

Resources