PDA

View Full Version : Monsters


MatchbookRomance
11-01-2004, 08:00 PM
Is there a way to make a variable that says which monster appears when a fight sequence starts? kind of like ... the value in a dynamic text box. The monster being the value. Is there a way to make it so it randomly picks a monster movie clip to put on the stage?

eatmorchikin6464
11-01-2004, 08:05 PM
Wow, this is really difficult to explain so I cant really.

MatchbookRomance
11-01-2004, 08:11 PM
Well than why post? if you DO know the code, just post the code and put in like "monster1" or something. I know enough about flash to get what it means...

Freddy
11-01-2004, 08:38 PM
I dont know much about arrays, but I'm 90% sure its how its done.

make something like
monsters[monster1, monster2, ect]
...and then some other stuff.

I dont know much about arrays or random, but Im sure an array would be used.

eatmorchikin6464
11-02-2004, 09:34 AM
Well, I can explain it, I just dont really know the code. The way I would go about doing it is making different monsters. Then you would need to get them to duplicate at different times so that there arent two monsters at once. Or, you could figure out how to do an array, as stated above, so that flash picks a random monster from that array to appear.

The Brown Cow
11-02-2004, 10:11 AM
You can pick out the name of the monster from an array. How you use this name (display, attachMovie, whatever) is your call.

// Create our list of monsters
monsters = ["dragon", "man", "dracula", "zombie", "lemer"]

// Now to actually pick a monster
var n = random(monsters.length);
var mon = _root.monsters[n];
trace(mon);

DarkReality
11-02-2004, 10:15 AM
I'm guessing that since monsters are animated, they're each their own MCs, rather than frames in one single MC which simply display different monsters.

Each of those MCs has a name, as in, when you make it appear, you have to call it somehow. The easiest thing to do is name all your monster MCs "Monster0", "Monster1, ... , "MonsterX" (X obviously being the number).

Then shove them into an array like shadow said:

Monsters[Monster0, ... , MonsterX]

You then have an array of Monster names:

MNames[Monster0_name, Monster1_name...MonsterX_name]

you should call random monsters like this, more or less:

i = Math.round(Math.random()*X);
And then whatever the code is to make a movieclip appear. attachMovie or something along those lines, nor sure anymore.

You then have the code for your textbox which goes something like this:

TextBoxVariableName = MNames[i];

And that should solve it all.

__________________________________

Then there's a completely different approach. Each Monster becomes an object of its own in a monster class (yes, Object oriented Programing). You proceed to give each monster object it's own name and the name of the MC which can then be called like this:

MonsterObject.MCname

But that's incredibly vague and I don't remember how to do this in AS at all. If you have Flash MX 2004 (and AS 2.0 automatically with it), check out an OOP tutorial on actionscript.org/tutorials or kirupa.com. They'll explain everything you need to know about objects and from there it should be a rather easy step to implement it.

But the arrays work just as well :-D >_<

MatchbookRomance
11-02-2004, 04:12 PM
i got what brown cow said, but how do i make it so the monster APPEARS after it selects one randomly...?

The Brown Cow
11-02-2004, 06:01 PM
attachMovie() maybe.

Depends on the way you made your game. You could attach a clip from the library, or maybe just play a certain frame of a movieclip that shows the monster.

We'd need to see your whole file in order to give you some code to use.

MatchbookRomance
11-02-2004, 06:27 PM
the frame things a good idea i guess but i have this code in the first frame of the actions layer:

// Create our list of monsters
monsters = ["dragon", "zombie", "specter"];
// Now to actually pick a monster
var n = random(monsters.length);
var mon = _root.monsters[n];
trace(mon);

Which is all the code you gave me haha. What would i need to put in for this?:

if (VARIABLE == dragon) {
gotoAndPlay(3);
}


what would i put in the place of VARIABLE to make it true... or is that code totally wrong lol?...

The Brown Cow
11-03-2004, 12:20 PM
if (mon == "dragon") {
monster_mc.gotoAndStop(3);
}

mon stores the name of our monster. Replace monster_mc with the name of the movie clip that contains the different monsters.

You can get rid of the trace(mon) line. That just prints the name of the monster in the output window. You'll only see it when testing anyway.

MatchbookRomance
11-03-2004, 04:13 PM
thanx brown cow, once again. haha. by the time this is done, you'll pretty much have MADE my game.