- This topic has 7 replies, 2 voices, and was last updated 10 years, 10 months ago by Brandon.
-
AuthorPosts
-
hardsofftMemberI am wondering on how to add 1 score point for each touch in a systematic order.
As for example if i have 3 balls numbered 1,2,3. so i need to start from 1 and then to 2,3. after touching on ball 3 then i need to touch in reverse manner like 3 to 2 and then to 1 and viceversa follows. so it needs to follow the same order…[i cannot start or touch any numbered ball as i wish]
BrandonMemberYou are going to need a variable with some checking (there are several ways to do this):
//off the top of my head, untested, I think it should work….
var myTouch = ‘0’;
var myScore = 0;//function for ball one
function ball1()
{
//check for first touch in order
if (myTouch = ‘0’)
{myTouch = ‘1’;myScore += 1;}
//check for second touch in reverse order
if (myTouch = ‘4’)
{myTouch = ‘0’;myScore += 1;}
}//function for ball two
function ball2()
{
//check for first touch in order
if (myTouch = ‘1’)
{myTouch = ‘2’;myScore +=1;}
//check for second touch in reverse order
if (myTouch = ‘3’)
{myTouch = ‘4’;myScore +=1;}
}//function for ball three
function ball3()
{
//check for first touch in order
if (myTouch = ‘2’)
{myTouch = ‘3’;myScore += 1;}
}
hardsofftMemberHi cincy. thanq for the reply. i tried ur code in _custom.js and on ball click run javascript. sorry to say that nothing seem to working..any idea on whats going wrong with…
BrandonMemberOops, maybe bad code in the first one:
//off the top of my head, untested, I think it should work….
var myTouch = ‘0’;
var myScore = 0;//function for ball one
function ball1()
{
//check for first touch in order
if (myTouch == ‘0’)
{myTouch = ‘1’;myScore += 1;}
//check for second touch in reverse order
if (myTouch == ‘4’)
{myTouch = ‘0’;myScore += 1;}
}//function for ball two
function ball2()
{
//check for first touch in order
if (myTouch == ‘1’)
{myTouch = ‘2’;myScore +=1;}
//check for second touch in reverse order
if (myTouch == ‘3’)
{myTouch = ‘4’;myScore +=1;}
}//function for ball three
function ball3()
{
//check for first touch in order
if (myTouch == ‘2’)
{myTouch = ‘3’;myScore += 1;}
}
hardsofftMemberso cincy i need to insert the whole code in custom.js. is that fine or stil i need to do anything else
BrandonMemberYes, insert it into the custom JS file, then assign the ball items the corresponding function.
If it still doesnt work let me know and I will see if I can do a sample mobi file.
hardsofftMemberHi cincy, i am sorry if i am disturbing you. i tried everything for a long time as you said but the score is not showing and nothing seems to happen with balls when touching in simulator…. i am attaching my zip file.
Attachments:
You must be logged in to view attached files.
BrandonMemberI found your problem. In the buttons, instead of the entire function (which you have in the custom js file) you only need:
ball1()
This will activate the function in the custom js.
Also, since you dont have anyway to actually see if the score is changing, you can place this inside the button ruy javascript;
alert(myscore);
So, in the button’s Run Javascript for the first one you will have:
ball1();
alert(myscore);Ball 2 will have:
ball2();
alert(myscore);etc…
-
AuthorPosts