Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Lab Assistant
Original Poster
#1 Old 6th Aug 2015 at 11:14 AM
Default BHAV help - randomize message when using object?
I want to make a fortune cookie-type object that gives a message pulled from a list of random phrases when used. I already have a functioning test object that has the basic functions - the sim comes over, does an animation, the message pops up. But since I only started learning BHAVs several days ago, I only know the coinflip command for now. What I want to have is:
1. A list of most common messages - let's say 79% chance
2. A list of rare messages - 20% chance
3. A list of super rare messages - 1% chance, these ones qould come with extra events, such as the sim getting a love potion-like boost to chemistry or somesuch but that's further in the plans.

But that's in the future; for now I'd jsut like to know how to make a list of phrases and to make the object give them out randomly upon interaction. I'd be grateful for pointers!
Advertisement
*shrugs*
retired moderator
#2 Old 7th Aug 2015 at 3:42 AM
Ok, it sounds like you have your Text List with all the messages, correct? I'm going to assume they are sorted/grouped by rarity


I would split this up across multiple BHAVs such that you have one BHAV that decides what type of message to display and then a BHAV for each message rarity level.

Starting with a "Common Messages" BHAV:
You could use the [prim 0x0008] Random Number (Temp 0x0000 := 0 .. < Literal [whatever number]) to pick a random number.
Then with 0x0024 Dialog, you can use the Pop-up Wizard to have the BHAV use the Temp to pick which message to display.

Now, calling 0x0008 will set the temp to a random number from 0 to a given number. But maybe the lowest number of your messages start further up in the list. Maybe your messages start at line 0x000A (10) and not 0x0 (0). You can use the [prim 0x0002] Expression primitive to add to the Temp before calling 0x0024.

This will give you a BHAV tree that will display a random Common message. Repeat this process for Rare Messages and Super-Rare Messages.

Then in your main interaction, you will probably be interested in this BHAV:
[global 0x049F] Random - Chance of X out of Y (2 args: X=0x0000, Y=0x0000)

Pass in your odds (79 out of 100) and set the True/False targets accordingly. For example, you might say if True, call your "Random Common Message" BHAV tree; if False, call the global 0x049F again with the next odds (20 out of 100). If True, call your "Random Rare Messages" BHAV; if False, call your "Super Rare Message" BHAV.

I don't mind if you call me "MSD" or something for short.
Tumblr
Perhaps someday I'll have leisure time back...
Lab Assistant
Original Poster
#3 Old 7th Aug 2015 at 1:40 PM
Quote: Originally posted by maybesomethingdunno
Ok, it sounds like you have your Text List with all the messages, correct? I'm going to assume they are sorted/grouped by rarity


I would split this up across multiple BHAVs such that you have one BHAV that decides what type of message to display and then a BHAV for each message rarity level.

Starting with a "Common Messages" BHAV:
You could use the [prim 0x0008] Random Number (Temp 0x0000 := 0 .. < Literal [whatever number]) to pick a random number.
Then with 0x0024 Dialog, you can use the Pop-up Wizard to have the BHAV use the Temp to pick which message to display.

Now, calling 0x0008 will set the temp to a random number from 0 to a given number. But maybe the lowest number of your messages start further up in the list. Maybe your messages start at line 0x000A (10) and not 0x0 (0). You can use the [prim 0x0002] Expression primitive to add to the Temp before calling 0x0024.

This will give you a BHAV tree that will display a random Common message. Repeat this process for Rare Messages and Super-Rare Messages.

Then in your main interaction, you will probably be interested in this BHAV:
[global 0x049F] Random - Chance of X out of Y (2 args: X=0x0000, Y=0x0000)

Pass in your odds (79 out of 100) and set the True/False targets accordingly. For example, you might say if True, call your "Random Common Message" BHAV tree; if False, call the global 0x049F again with the next odds (20 out of 100). If True, call your "Random Rare Messages" BHAV; if False, call your "Super Rare Message" BHAV.


Thank you for replying! It helped a lot. I've managed to make the main BHAV call other ones, instead of listing all the actions in one giant tree, and learned to use the 0x048F command - set the odds to 20 out of 100, and the other message popped up way more frequently. However, no matter what I do, I can't get 0x008 to work, I get errors no matter what options I choose. I attached screenshots of the settngs I have so far.
My Text String runs from 0x000 to 0x005. I've been fiddling with this for about two hours now, and can't get it to work.

(somewhat related: is it possible to have more than one Text List in the package? I tried making separate ones for rare and common messages, but weren't able to pick the newer one in the popup wizard.)
Screenshots
*shrugs*
retired moderator
#4 Old 8th Aug 2015 at 12:57 AM
In your 0x0008, you are saving the value in Temp 0x0 so your 0x0024 BHAV should be using Temp 0x0 (not Temp 0x5).

Unfortunately I don't think you have can multiple Text Lists files because it uses the instance value to designate the type/purpose of the Text List file. Two Text List resources with the same instance value in your package would conflict.

I don't mind if you call me "MSD" or something for short.
Tumblr
Perhaps someday I'll have leisure time back...
Back to top