Changing Idle briefly while Idle is active?

Started by Candall, Thu 14/09/2006 16:28:24

Previous topic - Next topic

Candall

Confusing topic, maybe... but here's what I'm up to.

I have a character who constantly idles, and this is accomplished using the SetIdle(n, 0) command.  Works fine.

However, I need to have this character occasionally run a different idle loop... just once through, and then resume the standard idle.

I can set up a function that gets a Random(99) passed to it and sets the Idle Animation based on that number (say, for example, to make the secondary idle animation run 5% of the time), but I'm just not experienced enough with programming to have it work out so that the animation will run in its entirety and then resume with the old.  I get some sort of odd seizure-like clash of animations competing with one another to play out.

Help?

Nathan23

#1
I don't try this code but It can help, you need to manage global variables for this or the function SetGlobalInt and GetGlobalInt,
first you need to set a global variable, in your global script place this code inside the function game_start:

Code: ags
 
function game_start() {
Ã,  // called when the game starts, before the first room is loaded
Ã,  SetGlobalInt(2, Random(99));
}


and int the room where the character will be choose the interaction editor search the eventÃ,  Player Enters Room (after fadein), put this after you choose "Run script" action:

Code: ags


int state, idle;

if (state == 0) // to choose between view 1 or 2

Ã,  {cEgo.SetIdleView(1,5);}

else
 
Ã,  {idle = GetGlobalInt(2);
Ã,  Ã,  if (idle >0)Ã,  Ã,  Ã,  Ã, // idle =0 won't set this view anymore
Ã,  
Ã,  Ã,  Ã, { cEgo.SetIdleView(2,5);
Ã,  Ã,  Ã,  Ã,  idle = idle -1;
Ã,  Ã,  Ã,  Ã, SetGlobalInt(2, idle);
Ã,  Ã,  Ã, }
Ã,  Ã, 
Ã,  Ã, }Ã,  


monkey0506

You could do something like this:

Code: ags
int rand = Random(99);
if (rand < 5) {
  cChar.LockView(n);
  cChar.Animate(cChar.Loop, cChar.AnimationSpeed, eOnce, eNoBlock, eForwards);
  }

// rep_ex
if ((cChar.View == n) && (!cChar.Animating)) cChar.UnlockView();



Candall

Nathan23:Ã,  Thanks for the suggestion, but it's important that this particular character stays in perpetual motion.

monkey:Ã,  Your snippet worked great!

I made a couple of modifications to better suit my particular needs and I ended up with this:

Code: ags

int rand = Random(99)+1;
if ((rand < 5) && (cChar.Frame==7)) {
Ã,  cChar.LockView(2);
Ã,  cChar.Animate(cChar.Loop, cChar.AnimationSpeed, eOnce, eNoBlock, eForwards);
Ã,  }

// rep_ex
if ((cChar.View == 2) && (!cChar.Animating)) cChar.UnlockView();


Basically, all I did is make sure that the secondary idle isn't called unless the character is on a specific frame.

Thanks again, guys!

monkey0506

Well I didn't expect that EXACT snippet to work correctly...

Quote---------------------------
Error n00b!
---------------------------
Symbol 'n' undefined! WTF n00b! AGS DELETED!

---------------------------
OK
---------------------------

...but...I'm glad it worked (though since you increased rand by 1, you do realize there's only a 4% chance now...?).

You're quite welcome.


SMF spam blocked by CleanTalk