App Inventor: Making one button change more than one variable - variables

This is about App Inventor 2, i had a button which could change depending on what image sprite had been activated. However, i deleted this button accidentally and lost all of the blocks assigned to it. I cannot remember how to do it. Could someone please tell me how I create a button that can change the value of more than one variable depending on what image sprite has been activated?

You can set specific counter for specific sprite. Just set the counter when the sprite is touched. Then, when the button is clicked, you need to use if and else function to check for what sprite is touched. Below is an example of code, yet it is not complete:

Related

how to constantly update a variable with a touchscreen dragging input event position

My game require constant update of a var with a drag gesture postion as my finger is moving on the touch sreen please help as im pretty new to programming.
By default, when you touch the screen, Godot interprets that as a mouse motion, so to get the position whenever the user has their finger on the screen you can do:
func _input(event):
if event is InputEventMouseMotion:
gesturePostion = event.position
Now you have the variable 'gesturePostion' which stores the position of your finger on the screen as a Vector2. Just make sure you've defined 'gesturePostion' as a global variable (you can do that by defining the variable outside any function).

What secret things are happening to my NSButtonCell?

I'm writing an OS X app (target 10.10, Xcode 6.1) and I'm really confused by my custom NSButtonCell subclass. It seems like there are things going on here that shouldn't. I'm new to OS X programming, so I'm asking if anyone has insight into the inner workings of NSButtonCell.
First, what seems to be working?
I can set the button's image and title. The image appears normally.
The storyboard sets up the button to be Style: Textured and Type: Momentary Change. It's not Bordered, not Transparent, and doesn't allow Mixed State.
List of complaints:
I override -drawTitle:withFrame:inView: to draw the title in a custom color depending on the cell's highlighted. This color should be #cccccc when the cell is not highlighted, but it's actually #d6d6d6.
The button has both image and alternate image. The image that's drawn is never the alternate image, so I override -drawImage:withFrame:inView: to pick the correct image for cell's highlighted. This appears to work, but what the heck, NSButtonCell? How is on/off state different from highlighted? I've tried many of the Type options and none seem to change the fact that pressing the button will momentarily change highlighted, and toggle state.
Speaking of momentarily changing highlighted, it appears that its duration is about as short as possible, so I had to implement a sort of "debouncer" to prevent -drawWithFrame:inView: from being called more frequently than a specified threshold.
My button cell also has properties myBackgroundColor and myAlternateBackgroundColor. I'm not using backgroundColor because I need to be able to draw a custom background shape (filled rect, filled circle, etc). The alternate background color is used when highlighted. The problem here is that the alternate background color should be #93edbf but appears to be #a1eecb! In order to get it to look like #93edbf, I need to set the color to #84ecb2.
So far this has all been about one particular instance of this button cell. But in another instance, the alternate background isn't drawing at all! I've read through the storyboard code and the buttons are as identical as they can be. My view controller code likewise updates both button cells' properties at the same time. Why would one button behave differently from another?
I want the button to highlight on mouse down instead of "momentarily" after mouse up. I haven't yet implemented this in my custom cell. Man, NSButtonCell is really lacking some things. How does something like that happen? Don't the OS X and iOS teams ever talk to each other?
What could it be?
I've already verified that the cell's controlTint is set to NSClearControlTint. I've checked for background filters, compositing filters and content filters on the off chance they had anything to do with this.
I know Apple really wants us to use their native look and feel for UI elements, but I never thought they'd go so far as to force the use of some highlight tint.

UIButton in UICollectionViewCell resets its label text to what is set using storyboards from the runtime text being set on every click

I am working on an app having a collection view with Collection view cells having 4 buttons to invoke different actions.Each links to a different IBAction. I have read multiple threads across the board and had decided to use storyboards rather than go at it programmatically since 'this could be the way forward'. So while setting up the buttons, I had set default label text to Button 1, Button 2 etc. In the code, while giving cell for index path, I am changing the button text to something programmatically. When the application is run the cells render fine with dequeueing, and the text being set programmatically is set correctly. However, when I click any of the buttons, the action is called, but the label text of the button resets to what was set using storyboards.
I have tried everything to retain the text label copy to what it should be. But to no avail. When I again dequeue the cell by scrolling across the collection view and the view gets redrawn, the button again gets the correct text.
Can anyone please shed some light on why the button text for a button placed in a collection cell will reset its text and will not allow it to be set unless the view is redrawn.. Also any ideas on how to fix this.
Thanks a ton
deej nailed it --
I had the same problem but was doing something stupid:
self.btnProperty.titleLabel.text = #"button title";
rather than:
[self.btnProperty setTitle:#"button title" forState:UIControlStateNormal];
Use the latter.

How do I trigger an event when a UIImageView reaches a certain location?

I have a UIImageView that moves around the screen, and I am trying to trigger a method when it is within a certain distance of another UIImageView, also moving. There is not necessarily any specific time I want to check, I want to know anytime it is within that distance. Help!
EDIT: I have multiple objects(the enemies) moving down the screen while the player is at the bottom of the screen. When the user taps the screen, it "shoots"(a new projectile object is created and the animation to move it up the screen is started). I am trying to detect when the "projectiles" hit the "enemies" and triggering an event(i.e. killing the enemy). I have no idea where to put the code to do this, or even what to do. Do I want to use the Notification System, or do I want to calculate if the projectile will hit the enemy as soon as it is fired?
You probably want to use Key-Value Observing. Here's an example.

button tapping speed, two buttons, to increase points

im trying to make a simple game on cocos2d box2d, its basically got two buttons and a label with the points. the points increment by +1 every second.
what im trying to do is, the player taps both buttons sequentially so it has to be 'button1' then 'button2' then 'button1' then 'button2' .....
if this is done properly then the points increment speed should increase, and the faster the buttons are tapped sequentially, the faster the points should increase.
how can i go about doing this? any ideas?
The idea is simple: you only increment the score when the other button was the last pressed button. That's it. So:
Keep track of the last pressed button.
If button1 is pressed, and button2 was not the last pressed button, don't do anything, otherwise increment the score by some amount.
Do the same kind of check for button2.
Does this make sense?