Page 1 of 1

RANDOMNESS

PostPosted: Sat Sep 27, 2008 12:34 am
by BlarghNRawr
how can i make an actor have a rand om animation?

and also... how can i make items randomly appear on a random part of the stage, and only when ur in a battle (not just in the menu)

Re: RANDOMNESS

PostPosted: Sat Sep 27, 2008 3:49 pm
by Rux
.......... I'll give you a code for random things to happen. What it does is when ever an event happens a int variable is set and read to see what actions the game needs to perform.

Code: Select all
int n;
n = rand(*put how many different actions you want here* 2)
if(n==0)Action;//Always start with zero for 1\\
if(n==1)Action;


This will make a random action every time the event happens. :wink:
I also made a demo a while ago.
Hope this helps!

Re: RANDOMNESS

PostPosted: Sat Sep 27, 2008 4:28 pm
by BlarghNRawr
what will this do?
make things appear at random, or give somethig a random animation?

Re: RANDOMNESS

PostPosted: Sat Sep 27, 2008 9:37 pm
by DilloDude
For a random animation, on some event (eg create actor), use:
Code: Select all
int anim = rand(nAnims);//change nAnimns to the number of animations you want to choose from
//if you want to choose between all the anims, or just the first few, you can use this:
ChangeAnimation("Event Actr", getAnimName(anim), FORWARD);

//or if you want the last few, or a group in the middle, use this:
ChangeAnimation("Event Actr", getAnimName(anim + value), FORWARD);//change value to the frame number of the first frame you're using

//if you want to choose from a collection of animations, not all together, yuo have to do it manually:
switch(anim)
{
    case 0: ChangeAnimation("Event Actor", "someAnimation", FORWARD); break;
    case 1: ChangeAnimation("Event Actor", "someOtherAnimation", FORWARD); break;
    case 2: ChangeAnimation("Event Actor", "thisHereAnimation", STOPPED); break;
    ...
}

Re: RANDOMNESS

PostPosted: Sat Sep 27, 2008 9:39 pm
by BlarghNRawr
ok thnx

Re: RANDOMNESS

PostPosted: Tue Oct 07, 2008 12:59 am
by supa-tails
How do I make an animation choose randomly at the create actor? For example, right when an actor is created it randomly chooses 1 out of 10 animations and stays that way.

Re: RANDOMNESS

PostPosted: Tue Oct 07, 2008 1:54 am
by BlarghNRawr
.

Re: RANDOMNESS

PostPosted: Sat Nov 15, 2008 7:51 pm
by Bee-Ant
supa-tails wrote:How do I make an animation choose randomly at the create actor? For example, right when an actor is created it randomly chooses 1 out of 10 animations and stays that way.

AnyActor>CreateActor>
Code: Select all
animindex=rand(10);

Re: RANDOMNESS

PostPosted: Sun Nov 16, 2008 8:32 pm
by Lexcondran
i think that thing is very weird as i said f his mom and it said yes over and over again lol
i said he is stupid and it says rux is sitting on my computer alot
then i say moo and it talks about cleaning up a puddle

Re: RANDOMNESS

PostPosted: Wed Mar 18, 2009 4:34 pm
by BlarghNRawr
T_T
srry i have a HUGE problem with rand...
it really doesnt like me

i know this sounds terrible, but, more depth please... ACK!
ive never had to say that in a long time

Re: RANDOMNESS

PostPosted: Thu Mar 19, 2009 12:41 am
by skydereign
You could always do it like this. Didn't read much into the topic, but I believe this is what you want.
Item->CreateActor->Script Editor
Code: Select all
int random = rand(2);
switch (random)
{
    case 0:
    //ChangeAnimation to actor's first animation
    break;
    case 1:
    //ChangeAnimation to actor's second
    break;
}

The problem with animindex=rand(10) is that animindex is a read only variable. So you would need to do it manually like the switch above. If you don't get rand, it picks a random integer from 0 to 1 below your desired number.

Re: RANDOMNESS

PostPosted: Thu Mar 19, 2009 11:16 pm
by Diana Kennedy
I must say, I have the same Problem. I would like to make animatons happen randomly triggered by an event or so, but none of the codes above work. When you don't have any notion of scripting you don't know what exactly to copy from given codes and what not.

Okay, let's say We have two actors: One is named "Dragon" and the other "Ghost" I would like Dragon to change to a randomly choosen animation after colliding with Ghost. what would the script be, I mean entirely (and without Slash commentaries) just as We should type it into the script editor after choosing "collision" select an action?

The next step would be that Ghost reacts with his own animations depending on which animation was choosen by Dragon. Lets say: Dragon chose the animation "bite" then Ghost should change its animation to "jump".

You probably see what I want to build: fighting scenes that can't be predicted.

Re: RANDOMNESS

PostPosted: Thu Mar 19, 2009 11:34 pm
by skydereign
Okay, I'll try my best to make this clear.
Dragon->Collide(Ghost)->Script Editor
Code: Select all
int RAND = rand(2);
switch (RAND)
{
    case 0:
    ChangeAnimation("Event Actor", "Bite", FORWARD;
    ChangeAnimation("Collide Actor", "Jump", FORWARD;
    break;
    case 1:
    ChangeAnimation("Event Actor", "Scratch", FORWARD;
    ChangeAnimation("Collide Actor", "Block", FORWARD;
    break;
}

The two, is the number of animations you want, it picks a random number, 0 or 1, in this case. Then the switch will change the animations according to the number. The dragon will bite, and the ghost will jump. And so on... I suggest commenting your code, it is meant to make it easier to read, the reason I used them in my previous example was I don't know what the ChangeAnimation will change to, as it was not my game. It is to show where the ChangeAnimation will go.

Re: RANDOMNESS

PostPosted: Fri Mar 20, 2009 10:17 pm
by Diana Kennedy
Thank you very much! I will try this out and then give feedback !

Re: RANDOMNESS

PostPosted: Sat Mar 21, 2009 2:49 pm
by BlarghNRawr
thanks :)