I'm setting up a simple Qualtrics survey with one question with a Loop & Merge function (in this one block); in Loop & Merge field 1, I've provided the URLs to my media files. The respondents have to select the right answer from two answer options (let's say Yes/No). All all my files are set up as a Loop & Merge within one question so that I won't have to create 100 separate questions for each individual media file.
This works great, however, I would also like to score my respondents' answers. The regular "scoring" feature in Qualtrics doesn't seem to work for me, since I can only provide one scoring option per question (i.e. I could only say that the first answer is always 1 point, and the second answer is always 0 points). However, the correct answer varies between my files (sometimes it's Yes/the first option; sometimes it's No/the second option).
I'm thinking there might be a way to list the correct answer (=i.e. the answer that should receive 1 point) in Field 2 in the Loop & Merge function; and then include some (javascript?) code in the question which would check the survey taker's answer choice against the "correct answer" in Field 2 of the Loop & Merge function for each media file. The code would assign "1" point if the participant's selected answer corresponds to Field 2 for each media file.
How would I write the (javascript) code to calculate a score for each question and an overall score at the end? (I don't need survey takers to see their score, but once a person is done, I would like to quickly see what their final overall score is, say 72 out of 100 possible points.)
Update: In the loop/merge function, I've added the right answer (for each file) in Field2, the incorrect answer in Field3. As suggested below, I've piped loop fields (2 and 3) into my question choices. I've added code in Field4 about whether or not the order of the answer options should be changed (0,1; 0= don't change order, 1= change order) so that the options always occur in the same order (for example, always Choice 1 = "Yes", Choice 2 = "No".) I've (unsuccessfully) tried to use the following JS code to refer to Field 4:
if (${lm://Field/4}==1) {
(choiceNum = ${lm://Field/3}, ${lm://Field/2})
}
If there is a way to work without JavaScript, I'd be glad to hear about that option as well.
Thank you so much!
How about this without JavaScript:
Include your two choices as loop fields: Field 2 is correct answer, Field 3 is incorrect answer
Pipe your loop fields (2 and 3) into your question choices
Randomize the choices
Score the question: Choice 1/Field 2 = 1 point, Choice 2/Field 3 = 0 points.
I'm currently creating a program using the createJS suite and have hit a roadblock. I'm "spawning" items on the stage however I wondered if there was a way to count how many currently exist on the stage.
So, for example:
if (spawnedItemCount <= 1) {
spawnItem();
}
spawnedItemCount would return the amount of a particular object that is currently being displayed on the stage. If there is only 1 (or less) of these objects then run the spawnItem function. Is this possible at all?
Thank you.
You, are looking for getNumChildren()
http://createjs.com/Docs/EaselJS/classes/Container.html#method_getNumChildren
Every container has this method, but it will only return the Number of direct children, no children of children, for that you will have to create a recursive call.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am having hard time remembering what Array.shift() and Array.unshift() do.
After few years, I still have too check out reference from time to time when I need to use one of them. Can anyone explain why those names are choosen and how to memorize which one does what?
I have no such problem with Array.push() and Array.pop()
As I known.
The shift command is come from the binary bit shift [1]. for Example.
001100
0 < 011000 // when you shift left
|
Yay!
I think it is quite simple it is just like you push it from behind. So this makes sense for me.
The unshift is the opposite way of shift.
001100
1 > 001100 // they called it unshift
1001100
|
Yay!
So that's it, Hope this helps!
[1] http://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
a.push(e) pushes e onto the end of a.
e = a.pop() pops the last element from a, to e.
a.unshift(e) enqueues e to the start of a.
e = a.shift() gets the first element from a to e.
Use push and pop for stacks.
Use unshift and pop for queues. (Or push and shift)
I remember the difference between shift (destructive) and unshift (constructive) simply by remembering that I use un-shift for en-queueing, and shift is the opposite to unshift.
Just think of your keyboard:
Shift gets a capital version of the first key you press.
.shift() gets the first item off the array.
This is certainly the most confusing pair of function names. The only salvation I can offer is to remember one of the following two things:
Shift can be thought of as "moving something around," and perhaps you can picture that if you "shift" an array around a bunch, something is liable to fall off the end (or in this case, the beginning). Unshift puts things back the way they were.
It's the opposite of what it sounds like it should be. unshift sounds like undoing something, but in fact, it's putting something onto the array.
Good luck!
How about:
SHIFTer makes a drifter
It returns the first entry to the variable.
and -
UNSHIFTer is a weenier that sneaks in line
Inserts argument as first entry in array
Oh, there are deep psychological techniques at work here!! :-o But seriously, you will remember it for its peculiarity :-)
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This piece of code pulls off all the images from your web page and rotates them in a circle. Really makes any page go naked (without its images). The best place to test is a website with many images. (Google Images for an example).simply place these code the url of any websites for e.g say goggle,remember u need to manually type "javascript:"
javascript:R=0;
x1=.1; y1=.05;
x2=.25; y2=.24;
x3=1.6; y3=.24;
x4=300; y4=200;
x5=300; y5=200;
DI=document.getElementsByTagName("img");
DIL=DI.length;
function A(){for(i=0; i-DIL; i++)//is equal to for(i=0; i < DIL; i++)
{
DIS=DI[ i ].style;
DIS.position='absolute';
DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px";
DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}
R++
}
setInterval('A()',5); void(0);//u can also use undefined here or u can pass these code to void(all code goes here);
//but u should not pass return false as it is used within a function to exit and return specified value
when undefined is returned browser reads that and dont nevigate away from the
current page.if not placed it redirects to next blank page.so its compulsory.also u can pass expression to void(exp here),it will be evaluated no problem but main thing to take in mind is that it always returns undefined which is necessary for browser also remember javascript: is a uri scheme similar to http: so u know when knew address to placed to url browser nevigates to that page even if it dont exist.In javascript: scheme ,browser executes the javascript code and writes that to new page .the void operator at the end of the uri returns undefined like void (exp)/void exp returns undefined which gets executed and prevents browser from taking default action
If you look carefully in the above code, its rotating the HTML “img” tag. Just replace it with “a” or “p” and watch some links or text rotate instead of images.But can anyone explain what is actually happening in the code?Also what does "javascript:" keyword actually do?
in the href attribut for hypertext document it uses http scheme .other time we can use javascript: scheme
There are two parts you need to pay attention to:
setInterval('A()', 5);
This executes the A function every 5 milliseconds.
function A(){
for(i=0; i-DIL; i++) {
DIS = DI[i].style;
DIS.position = 'absolute';
DIS.left = (Math.sin(R*x1+i*x2+x3)*x4+x5)+"px";
DIS.top = (Math.cos(R*y1+i*y2+y3)*y4+y5)+"px";
}
R++;
}
This function cycles through every element found, sets its position to absolute (not necessary to do this over and over), and then adjusts its left and top values, thus redrawing it in the viewport every 5 milliseconds in a new location.
If your confusion is regarding the math of locating the next location at which each element will be positioned, there's an entirely different site for those questions.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm working on a top down game, and this game is going to contain a lot of collisions simple and complex.
After doing some research, I understand that I have to always compare my character with 'object' within my code - and then check for collision calculations.
EG:
CheckCollisions(Player, Object);
Which means I have to add in every single collide-able object within my scene, into my code:
CheckCollisions(Player, Building1);
CheckCollisions(Player, Building2);
CheckCollisions(Player, Trash);
CheckCollisions(Player, Bench1);
CheckCollisions(Player, Bench2);
CheckCollisions(Player, Office1);
CheckCollisions(Player, Office2);
First off, my objects might not even be simple rects, they might be complex shapes. Secondly, some of them might have their own rotation. And thirdly, what happens if I have over tens of thousands of collie-able objects in my scene?
Ins't there an easier way to check for collisions within a HTML5/JS game?
Is this even possible? I'm really just looking for some advice and pointers.
Thanks
It's very uncommon to have a named variable for every single object in your game. Usually you store all objects in one data structure (like an array) and when you need to do something with all objects, you do a for-loop over this array.
Some important objects, like the player character, could have an own variable, but they should also be in the "all objects" array, so you don't need to program a special handling to include the player character.
Regarding performance: When you check everything against everything, the amount of collision checks which need to be performed increases quadratically. But you can reduce the effort when you only check collisions of those objects which are already close to each other. Before you check collisions, you:
divide the playing field into rectangular zones (the zones must be at least as large as the largest object).
Then you assign each object to the zone its upper-left corner is in.
Then you take each zone, and check collisions of each object in it with the other objects in the zone and with all objects the three zones right, down and rightdown from it (for objects which overlap zone borders).
When you have very complex shapes, you could also speed up collision-detection by calculating a bounding-rectangle for each shape (the smallest possible rectangle it fits into). Before you check the collision between two objects, you first check if their bounding rectangles intersect. When they don't, there is no chance for the complex shapes to intersect, and you can skip all the complex calculations.
As everyone so far has indicated, an array of objects is much better than naming all your objects individually.
A much easier method of collision detection that might work for you is to have a central object that tracks all occupied spaces. For instance, let's call it LocationTracker for now.
Assuming you're only using x and y axes, you can have a Point object that stores an X and a Y location, (and if you want to get fancy, a timestamp). Each object as it moves would send an array of all the Points that it is occupying. For example, you can call locationTracker.occupySpace(player[i], array(point(3,4), point(4,4), point(5,4)), etc.
If your call to occupySpace returns false, none of the Points match and you're safe, if it returns true, then you have a collision.
The nice thing about doing it this way is if you have x amount of objects, instead of checking x*x times per move, you check x times max.
You wouldn't need to pass in all points of the objects, just the outer most ones.
1 - you don't need to write a line of code for every object in your game. Put them into an array and loop over the array:
var collidableObjects = [Building1, Building2, Trash, Bench1, Bench2,Office1, Office2];
var CheckAllCollisions = function() {
for (var i=0; i<collidableObjects.length; i++) {
CheckCollisions(Player, collidableObjects[i]);
}
}
2 - if you have complicated collision check (ie rotated shape, polygon, etc) you can first check a simple rectangle check (or radius check) and do the more accurate check if the first one returns true.
3 - if you plan to have tens of thousands of objects you should have smarter data collections, for example objects sorted by X coordinate so you can quickly avoid checking everything larger than Player.X+100 and smaller than Player.X-100 (using binary search), or split the objects into a grid and just check the objects in the 3x3 grid cells around the player.
A much better way is to put all your scene objects into an array or a tree structure and then
for( var i=0; i<scene.length; i++ ) {
scene[i].checkCollision( player );
}
if you add a function .checkCollision() to every object, you can handle any special case in there.
It's a good idea to make the player a rectangle so the checking code doesn't become too complex.
Make the collision-checking-rectangle of the player object slightly smaller than the actual sprite; that makes the life easier for your players.
First of all, you should always have your objects in arrays. This includes things like enemies, bullets and other such things. That way your game can create and destroy them at will.
You seem to be talking about the actual frequency of the collision checks, and not the collision check method. To that my advice would be to only run collision checks on a finite number of the objects. Try using a grid, and only checking for collisions with objects in the same grid block as the player.
Another thing that helps is to have plenty of "short cuts" inside the method itself. These are things that can be checked quickly and easily before any complex math is done. For example, you could check the distances between the two objects. If the objects are farther away than their farthest corner, you don't have to check for a collision.
There are plenty of these methods that you can utilize in your own unique combination.