Copy link to clipboard
Copied
this is my game layout,
this is basicaly match order of names.
but every time when game reload all the display names are randomly placed.
i think frame random could be work but don't want to repeat the frame
anyone can help me !!!!
assign your names to an array, then randomizes the array:
var namesA:Array=["xxx","yyy",etc];
namesA=shuffle(namesA);
// namesA is now randomized. you can loop through namesA and present the display names randomly.
// nothing needs to be changed below.
function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a
;
a
= t;
}
return a;
}
Copy link to clipboard
Copied
what's the problem and what's the game?
Copy link to clipboard
Copied
first name come then i click 2 if it's order is correct then go to next name
just like quiz
but every time that names are coming in random that's the problem
Copy link to clipboard
Copied
assign your names to an array, then randomizes the array:
var namesA:Array=["xxx","yyy",etc];
namesA=shuffle(namesA);
// namesA is now randomized. you can loop through namesA and present the display names randomly.
// nothing needs to be changed below.
function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a
;
a
= t;
}
return a;
}
Copy link to clipboard
Copied
so i make all names into movie clip
Copy link to clipboard
Copied
that doesn't matter for using the code i suggested.
Copy link to clipboard
Copied
var namesA:Array=["a1","a2","a3"];
dynamic textfield name namesA
they are shuffling but output is a1,a2,a3 like this
there is only one name a3 then i click on according button if it's right then display next name...
Copy link to clipboard
Copied
can we jump Randomly to Frame Labels without Repeats
Copy link to clipboard
Copied
yes, put the frame labels in an array and apply the shuffle function to that array.
Copy link to clipboard
Copied
check this
function shuffle(arr:Array):Void {
var len:Number = arr.length - 1;
for (var i:Number = len; i >= 0; i--) {
var p:Number = Math.floor(Math.random() * (i + 1));
var t:Object = arr;
arr = arr
;
arr
= t;
}
}
var labels:Array = ["a", "b", "c", "d", "e"];
shuffle(labels);
var currentLabel:Number = 0;
function gotoNextLabel():Void {
if (currentLabel < labels.length) {
gotoAndPlay(labels[currentLabel]);
currentLabel++;
} else {
stop();
}
}
gotoNextLabel();
Copy link to clipboard
Copied
in this random frame label code
when i got it right name then how go to next name
Copy link to clipboard
Copied
call gotoNextLabel() again.
Copy link to clipboard
Copied
num_plates.num2.onRelease = function ()
{
if (names.gotoAndStop("b")) // here names is my movie clip inside a to x frame label
{
right.gotoAndPlay(2);
this.gotoAndStop(2);
updateScore(500);
this.enabled = false;
a = a + 1;
if (a == 24)
{
gotoAndStop("over");
}
gotoNextLabel();
}
else
{
updateScore(-100);
wrong.gotoAndPlay(2);
}
};
Copy link to clipboard
Copied
check this link
Copy link to clipboard
Copied
i didn't find names position
if (names.labels[0] == "a")//
{
right.gotoAndPlay(2);
this.gotoAndStop(2);
updateScore(500);
this.enabled = false;
a = a + 1;
if (a == 24)
{
gotoAndStop("over");
}
names.gotoNextLabel();
} //
Copy link to clipboard
Copied
your code snippets don't make sense.
you'll need to include more code or clearly explain what you're trying to do.
Copy link to clipboard
Copied
it's done!!!
i use this code
if (names.labels[names.currentLabel-1]=="a")
Thank you Kglad once again for your help
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
Hi Kglad
there is somethng problem n shuffle function
that names shuffle but after some clicks they repeat
Please help
on first frame in name movie clip code is
function shuffle(arr:Array):Void {
var len:Number = arr.length - 1;
for (var i:Number = len; i >= 0; i--) {
var p:Number = Math.floor(Math.random() * (i + 1));
var t:Object = arr;
arr = arr
;
arr
= t;
}
}
var labels:Array = ["a", "b", "c", "d", "e"];
shuffle(labels);
var currentLabel:Number = 0;
function gotoNextLabel():Void {
if (currentLabel < labels.length) {
gotoAndPlay(labels[currentLabel]);
currentLabel++;
} else {
stop();
}
}
gotoNextLabel();
and main time line button on click code is
if (names.labels[names.currentLabel-1]=="a")
{
right.gotoAndPlay(2);
this.gotoAndStop(2);
updateScore(500);
this.enabled = false;
a = a + 1;
if (a == 24)
{
gotoAndStop("over");
}
names.gotoNextLabel();
} //
Copy link to clipboard
Copied
once you hit the end of the array, you should reapply the shuffle function if you want to re-randomize the array.
Copy link to clipboard
Copied
in "names" movie clip i have 24 frames and in first frame if they all hit
then game is over.
in trace it's shown (b,g,i,a,v,.....) like this there is no repeatation in
array
but here in between frame is repeat.
how i find the solution.
Copy link to clipboard
Copied
once we hit the right match then delete the particuler array
is it possible?
Copy link to clipboard
Copied
you can remove an array element using the splice method. to remove the first array element, use:
labels.splice(0,1);
to remove the last element:
labels.splice(labels.length-1,1);
Copy link to clipboard
Copied
this is working but at one point, array intialized and again shffle the array
i didn't figured out the problem.
Copy link to clipboard
Copied
what problem are you seeing?