Verbot will only give one random number per rule?

Tips and questions about scripting your Verbot®.

Moderator: Staff

Verbot will only give one random number per rule?

Postby ender » Mon May 12, 2008 1:22 pm

I'm trying to create a mood variable for my verbot and then key certain responses to it just to make things a little more lively and unpredictable. I got this working initially by having a variable 'mood' that was set during my _startup by assigning a random number to it between 1 and 10. I then used those numbers to determine the verbots state of mind. Not realistic, but kind of fun.

So then I wanted to get a little more complex and instead of having a 'mood' variable, I thought I'd break that down into a couple of different states ... i.e. 'happiness', 'ego', etc. and then assign them a number between 1,10 randomly during startup.

The problem is that when I do this, all of the bots mood variables get set to the same number. i.e. if the first one comes back 6 they are ALL going to be 6. I'm getting my random number using a code module and method ... so 'mood.rand(1,10)' ... I've even tried giving each mood their own code module ... i.e. 'mood.happy(1,10)'... but still they all always come back with the same result as the first one ...

Is there a solution to this problem?
ender
ScribeBot
ScribeBot
 
Posts: 47
Joined: Sat Mar 29, 2008 3:01 pm

Postby JonC » Wed May 14, 2008 7:01 am

Ender,
I'm not sure if this will be any help, but I've tried a simple version of the same.
I don't use a random number generator, instead I make a call to a VCM that gets the time, extracts the seconds value and uses that to set a state (one of two at present). Code here:

int t1 = 1;
DateTime time = DateTime.Now;
t1= time.Second;
if(t1>op1)
{ return "true"; }
else {return "false";}

I also pass the parameter op1 as an integer (type int op1 into parameters box) to the VCM, so I can set the threshold for the effect.
Whilst this is not truly random, the timimg of the calls to the VCM is not fixed on a daily/hourly/minutely basis so the effect is quite random.
If you wanted greater randomness, just use the millisecond call

t1 = time.millisecond;

instead, that should do it!

Repeated calls to this would enable you to set different mood parameters, or else just return the 'time' value and use that to set parameters.

Hope this helps
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Postby ender » Thu May 15, 2008 1:18 pm

At what point in your processes are you calling the VCM method?

I am calling mine during the startup rule ... and so one could assume that if I used the time to set the bots mood variables, that they would all be pretty close to each other if not identical .... not many milliseconds are going to go by in the running of a single rule ... and even then the values of the mood variables would end up being incremental ... the ones lower in the list would have higher values ... so the bots mood would always be pretty predictable.

So ... Is there a better point in the cycle to run the mood setting VCM?? After a rule perhaps?
ender
ScribeBot
ScribeBot
 
Posts: 47
Joined: Sat Mar 29, 2008 3:01 pm

Postby JonC » Fri May 16, 2008 5:54 am

Sorry Ender, I didn't make myself very clear.

I use the "mood rule" at various points during the running of the Verbot. The calls are made as part of the outputs to a number of rules.
I haven't implemented this yet, but I intend to make calls to this rule when things happen within the Verbot that could reasonably be expected to alter it's "mood".

With my VCM call I can alter the probability of the the "mood" call being successful or failing, (at present my VCM returns just true/false which can be equated to happy/sad etc) thus:

If the Verbot was feeling miserable and something happened that could reasonably be expected to 'cheer it up' then the next "mood" call would be made with a low threshold for success, thus making the Verbot happy again, but still with a chance it would remain miserable!

To be frank, having thought about your problem a little more, I think that if you want to set a number of "mood flags" randomly during startup, then you will need a random number generator.

As another thought, I understand that you want to set happiness, ego etc, but why not call your VCM for values when relevant rules fire? This would mean that your Verbot's "mood" variables could easily change during the 'day' - you did say you wanted random, didn't you?
Admittedly you might end up with a very mercurial Verbot, but perhaps that what you want!

I must admit that I don't know why repeated calls to your VCM produce the same 'random' number.
Would you object to posting your code for the generator and I'll try running it myself to see what happens?
I'll also admit to some personal interest here, I may have a use for the code myself!
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Postby ender » Mon May 19, 2008 10:17 am

Code from VCM

Method : GetMood
Parameters : int min, int max

Random rand = new Random();
int num = rand.Next(min, max);
return num;

Code from _Startup

<?csharp
vars['happy'] = Mood.GetMood(1,10);
vars['ego'] = Mood.GetMood(1,10);
?>

When this runs both Ego and Happy = the same.

I've tried several things to get around this problem.

I wrote two new methods called: GetEgo and GetHappy with different variable names and still they equaled the same. I tried calling one from _Startup and then one from _startup2 ... using a send from _Startup ... still got the same number. I tried taking out the min,max and having them hard coded ... One time, just to see what would happen, I tried happy at 1,10 and ego at 1,20 and .... happy = 7 and ego = 14.... I ran startup again and got ... happy = 5 and ego = 10...

No idea whats going on.

---------

At any rate, it sounds like you and I are trying to do different things ... I am trying to set the bots mood at startup ... thats all. Then, various inputs effect the bots mood .... for instance, if I say its stupid then its happy goes down by 1 point ... If I say its smart then its happy goes up by 1 point. Then I have other rules that use 'happy' as a condition using something like "int.Parse(vars["Happy"]) >= 8"... which then runs that output if the bots happy is greater than or equal to 8 ...

The idea of the 'random at startup' is to account for the things that happen between the time we talk to a person ... since typically people are NOT in the same mood now as when we talked to them last.

Eventually, this will get more complex, with each variable having 100 points and potentially having several factors effect mood at startup ... i.e. time of day, length between conversations, etc.

I might even try to figure out how to have a effect variable... since sometimes when we talk to people, what we say has a greater impact or lesser impact than other times .... i.e. maybe one time I talk to the bot and say its smart that gives it 2 points of happy, but the next time it gives 1 or even 0, and then another 5 or 10 points... but thats a while a way ... right now I am just testing the basic concept before investing to much time in developing it.

The way I have decided to currently solve my problem with the random numbers is to have mood SETS ... so if GetMood() returns 6 then happy = 5 and ego = 4 ... which actually is more true to real life, as I'm eventually planning to add in things like anger, bored, etc ... and it would be kind of strange to have the bot have a 10 in happy and 8 in anger... since those two emotions, while different, are mutually exclusive.
ender
ScribeBot
ScribeBot
 
Posts: 47
Joined: Sat Mar 29, 2008 3:01 pm

Postby Aaron » Mon May 19, 2008 11:48 pm

I think that the problem is that the .Net random number generator is seeded with the current time (probably in milliseconds or maybe 10 microseconds). Since you are creating two Random objects (one in each call to GetMood) back to back, they're likely to be seeded with the same number and to generate the same sequence.

Here's what I'd suggest in your rule output:
Code: Select all
<?csharp
Random rand = new Random();
vars["happy"] = rand.Next(1, 10).ToString();
vars["ego"] = rand.Next(1, 10).ToString();
?>
To test: happy=[happy], and ego=[ego]


I did a quick test and it worked well for me.
Aaron
SupremeBot
SupremeBot
 
Posts: 1261
Joined: Thu Feb 26, 2004 11:13 pm

Postby ender » Fri Jun 13, 2008 1:25 pm

I'll have to try this and see what I get... thanks.
ender
ScribeBot
ScribeBot
 
Posts: 47
Joined: Sat Mar 29, 2008 3:01 pm

Postby JonC » Sat Nov 15, 2008 5:39 pm

Okay. I can confirm that this second method (Aaron's) for multiple random generation works.

The VCM method also works with repeated calls provided the Verbot has interacted with the "real" world between calls (thus allowing the time to change!).

Overall, both techniques are useful (i use both), but the csharp code is required for multiple calls in one rule.

My thanks to both Ender and Aaron for the code.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron