Bob the Pleo Forums
Pleo Stuff => Pleo Hardware/Software => PDK, Programming, and code => Topic started by: Getorix on November 30, 2009, 01:34:38 AM
-
TASK:
Make Pleo to behave in a different way according to random number generator value.
SOLUTION:
Add the following code to the main.p file:
#include <Time.inc>
#include <Util.inc>
then add this code to public init() function:
seed(time());
Add the following code to the sensors.p file:
#include <Sound.inc>
#include <Util.inc>
#include "sounds.inc"
then add this code to public on_sensor(time, sensor_name: sensor, value) function:
new snd_num = rand(2);
switch (sensor)
{
case SENSOR_TOUCH_HOLD:
{
if (sensor_name:value == SENSOR_HEAD)
{
if (snd_num == 0)
{
sound_play(snd_bite);
// Wait for the sound to complete.
while (sound_is_playing(snd_bite))
{
sleep;
}
}
if (snd_num == 1)
{
sound_play(snd_moo);
// Wait for the sound to complete.
while (sound_is_playing(snd_moo))
{
sleep;
}
}
if (snd_num == 2)
{
sound_play(snd_kisses);
// Wait for the sound to complete.
while (sound_is_playing(snd_kisses))
{
sleep;
}
}
}
}
}
Please find these project files in attach [random.rar]
Enjoy.
P.S. This is my first project for Pleo, so sorry for the random.upf file content, I am not quite sure how to create them by now (have to read manual).
P.P.S. I look forward for any ideas how to use it in interesting way :)
-
That is great!!! Just what I needed :) I plan on using that information to create a mini personality (or two :P) a Christmas one for now and later I can redo the sleepy time personality that I made earlier :)
-
No worries :)
If you (or someone else) have anything else to "code" just ask.
-
There are a few people that will be very interested but I haven't seen most of them in a while, I know that one is very ill :( Not sure about the others, hopefully they turn up soon :)
-
Woohoo!!! Hehe. It worked spot on, thank you, thank you, THANK YOU!!!
Teehee can't wait to unveil my little pet project :D
-
Question though, does anyone know how to use the TIMER sensor, ie: getting Pleo to play sounds/motions without physical imput like touching the head. I have it working fine by touching the back but would much prefer to have Pleo just play random skits like in the Holiday personality.
-
I've created new topic for this issue: Using SENSOR_TIMER (http://bobthepleo.com/forums/index.php?topic=1053.0)