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

Title: Randomizing Pleo
Post 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:
Code: [Select]
#include <Time.inc>
#include <Util.inc>

then add this code to public init() function:
Code: [Select]
seed(time());
Add the following code to the sensors.p file:
Code: [Select]
#include <Sound.inc>
#include <Util.inc>

#include "sounds.inc"

then add this code to public on_sensor(time, sensor_name: sensor, value) function:
Code: [Select]
   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 :)
Title: Re: Randomizing Pleo
Post by: InmemoryofRomeo on November 30, 2009, 01:44:56 AM
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 :)
Title: Re: Randomizing Pleo
Post by: Getorix on November 30, 2009, 01:54:40 AM
No worries :)
If you (or someone else) have anything else to "code" just ask.
Title: Re: Randomizing Pleo
Post by: InmemoryofRomeo on November 30, 2009, 03:15:15 PM
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 :)
Title: Re: Randomizing Pleo
Post by: InmemoryofRomeo on December 20, 2009, 09:11:57 PM
Woohoo!!! Hehe. It worked spot on, thank you, thank you, THANK YOU!!!

Teehee can't wait to unveil my little pet project :D
Title: Re: Randomizing Pleo
Post by: InmemoryofRomeo on December 20, 2009, 10:48:58 PM
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.
Title: Re: Randomizing Pleo
Post by: Getorix on December 23, 2009, 04:27:09 PM
I've created new topic for this issue: Using SENSOR_TIMER (http://bobthepleo.com/forums/index.php?topic=1053.0)
SimplePortal 2.3.5 © 2008-2012, SimplePortal