Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need a script

Mikey Mechanique
Mechanique Machinations
Join date: 16 Mar 2005
Posts: 5
04-12-2005 16:38
I need help making a script that will have an object say something random (chosen from a list) when touched. I'm just starting in learning how to do scripting, so all help would be appreciated.
Graham Mondrian
Registered User
Join date: 16 Mar 2005
Posts: 59
04-12-2005 16:49
Hey mikey, Heres a solution that randomly generates a list index.


CODE

list subject;

state make_list
{
state_entry()
{
subject = ["item1","item2"];
// really depends how input is taken but theres a hard coded example
// post back if you want a notecard reader or something
} /// s_e()

touch_start(integer total_number)
{
llSay(0,llList2String(subject,llFloor(llFrand(llGetListLength(subject))))));
// although you'll run out of things to say, they'll always be in a random order.
}

} /// makeList
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-13-2005 00:58
Alternatively the llListRandomize() function works (again) too.

Something like this might do.

CODE

list items=["item1", "item2", "item3"]; //again this is hard coded, other options exsit.

default
{
touch_start(integer times)
{
llSay(0, llList2String(llListRandomize(items, 1), 0));
}
}


the wiki page for lists can help a lot, and will show you all of these functions in place.

NB: I've not actually tried compiling this, but it ought to work.
Hiro Pendragon
bye bye f0rums!
Join date: 22 Jan 2004
Posts: 5,905
04-13-2005 01:23
Please note 2 things:

1. In the first reply, there was a forum bug... there should be no space in this line:
llSay(0,llList2String(subject,llFloor(llFrand(llGe tListLength(subject))))));

2. The randomizing list is far less efficient than the first example.
_____________________
Hiro Pendragon
------------------
http://www.involve3d.com - Involve - Metaverse / Emerging Media Studio

Visit my SL blog: http://secondtense.blogspot.com
Hiro Pendragon
bye bye f0rums!
Join date: 22 Jan 2004
Posts: 5,905
04-13-2005 01:26
Please note 2 things:

1. In the first reply, there was a forum bug... there should be no space in this line:
llSay(0,llList2String(subject,llFloor(llFrand(llGe tListLength(subject))))));

2. The randomizing list is far less efficient than the first example.
_____________________
Hiro Pendragon
------------------
http://www.involve3d.com - Involve - Metaverse / Emerging Media Studio

Visit my SL blog: http://secondtense.blogspot.com