I have a TV character who looks like a tv but his second (number 1) loop is a newscast and i did it in the interaction editor and it works fine and dandy, looks neat too...
(http://img214.imageshack.us/img214/12/owmantc4.png)
but i wanted to add maybe a few more short clips on a random basis... so i figured ide try to move it to one script action, in the interaction editor
at the bottom where it says "text script equivalent code" it isnt coming up with anything for those two lines.
sound obviously just would be Playsound(4); but I am not sure how to set it up with a few scenes random or in order...
thanks alot guys...
You want to call your character animation with this command:
Character.Animate(int loop, int delay, optional RepeatStyle, optional BlockingStyle, optional Direction)
Assuming your character has the name "Television", then cTelevision.Animate (1, 0, eRepeat, eNoBlock).
For a random loop, you might be able to get away with calling random for the loop parameter. Something like cTelevision.Animate (Random (3) +1, 0, eRepeat, eNoBlock), where you would get a random number of either 0, 1 or 2 (3 numbers) +1, giving either loop 1, 2, or 3.
If that backfires you will have to declare a variable and randomize it before calling the animation command. So at the very top of your script you'd create a variable, say int loopswitch, and then when you want the random channel you would write:
loopswitch = random (3) +1;
cTelevision.Animate (loopswitch, 0, eRepeat, eNoBlock);
Hope that helps!
Baron
EDIT: Yes, pay attention to Monkey_05_06's post below -the Random function is indeed inclusive!
Actually, to clarify, Random(X) returns a value in the inclusive range 0-X, so Random(3) could return 0, 1, 2, or 3. So if you want to select loop 1, 2, or 3 at random you would use:
cTelevision.Animate(Random(2) + 1, cTelevision.AnimationSpeed, eRepeat, eNoBlock);
problem is i need it to play the right sound with it so if i did
cTV.Animate(Random(2) + 1, cTV.AnimationSpeed, eRepeat, eNoBlock);
playsound(Random(2) +1); would it still do the same random number on this line.. or a new one (does the rand work off the CPU clock)
In this case you would need to store the random value first so that you get the same value for the animation loop and the sound file.
int ran = Random(2) + 1; // loop/sound 1, 2, or 3
cTv.Animate(ran, cTv.AnimationSpeed, eRepeat, eNoBlock);
PlaySound(ran);
If you want the sound to continuously loop in the background though instead of just playing once, you could try making it a music file instead and then doing this:
int ran = Random(2) + 1; // loop/sound 1, 2, or 3
cTv.Animate(ran, cTv.AnimationSpeed, eRepeat, eNoBlock);
SetMusicRepeat(1);
PlayMusic(ran);
int ran = Random(2) + 1; // loop/sound 1, 2, or 3
cTv.Animate(ran, cTv.AnimationSpeed, eRepeat, eNoBlock);
PlaySound(ran);
i did that code but with an extra line because after it plays the one clip, i want it to go back to the blank screen (tv off), so i tried
int ran = Random(2) + 1; // loop/sound 1, 2, or 3
cTv.Animate(ran, cTv.AnimationSpeed, eRepeat, eNoBlock);
PlaySound(ran);
cTv.Animate(0, cTv.AnimationSpeed, eRepeat, eNoBlock);
but with that code it never ran the first animation just played the sound and the screen was blank
please someone help me :(
If you call .Animate with eNoBlock, the game doesn't pause while the animation is played.
You'll want:
int ran = Random(2) + 1; // loop/sound 1, 2, or 3
PlaySound(ran);
cTv.Animate(ran, cTv.AnimationSpeed, eRepeat, eBlock); // BLOCKING
cTv.Animate(0, cTv.AnimationSpeed, eRepeat, eNoBlock);
// script for Character 9 (Tv): Interact character
int ran = Random(1) + 1; // loop/sound 1, or 2
PlaySound(ran + 3);
cTv.Animate(ran, cTv.AnimationSpeed, eBlock);
cTv.Animate(0, cTv.AnimationSpeed, eRepeat, eNoBlock);
now with this code, the tv just keeps doing the animation over and over again, and does not stop (even thought i took out erepeat)
I'm not sure why any help please?? :X
FIGURED IT OUT
NEEDED THAT 0
cTv.Animate(ran, cTv.AnimationSpeed, 0, eBlock);
TY EVERYONE FOR ALL THE HELP :)
You can't simply remove the eRepeat, the parameters are expected in a specific order. You'll need to pass the opposite value, eOnce, instead. Also, unless you are actually animating the TV while it's turned off, you don't need to call cTv.Animate to release it back to it's normal loop. Try this instead:
int ran = Random(1) + 1; // 1 or 2
PlaySound(ran + 3); // sound 4 or 5
cTv.Animate(ran, cTv.AnimationSpeed, eOnce, eBlock); // animate loop 1 or 2, once and blocking
cTv.Loop = 0; // restore the television back to its normal loop -- use this if the TV has a static image while it's off; otherwise use
cTv.Animate(0, cTv.AnimationSpeed, eRepeat, eNoBlock); // restore the TV back to its normal "off" animation -- use this only if you actually animate the TV while it's off