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