Creating a button in scratch - mit-scratch

I am trying to make a multiple choice quiz in Scratch, but I am having trouble with coding the buttons. I have created the buttons, but I do not know how to get them so the users can click on them to choose answers. How can I get them to work?
Here is a screenshot of the code and the actual quiz.

You're currently using the TOUCHING SPRITE block. This block is for when the sprite itself is touching another sprite.
If you go into the code for each button, you'll find a hat block: WHEN THIS SPRITE CLICKED.
You can take this block, and have it set a variable with which block was clicked.
So in each of the button sprites you'd have something like this:
WHEN THIS SPRITE CLICKED
SET (ANSWERSELECTED) TO [A]
Then in your person sprite, where you currently have TOUCHING SPRITE 2 etc, you can have a variable that contains the answer selected. You'll want to clear the variable each time a new question is asked, e.g., set it to blank.
So you'll end up with something like this:
That's probably the simplest way.
IIRC, if you don't want to put scripts in the button sprites, you can also hack something together with something like IF MOUSE DOWN AND MOUSE X = (here you'd need to hack together the location of the button, probably using a AND block and using the X location of the button on both ends (which you can find using the mouse, under the player shows the current X and Y positions of the mouse)) AND MOUSE Y = (same as with X) SAY CORRECT FOR 3 SECS, but that's more difficult.
(That will require that the mouse be on the exact center of the button, though, so if you want to do it that way you'll probably want to account for being slightly off the center.)

Related

Delete button for object - MRTK

I have a question regarding Unity and mrtk. I need to create an object, which can be deleted via button push. This button should be attached to the object. Now there is the app bar which can be attached to the object and which is very convenient because the buttons are only displayed on the side of the object you currently look at. However the app bar does not seem to work properly with the new bounding box and after deactivating the adjust button on it. So my question basically is, how do i make a button which is attached to the object, hovers on it and is only displayed on the side of the object i am currently looking at? The script of the app bar is very poorly commented, so i cannot figure out which part is responsible for making the button appear on the correct side and correspondingly how to write a script displaying the delete button only on the correct side (following the direction i am currently looking at).
To solve this problem you need a free Canvas that attaches to your object. This Canvas should be adjusted to the dimensions of the object and always look at the camera. To do this, first create a canvas and set RenderMode to World Space, Remember that you have entered the Event camera reference.:
After completing the canvas, make a button like the one below and place it in the body. In this section, adjust the dimensions so that you want to appear in near of your main object.
Finally, I suggest using Look At Constraint to match the canvas and the view to the camera. Insert the camera as source and fix Constraint settings it as shown below.
Example Result

Matlab GUI sliders: Change position directly to clicked point

Does any one know a way to change the behavior of Matlab sliders so that they move directly to the value you click on?
For instance, lets say a slider is initialized at zero (far left side). I'd like to able to click anywhere on the slider (including the far right side) and have the slider instantly move to that location. The way they normally work you'd have to click repeatedly to move the slider over to the right side one increment at a time, or hold down the right arrow.
I am running an experiment where subjects need to assign values for 420 sliders! It would speed things up a lot of each slider only required a single click.
Thanks,

In gamesalad actor moves out of the screen on x-axis

In gamesalad framework I am creating a game in which I have an actor which only moves on x-axis on touch is pressed. But when I move it to x-axis the actor goes away out of the range of the screen. Let me clarify that I am new to gamesalad framework.
plz help to solve the problem.
I'm reading this in two different ways:
1 - when you press your touch controls the actor disappears from the screen
2 - when you press the touch control the actor moves along the x-axis and out of the screen
For the sake of argument I'm going to assume that we're talking about number two.
What you'll need to do is restrict the actors movement to the boundaries of the current screen. You can do this is two ways with Gamesalad
1 - create an invisible barrier for your actor to collide against
2 - use a behaviour to prevent your actor from going beyond the screen boundary
I'll explain both:
1, Invisible barriers
What you'll do is create a new actor, and set it to collide with the actor that your controlling. You'll create a few instances of this actor to create a walled area for your actor. Although this works, it's a little cludgy and using additional actors in a scene take a little performance away from your application.
2, using a behaviour
In my opinion the better way is to use the given behaviours in Gamesalad itself.
To stop the player actor from moving off screen you can use a combination of Rules and the Constrain Attribute behaviour to achieve this.
The first thing to know is your screen size; for an iPad I believe it's 1074 along the x-axis.
So to stop the actor moving off either side of the screen you'll need to do the following:
Open up the player actor
the click on the "Create Rule" button on the top right.
A new rule window will appear, but default the first dropdown will say "Actor receives event" change this to "Attribute".
Next select the attribute to use the rule against, since we're interested in the x-axis we'll want to query that player attribute which will be:
(also known as self) > Position > X
Select the greater than symbol (">") and then enter the maximum width of the screen minus whatever border value you want, so I'll use 1014 (1024 - 10).
Find and drag the Constrain Attribute behaviour into your rule a set the actors X position to 1014.
This will stop the actor from going beyond one side of the screen, now copy the rule and amend the settings to that if the actor goes less than, say 10, it will constrain the actors X position to 10.
I'd post an image, but alas my Karma isn't large enough right now! Hence the large explanation!
Hope this is what you're looking for!
It is way easier than that.
In top of the Gamesalad Creator there is a play button, which you probably know, displays your progress. To the left of this button there is a button that looks like a little video camera, it changes the camera settings. So what you first have to do is click the camera button, then the rectangular camera screen will show itself as marked. In the center of each of the sides of the highlighted rectangular which is the camera screen, sits 1 little grey rectangular. Each of these needs to be pulled to the center of the camera view so that you get a little grey "cross" in the center and from the center to the boarder there will now be this highlighted color.
Second and last step is easy, just go under your character and in (type or drag in a behavior block) you type control camera... or drag the control camera block, which as by the type box is statet possible.
Since Gamesalad only can have one camera at a time, and you character is the only one with the control camera option applied it will follow him and only him. Wherever your character starts on the screen, the camera will follow it when it passes through the center of the screen. You may know this from Super Mario Bros. Where you start of a little to the left and walk right and the second Mario enters the center of the screen, the camera follows him from then on.
Hope this helps... :

How do you return draggable content to their original positions in iPhone dev?

I am wanting to create a button in my iPhone app that when touched will return other draggable elements to their original position. I have looked at the Apple "MoveMe' example, but that returns the button to the center of the screen. I want to be able to position draggable objects around the screen, drag the objects within the app, and then return them to their original starting positions by pressing a designated button.
Any help appreciated!
Cache the initial positions of your draggable objects, and use an event handler on the button to reset their positions. I'm a little confused. The MoveMe example code is exactly what you need to answer your question -- what more do you want? You won't find a perfect code example for any arbitrary problem you can dream up.
Play around with saving the original positions and using MoveMe to reset the objects and I bet you'll have what your looking for in no time at all.

openGL and buttons on iPhone

I'd like to make a "video wall" type application, where multiple images are mapped onto a cylinder, I'd like to then enable each of these images as buttons.
Is this possible? I'm not sure if objects in an openGL space can act as buttons.
sure, it's possible. When the user clicks the opengl context you should be able to get back a x, y location where they clicked. It's then a matter of just doing your projection math backwards to find out what part of the scene they clicked.
You can also render the entire scene to a back buffer with each button set as a different color, then do a glReadPixels from this back buffer at the location of the click. The color value returned is the button they clicked.
And here's an example with a even faster method: http://www.lighthouse3d.com/opengl/picking/
There you only draw the picking buffer when the user clicks the mouse, and only for the single pixel they clicked.
Note: not all of these methods may work with OpenGL ES....so you'll have to pick the one that's right for you.
As a side note, this is also how many FPS games accomplish hit detection.