-
my x booty it is that BIG
no, not yet...wait...wait...wait...ok now but only if you fast tnough
this is the problem i am runing into.how can i make it so that they wait until all 3 heros have select their attacks before any of them does an action.
i got hero1 hero2 and hero3:
hero1speed=15;
hero2spedd=10;
hero3speed=20;
(this is only for reference)
in english this is what i need
hero1 i choose my attack and wait on hero2 and hero3 to choose attack
then
hero2 i choose my attack and wait on hero3 to choose attack
then
hero3 i choose my attack
then a 2 second wait..
then
hero3 attacks first-but only if his speed is greater then hero1 and hero2
then
hero1 attacks second-but only if his speed is greater then hero2
then
hero2 attacks third-but only if his speed is lower then hero3 and hero1
i guess in short what i really need is a "wait function"
the thins is i got NO idea how to do this cuse i have never bump into any in no tutorials any help.
sorry i cant upload the fla but is cuse i am trying to keep the game under wraps...you guys know what i mean.
thanks in advance
NOTE: i am a newb with some fairly knowledge of AS.
-
self-portrait
If you want flash to wait you'd have to set up some kind of timer
code:
max = 3 *12; // (seconds *framerate)
a ++;
if(a<max) {
a ++;
} else {
// make some other stuff...
}
-
my x booty it is that BIG
Originally posted by Kianis
If you want flash to wait you'd have to set up some kind of timer
code:
max = 3 *12; // (seconds *framerate)
a ++;
if(a<max) {
a ++;
} else {
// make some other stuff...
}
i dont know if that is suppose to help me...but uhuhuhuhuh thanks i think...was i suppose to understand that? i want my mommy hahahaha j/k thanks though but am as lost as i was before
-
Senior Member
Ok, step by step:
In hero 1, he goes first. When he selects his move, set a variable:
code: _root.turn="hero2"
Now in hero 2, add an if statement around everything:
code: if(_root.turn=="hero2"){
then after player 2 has made his move add:
code: _root.turn="hero3"
Then add another if statement to hero 3:
code: if(_root.turn=="hero3"){
Then you need a timer to wait 2 seconds. As kianis said:
code: max = 3 *12; // (seconds *framerate)
a ++;
if(a<max) {
a ++;
}
Change the "3" to the number of seconds to wait and the "12" to the frame rate of your game(frames per second, you get it?) then it keeps adding one to a until it is greater than the number of seconds. This means 3 seconds has passed.
Now, immediately after that, you need some more if statements:
code:
else{
if(hero1speed>hero2speed&&hero1speed>hero3speed)
{
//HERO 1 WINS
}
//etc.
}
Keep adding more statements until you meet all possibilities.
Hope that helps
-
A more elegant way to do this is to store some of your hero data in an Array, then use the inbuilt Array.sortOn() function of flash.
code:
//initialise
var Hero = new Array();
Hero[0] = {name:"hero1", speed:15};
Hero[1] = {name:"hero2", speed:10};
Hero[2] = {name:"hero3", speed:20};
// re-order
Hero.sortOn("speed");
// since we want highest value first, we step backwards through the sorted array
for (i=2; i>-1; i--) {
trace("Array index " + i + ": " + Hero[i].name + ": Speed = " + Hero[i].speed);
}
This code you can paste straight into frame 1 of a new flash file just to see the sortOn function in action. If you had 3 objects in your scene named hero1, hero2 and hero3, and each of those objects had an internal function named 'doMove' then you could use something like this:
code:
for (i=2; i>-1; i--) {
nextToMove = eval("_root."+Hero[i].name); // grab a handle on the object specified by 'name'
nextToMove.doMove(); // do whatever you want with that object
}
-
my x booty it is that BIG
Originally posted by slight
A more elegant way to do this is to store some of your hero data in an Array, then use the inbuilt Array.sortOn() function of flash.
code:
//initialise
var Hero = new Array();
Hero[0] = {name:"hero1", speed:15};
Hero[1] = {name:"hero2", speed:10};
Hero[2] = {name:"hero3", speed:20};
// re-order
Hero.sortOn("speed");
// since we want highest value first, we step backwards through the sorted array
for (i=2; i>-1; i--) {
trace("Array index " + i + ": " + Hero[i].name + ": Speed = " + Hero[i].speed);
}
This code you can paste straight into frame 1 of a new flash file just to see the sortOn function in action. If you had 3 objects in your scene named hero1, hero2 and hero3, and each of those objects had an internal function named 'doMove' then you could use something like this:
code:
for (i=2; i>-1; i--) {
nextToMove = eval("_root."+Hero[i].name); // grab a handle on the object specified by 'name'
nextToMove.doMove(); // do whatever you want with that object
}
now that i kinda understand a lil better ill give it a shot when i get home...thanks a lot man
-
my x booty it is that BIG
Originally posted by dogtown08
Ok, step by step:
In hero 1, he goes first. When he selects his move, set a variable:
code: _root.turn="hero2"
Now in hero 2, add an if statement around everything:
code: if(_root.turn=="hero2"){
then after player 2 has made his move add:
code: _root.turn="hero3"
Then add another if statement to hero 3:
code: if(_root.turn=="hero3"){
Then you need a timer to wait 2 seconds. As kianis said:
code: max = 3 *12; // (seconds *framerate)
a ++;
if(a<max) {
a ++;
}
Change the "3" to the number of seconds to wait and the "12" to the frame rate of your game(frames per second, you get it?) then it keeps adding one to a until it is greater than the number of seconds. This means 3 seconds has passed.
Now, immediately after that, you need some more if statements:
code:
else{
if(hero1speed>hero2speed&&hero1speed>hero3speed)
{
//HERO 1 WINS
}
//etc.
}
Keep adding more statements until you meet all possibilities.
Hope that helps
mmmmm i understand every line of AS the thing is i dont really see how it will work but ill give it a shot.
-
Here use this:
code:
speedFile = "15|10|20";
heroSpeeds = speedFile.split("|");
i = 0;
fps = 12;
counter = 2*fps;
attacking = false;
function selectAttack() {
_root["hero"+i].attack = chosenAttack;
if(_root["hero"+i].attack) {
i++;
}
//^ Waits to give every "hero" an attack ;
for(j=0; j<i; j++) {
if(j == i-1) {
if(_root["hero"+j].attack) {
startBattle();
}
}
}
//^ If all heros have an attack, start battle ;
}
function startBattle() {
counter -= 1;
m = heroSpeeds.length-1;
if(counter <= 0) {
heroTurn = heroSpeeds.sortOn();
//^ Originally posted by slight
for(k=0; k<i; k++) {
_root["hero"+k+"speed"] = heroSpeeds[k];
if(_root["hero"+k+"speed"] == heroTurn[m]) {
turnAttack = true;
}
}
if(turnAttack && !attacking) {
heroAttack(_root["hero"+k]);
attacking = true;
m--;
}
counter = 2*fps;
}
//^ This is the meat of the engine. It checks if its
// the "hero"'s turn to attack and then it does so.
// If the hero is "attacking" then it does not continue.
}
function heroAttack(hero) {
if(hero.attack == "spear") {
// Blah Blah make the hero do something to attack ;
}
if(hero.attack == "sword") {
// Blah Blah make the hero do something to attack ;
}
attacking = false;
}
this.onEnterFrame = function() {
selectAttack();
}
and thats basicly it....
EDIT: fixed some bugs and now I'm almost postive it works.
Last edited by PromiNom; 09-25-2004 at 04:21 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|