Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Randomising a list and general function implementation

jamieparsons Lemon
undergrad n00b
Join date: 5 Nov 2008
Posts: 36
11-05-2008 18:58
Hey everyone I'm still a bit of a newbie at all this and every single step is a complete struggle so hoping someone can give me a little guidance.

I'm currently doing a Second Life scripting project for my first year Computer Science course... I have no prior knowledge of programming (doing some java in another class but that only helps a little).

My problem is I never know how to implement things... we're given random little tasks to do and I just struggle every step of the way, not only embarassing but completely soul destroying as it's the only class I'm having problems in.
Does anyone know of any good tutorials that will really give me a boost in the whole structure and implementing functions?

So right now I have a little chatbot type program that I wrote and after a few hours of writing and rewriting I finally have something:






MY CHATBOT...

list happy = ["excited", "pleased", "chuffed", "content"];
list unhappy = ["unhappy", "bored", "angry", "sad", "frustrated"];

default
{
state_entry()
{
llListen(0,"",NULL_KEY,"";);
}

listen(integer channel, string name, key id, string message){

integer x;
integer found = 0;
string currentSad;
for (x = 0; x < llGetListLength(unhappy); x++){
currentSad = llList2String(unhappy, x);
if(llSubStringIndex(message, currentSad) != -1){
llSay(0, "why are you " + currentSad + "?";);
found = 1;
}
}

integer y;
string currentHappy;
for (y = 0; y < llGetListLength(happy); y++){
currentHappy = llList2String(happy, y);
if(llSubStringIndex(message, currentHappy) != -1){
llSay(0, "I'm glad you're " + currentHappy);
found = 1;
}

}
if(found == 0){
llSay(0, "how interesting!";);
}
}
}


Now I have been asked to randomize the responses so how would I implement that and what function is best to use?
I have found the llFrand() and llListRandomize()


With llListRandomize I was thinking of putting something like this in the first line of the listen state...

list randomUnhappy = llListRandomize(unhappy, 1);



and then change the: llSay(0, "why are you " + currentSad + "?";);

to: llSay(0, "why are you " + randomUnhappy + "?";);


Can't get this to work.

Basically my main problem is when I find a function I'd like to use I really don't know how to implement it, when I use the likes of LSLportal and LSLwiki it really is a bit too daunting to get my head round.

So if any of you have any good pointers on how you started out and if you can direct me to some good tutorial websites that give me more than just the "this is how to do llSay" but actually has substance - telling me how to implement things.

Hope you can help folks as I'm kind of falling behind with my work and I'm completely stressing out.

Cheers.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-05-2008 20:16
From: jamieparsons Lemon
I just struggle every step of the way, not only embarassing but completely soul destroying


welcome to learning how to program / script / code, its hard to wrap your head around it at first but just keep at it it will click

From: jamieparsons Lemon

Now I have been asked to randomize the responses so how would I implement that and what function is best to use?
I have found the llFrand() and llListRandomize()


both could work, think of a deck of cards, using llFrand() would be like choosing any random card anywhere in the deck, llListRandomize would just shuffle the list, use them both and you would be choosing a random card from a shuffled deck greatly improving your "randomness"


From: jamieparsons Lemon

With llListRandomize I was thinking of putting something like this in the first line of the listen state...

list randomUnhappy = llListRandomize(unhappy, 1);



and then change the: llSay(0, "why are you " + currentSad + "?";);

to: llSay(0, "why are you " + randomUnhappy + "?";);


Can't get this to work.


thats right, becuase your just shuffling the deck, you would need something more along the lines of

llSay(0, "why are you " + llList2String(unhappy, current_response) + "?";);

and using a counter so you go tru them one at a time, like pulling the top card off of a deck and setting it aside... the problem with this is when you get to the end of the deck you have to reshuffle or else its no longer random

instead of using a counter (in the form of current_response above) you could use llFrand, then you would always be random, with less code, and with your short list you wouldnt even need to "shuffle the deck" (altho the combination of both would be good for a card game like uno or whatever)


From: jamieparsons Lemon

Basically my main problem is when I find a function I'd like to use I really don't know how to implement it, when I use the likes of LSLportal and LSLwiki it really is a bit too daunting to get my head round.

So if any of you have any good pointers on how you started out and if you can direct me to some good tutorial websites that give me more than just the "this is how to do llSay" but actually has substance - telling me how to implement things.

Hope you can help folks as I'm kind of falling behind with my work and I'm completely stressing out.

Cheers.


the best way to learn what everything does, is the wiki, take the wiki info set it in a small controlled test script ans fiddle with it to see what it does, when i started SL i barley had any scripting knowledge and thats the way i learned, well that and bugging people almost constantly

once i found my writing style (noobie expanded) and understood the basic mechanics of it, lsl, and almost every other language ive tried to date has just fallen into place

just keep at it

and good luck
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
11-05-2008 20:44
Omg, you're so lucky that you get an assignment with LSL :P i'd be so happy if i could have LSL instead of using tones of others programs (VB, VBA, Fortran, Matlab, C++ ...) while back in uni ... :( LSL is way more fun that those, and you should be proud of playing around with it :)

Anyway, in regard to your concern:
=====
list randomUnhappy = llListRandomize(unhappy, 1);

and then change the: llSay(0, "why are you " + currentSad + "?";);

to: llSay(0, "why are you " + randomUnhappy + "?";);
=====

randomUnhappy is a randomized list created from the unhappy list. It is like to do a shuffle the order of each element in the unhappy list, then return the result in the randomUnhappy list.

The parameter in the llSay(0,"";) function is string type only, i.e. everything inside the "" has to be string. So the entire "why are you " + currentSad + "?" is a string, and currentSad was previously defined from [ currentSad = llList2String(unhappy, x); ] which is the x'th element from the unhappy list.

Then in the [ llSay(0, "why are you " + randomUnhappy + "?";); ], you are putting the randomUnhappy list type into a string type, which is incorrect syntax as everything in the "" has to be string only.


The correct way to get a random element from the unhappy list would be something like this:

1) using llFrand() to get a random number from the total length of the unhappy list, e.g.
integer random_number = (integer)llFrand((float)llGetListLength(unhappy));

Firstly, using llGetListLength() to get how many elements in the list, in this case 5. This is an integer type.
Secondly, llFrand() has to be a float type, so by using a (float) before which converts the integer type into float type and does the job. Now the range in llFrand is now from 0.0 to 5.0.
Lastly, using a (integer) to convert the whole thing into an integer type, e.g. if the result is 3.2, the random_number will be 3 etc..


2) after you have the random_number, you can then use it to get the element from the unhappy list, e.g.
string random_response = llList2String(unhappy,random_number);

The llList2String(list,n) function returns the nth element from the list.


3) and finally to output the result using llSay(), e.g.
llSay(0, "why are you " + random_response + "?";);

The first parameter in llSay is the channel to use, in this case 0, which is the standard chat. So that everyone will hear this message when they are 20m within the saying object.



The LSL portal as well as the wiki are pretty much what most ppl use nowadays. Combining with the library and various examples, you should be able to get "how to implement" those functions.

Hope that helps :)
Zolen Giano
Free the Shmeats!
Join date: 31 Dec 2007
Posts: 146
11-05-2008 21:00
I would use llFrand() to pick a random number to use with llList2String() to get a random line from the list.

I'm not in world to test this, but something like this might work:


integer x = (integer)llFrand((float)llGetListLength(sadlist)-1);

string sad = llList2String(sadlist, x);


lol...I really should test this before posting cuz its a little wonky. One must cast the variables to floats then back to integers if you use llFrand.

and llList2String starts counting lines from 0...so you have to subtract "1" from the list length....not sure if I did that right in the code there...but thats the idea.


I would use this method over the llListRandomize() method becuse I assume this would probably use less memory and script time.....

But you can build it using both methods and toss in llOwnerSay((string)llGetFreeMemory()); in the script to see what method is using less memory and tell your teacher how smart you are for building 2 versions.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-05-2008 21:18
while using both MIGHT increase randomness (it might not too, due to seeding of random numbers) your code will be smaller if you just pick one or the other...

the code is simplest with list randomize, since you can run it on the list and just always use the first index.

the code is slightly more complex if you use FRand, since you have to specify a range, and then feed the answer to the function that reads the list, but this way is probably faster and more resource friendly then randomizing an entire list, especially if it's a big list

the first method is also frowned upon in general, because scrambling your data makes it harder to access specific parts of that data, in this case it's just bad form, not harmful, but it isn't a good habit... that said there are case where it's the best path.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
jamieparsons Lemon
undergrad n00b
Join date: 5 Nov 2008
Posts: 36
Almost there i think...
11-05-2008 21:23
wow thanks for the help :)

BUT - and don't hate me... I kind of read the question wrong the first time.

Turns out I was just supposed to create another list full of replies that were randomized.

So all your help is still completely valid :)

What I'm doing just now isn't a homework assignment, we had a couple of hours in class to have the whole chat bot done, I've spent a good 5 hours on it now and only just starting to get to grips with it. Was really unfair as they really did just throw us in it, only been 2 months and I'm studying object oriented programming in java in my software development class and thats the only programming experience I have which is kind of different from this.

Anyway back to the matter at hand, finally got something that at least compiled after a couple of hours but now nothing happens. My chatbot is just a cube just now but... it's not chatting to me anymore since I implemented this random response into it :/


list happy = ["excited", "pleased", "chuffed", "content"];
list unhappy = ["unhappy", "bored", "angry", "sad", "frustrated"];
list reply = ["How come you're ", "Tell me why you're ", "Do you want to talk about why you're "];


default
{
state_entry()
{
llListen(0,"",NULL_KEY,"";);
}

listen(integer channel, string name, key id, string message){

integer x;
integer found = 0;
string currentSad;
string randomReply;
integer random = (integer)llFrand((float)llGetListLength(reply));
randomReply = llList2String(reply, random);
for (x = 0; x < llGetListLength(unhappy); x++){
currentSad = llList2String(unhappy, x);
if(llSubStringIndex(message, currentSad) != -1){
llSay(0, randomReply + currentSad + "?";);
found = 1;
}
}

Now everything in llSay is a string. I've only just implemented (integer) and (float).
I had...

integer random = llFloor(llFrand(llGetListLength(reply))); before.

It seemed to compile fine, and llFloor converts everything into an integer doesn't it? Which way is better... (integer) or llFloor?

I think I may have stared at this code too long now but since I'm randomizing the responses, does that mean I would still need a for loop? Since x does not have to be incremented.

Anyway if someone can spot what's wrong with this and why it's no longer giving me any output that would be great.

Thanks for the script Osgeld, going to have a wee look through it now.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-05-2008 22:09
From: someone

CODE

list happy = ["excited", "pleased", "chuffed", "content"];
list unhappy = ["unhappy", "bored", "angry", "sad", "frustrated"];
list reply = ["How come you're ", "Tell me why you're ", "Do you want to talk about why you're "];


default
{
state_entry()
{
llListen(0,"",NULL_KEY,"");
}

listen(integer channel, string name, key id, string message){

integer x;
integer found = 0;
string currentSad;
string randomReply;
integer random = (integer)llFrand((float)llGetListLength(reply));
randomReply = llList2String(reply, random);
for (x = 0; x < llGetListLength(unhappy); x++){
currentSad = llList2String(unhappy, x);
if(llSubStringIndex(message, currentSad) != -1){
llSay(0, randomReply + currentSad + "?");
found = 1;
}
}


I don't see anything obviously wrong, though I'm certain there's code you aren't showing us (missing brace on the end, found variable is never actually used) perhaps report the found variable at the end of the listen code if it's 1... also make sure you aren't running into a problem of spelling or capitalization (you are doing an exact match). if that's what's happening, you might try converting the incoming message to lower case before comparing (llToLower)

@rounding random output
you definitely want to watch the possible bounds of your random number when rounding...
integer will truncate (meaning remove ther fractionl part). in your above example this works to your advantage,since it will choose a number from zero, to just under your max, and be reduced by removal of the fractional part (range on llFrand is [0 - x) or (-x - 0] brackets means includes, parenthesis meanup to but not including) llFloor would workrk also, just be sure to remember that it gives a very slight edge to your low number since it could be absolute, or have been rounded. when your range is negative floor will still round down (-1.1 -> -2, while integer conversion will round up (-1.1 -> -1)

as a general rule, it's prefered practice to use the floor and ceiling functions because they don't change the direction of rounding, and the round functionfor others since it obeys rounding rules. in practice, integer conversion is fine as long as your bounds are solidly within a set range that doesn't cross 0 (plus it doesn't hurt that you needed and integer index so would have used it anyway) also watch out, in some languages, they use 'business rounding" which switchs between floor and ceiling models each time it gets .5 (keeps banks from always keeping the difference on transactions that split pennies)

@looping structures
you might want to consider either using a different test (not likely here) an escape method (I DO NOT suggest jump) a different looping structure.

your current loop could include an if (found) x = list length (which would by default pop you out of the loop so you don't have to keep testing for something youalready found)
other loop structures might even be better, such as do- while (always executes once before teh test) and while (do) which is similar to the for loop, but less limited in use. both support other types of tests, and neither requires a counter variable, though both can use one.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
jamieparsons Lemon
undergrad n00b
Join date: 5 Nov 2008
Posts: 36
11-05-2008 22:45
Thanks for the reply singer, and yeah that was just a little of my code the rest is as follows...

list happy = ["excited", "pleased", "chuffed", "content"];
list unhappy = ["unhappy", "bored", "angry", "sad", "frustrated"];
list reply = ["How come you're ", "Tell me why you're ", "Do you want to talk about why you're "];


default
{
state_entry()
{
llListen(0,"",NULL_KEY,"";);
}

listen(integer channel, string name, key id, string message){

integer x;
integer found = 0;
string currentSad;
string randomReply;
integer random = llFloor(llFrand(llGetListLength(reply)));
for (x = 0; x < llGetListLength(unhappy); x++){
randomReply = llList2String(reply, random);
currentSad = llList2String(unhappy, x);
if(llSubStringIndex(message, currentSad) != -1){
llSay(0, randomReply + currentSad + "?";);
found = 1;
}
}

integer y;
string currentHappy;
for (y = 0; y < llGetListLength(happy); y++){
currentHappy = llList2String(happy, y);
if(llSubStringIndex(message, currentHappy) != -1){
llSay(0, "I'm glad you're " + currentHappy);
found = 1;
}

}
if(found == 0){
llSay(0, "how interesting!";);
}



}
}

As you can probably tell, i've only focused the random reply on the 'unhappy' list for now until I get it sorted. But that's what I have and it compiles fine but the chat bot doesn't give me a reply :(

Hope someone can help 'cause I have now hit a wall.
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
11-05-2008 23:45
Your script was fine and i had a test in-world was no problem at all. Maybe you just need to reset it? and make sure you're close (about 20m) from the box when you type.

Anyway, below is a little mod from your script. I also was only focusing on the unhappy list. Putting the randomReply line ONLY when it is found to save some resources, as well as adding an outrage value to stop the for-loop. This is commonly use to stop a for-loop instead of using the swearing "jump" in any programming language.

You could do the rest with happy list :)



list happy = ["excited", "pleased", "chuffed", "content"];
list unhappy = ["unhappy", "bored", "angry", "sad", "frustrated"];
list reply = ["How come you're ", "Tell me why you're ", "Do you want to talk about why you're "];


default
{
state_entry()
{
llListen(0,"",NULL_KEY,"";);
}

listen(integer channel, string name, key id, string message){

integer x;
integer found = 0;
string currentSad;
string randomReply;
integer random = llFloor(llFrand(llGetListLength(reply)));
for (x = 0; x < llGetListLength(unhappy); x++){
currentSad = llList2String(unhappy, x);
if(llSubStringIndex(message, currentSad) != -1){
randomReply = llList2String(reply, random); // execute only when found
llSay(0, randomReply + currentSad + "?";);
found = 1;
x = 99999; // good way to stop a for-loop without using jump
}
}

if(found == 0){
llSay(0, "how interesting!";);
}
}
}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-06-2008 04:20
Another way to do it that uses less sim resources:

CODE

reply = llListRandomize(reply, 1);
unhappy = llListRandomize(unhappy, 1);
llSay(0, llList2String(reply, 0) + llList2String(unhappy, 0) + "?");
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-06-2008 08:16
I believe OP is only randomizing the reply phrase, not the unhappy list (which is being detected for and spit back out)

another way to say
func(x) != -1
is to use ones complement operator like so
!~func(x)
which converts -1 to 0, and all other numbers (including 0) to something other than 0 (not important what for this usage, but it's worth reading into for other uses). zero = false (a fact in most languages), any other number (in LSL) = true (some languages only recognize 1 or -1) [be aware of this, in each language, for instance in PHP (FALSE > -1 is FALSE, because -1 is converted to boolean first, and I believe the default value of TRUE is 1) LSL has no actual boolean types, only constants]
this evaluates faster in just about every language, this only works for functions that return a zero based index, and -1 for not found... you can metally interpret this kind of usage as ~=found !~=not_found)

using that

if (!~llSubStringIndex( message, currentsad )){
llSay( 0, llList2String( reply, (integer)llFrand( llGetListLength( reply ) ) ) + currentsad );
}

the hint there, is that if you only use a variable once you can replace the variable with what it is equal to and save a step and variable space while you're at it. also if you're going to declare a variable, then immediately set it, you might as well include the set in the declaration

the one other thing you might want to watch is using functions in loop tests. it's better to avoid this if possible by setting a variable to the function output (as long as that output isn't going to be changing while your in the loop) then use the variable, so that you aren't adding the load of calling a function every pass through your loop (sometimes it's unavoidable, but usually not)

anybody remember if it's faster to break a message into a list and then use listFindList on it's elements to check for key words? I know string searching in LSO was very slow, it's another possible way to search the string, always good to know options, especially for future use =)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-06-2008 09:39
If I was to do it then it would be like this. Notice I am NOT listening on channel 0, that is a major baddie in SL. It would have to process every single thing said anywhere in the sim by every object and avatar, 24 hours per day and then check to see if it is in range and then if any word said is in your list.
CODE

list mood =["excited", "pleased", "chuffed", "content", "unhappy", "bored", "angry", "sad", "frustrated"];
list ask =["How come you're ", "Tell me why you're ", "Do you want to talk about why you're "];

default {
state_entry() {
llListen(7, "", NULL_KEY, "");
}
listen(integer channel, string name, key id, string message) {
if (~llListFindList(mood, [message])) {
llSay(0, llList2String(llListRandomize(ask, 1), 0) + message + "?");
}
else if(message == "reply"){
llSay(0, "how interesting!");
}
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
jamieparsons Lemon
undergrad n00b
Join date: 5 Nov 2008
Posts: 36
11-06-2008 13:06
Thanks for all your help folks, still can't get my script to work but I think the island I'm working on is maybe just too overloaded with stuff (uni work island) as my original script without the trimmings that did work is no longer working either :/

So Singer, I've never heard of this compliment operator. In pseudocode would it be the equivalent of:

if 'you find' llSubStringIndex( message, currentsad ) ?
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
11-06-2008 15:59
If you need a quiet, secluded, place to test your scripts call me, I will give you access to some of my unused land as a sort of Homework room :)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-07-2008 05:31
From: jamieparsons Lemon

So Singer, I've never heard of this compliment operator. In pseudocode would it be the equivalent of:

if 'you find' llSubStringIndex( message, currentsad ) ?

here's a semi-technical page on signed number systems, if you're like me, it'll give you a headache
http://en.wikipedia.org/wiki/Ones%27_complement#Ones.27_complement

the lsl portal doesn't really bother describing how it works, however it's a bitwise (operates on the individual bits), unary (meaning it apllies only to the number it's in front of), operator. it's action is to reverse all the bits from what they were before, in our case, -1 is represented as a string of all ones in the bits of the integer. converting it to all zeroes via this operator, it becomes zero, or false, which is the answer we want, if the function didn't find an index.

if you read the above article, keep in mind thta you can ignore the information about -0 since the system doesn't actually read integers in the ones complement sytem, it's just a useful operation to have when using bitmasks (namely for turning all bits on or off without having to store a constant).

for our purposes it does the following action (that might be eiser to understand)
~number == -llAbs( number + 1 );
eg
-1 --> 0
0 --> -1
1 --> -2
etc

the difference is because it's a bitwise operation, it works FAST, and because we aren't comparing it (only checking to see if it's zero or not) we avoid a test

both (~findIndex( x )) and (findIndex( x ) != -1) will do the same thing in LSL, the first is smaller, easier to read (if you know what you're looking at) and faster, but only good if you don't need to save the index (which you don't here)

PS previous post, the code was wrong, the text was right, treat ~ as found, correct statment is
CODE

if (~llSubStringIndex( message, currentsad )){ //-- read as 'if found subStringIndex of currentSad in message
llSay( 0, llList2String( reply, (integer)llFrand( llGetListLength( reply ) ) ) + currentsad );
//-- say in public, stringIndex from replyList at randomIndex + curent sad
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
11-07-2008 12:50
Woohoo 2's complement! Woooo!
_____________________
wolk Writer
Registered User
Join date: 4 Jun 2008
Posts: 4
11-07-2008 15:24
I wrote a random sentence generator, using a free script from my inventory. It works perfectly. The part of it that picks a random text from a list goes as follows:

string rnd(list lst)
{
lst=llListRandomize(lst,1);

return llList2String(lst,0);

}

string geteen()
{
list onderwerp = [
"A small but pregnant difference ",
"The recollection ",
"Such monstrous passion ",
"Nonsense ",
"Matter ",
"Something known only to yourself ",
"A silent wonder ",
"Everlasting happiness "];

return rnd(onderwerp);
}


I would like to make the sentences appear on a prim, instead of hovering above it. LSL doesn't seem to support choosing fonts and font sizes. So the way the generated sentences are displayed isn't very satisfying.
Does anyone have a suggestion? Of course I could make a jpg for every fragment of text, but I want to be able to add texts easily, so that isn't really an option.

Wolk
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-07-2008 16:34
From: wolk Writer
I wrote a random sentence generator, using a free script from my inventory. It works perfectly. The part of it that picks a random text from a list goes as follows:

string rnd(list lst)
{
lst=llListRandomize(lst,1);

return llList2String(lst,0);

}

string geteen()
{
list onderwerp = [
"A small but pregnant difference ",
"The recollection ",
"Such monstrous passion ",
"Nonsense ",
"Matter ",
"Something known only to yourself ",
"A silent wonder ",
"Everlasting happiness "];

return rnd(onderwerp);
}


I would like to make the sentences appear on a prim, instead of hovering above it. LSL doesn't seem to support choosing fonts and font sizes. So the way the generated sentences are displayed isn't very satisfying.
Does anyone have a suggestion? Of course I could make a jpg for every fragment of text, but I want to be able to add texts easily, so that isn't really an option.

Wolk


http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryXyText12
/invalid_link.html

and dont use jpg, its pointless in SL, your client compresses your images to jpg2000 before upload, so your just really adding noise to your images
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-07-2008 17:30
From: wolk Writer
I would like to make the sentences appear on a prim, instead of hovering above it. LSL doesn't seem to support choosing fonts and font sizes. So the way the generated sentences are displayed isn't very satisfying.
Does anyone have a suggestion? Of course I could make a jpg for every fragment of text, but I want to be able to add texts easily, so that isn't really an option.

Wolk

you can fake it appearing on the prim (although you can pick font size, but color is easy) by using hovertext on a hidden prim under where you want the text to appear on your visible prim. I do the same thing on my simple tp hud (code for which is on this forum)

if you need font and size options, you should look into XxyText (think I spelled that right), there should be some postings with links on the forum. it's the update to XyText, supposed to be more efficient, IIRC they both use specially formed prims.

PS, not sure why the list is being built in a function, instead of a global or right in whatever event might change it, and the other function should probably be rewriten as
CODE

string rnd(list lst){
return llList2String( llRandomizeList( lst, 1 ), 0 );
//--or really this is generally better form though an extra function call
// return llList2String( lst, (integer)llFrand( llGetListLength( lst ) ) );
//-- because it doesn't change the list item order, so other functions can get expected output from it
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
wolk Writer
Registered User
Join date: 4 Jun 2008
Posts: 4
11-07-2008 18:16
Hello Osgeld, that is rather complicated. I tried to do it, but it's full of bits and pieces that I don't understand. At the point where I got, I had one prim, with 5 large a's on it.
My generator generates rather long sentences, like "The recollection is a mystery, yet it's the only certainty we have."
As far as I can tell it would be hard to format such long texts with it.

Wolk
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-07-2008 21:20
it is, you would have to string prims to match the size of your text

about the only other way i can think to do it is to use a website

like with a php site + the gd lib (or imagemagik) you can have it create images on the fly (thats how they make those annoying captcha things)

ie this in php + libgd

CODE

<?php
// Create a 300x100 image
$im = imagecreatetruecolor(300, 100);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

// Make the background white
imagefilledrectangle($im, 0, 0, 299, 99, $white);

// Path to our ttf font file
$font_file = 'kawoszeh.GEN.ttf';

// Draw the text
imagefttext($im, 36, 0, 50, 55, $black, $font_file, 'example');

// Output image to the browser
header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);
?>


produces this

http://cheesefactory.us/filecenter/gd_example.php

then load them up on your prim as a web media, course then you would have to have access to the media controls on the land, and a web server thats scriptable and doesnt clutter up your pages with ad's
wolk Writer
Registered User
Join date: 4 Jun 2008
Posts: 4
11-08-2008 08:52
Osgeld, that is too advanced for me. I guess I'll have to wait till they add choosing fonts and fontsizes to lsl.

Void, that is what i did, but when you see the prim at an angle, the text isn't at an angle.
I hope the Lindens will realize soon that there's something missing from lsl...

Wolk
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-08-2008 09:21
From: Void Singer
PS, not sure why the list is being built in a function, instead of a global or right in whatever event might change it, and the other function should probably be rewriten as
CODE

string rnd(list lst){
return llList2String( llRandomizeList( lst, 1 ), 0 );
//--or really this is generally better form though an extra function call
// return llList2String( lst, (integer)llFrand( llGetListLength( lst ) ) );
//-- because it doesn't change the list item order, so other functions can get expected output from it
}

I guess my post #12 is invisible to the crowd today. You will see that the bitwise operator was correct and this bit : lList2String( llRandomizeList( lst, 1 ), 0 ); was already used.

Using llFrand is much less efficient and should only be considered if there actually are other functions that need to place a call to the lists and need them in a specific order.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-08-2008 09:56
I also forgot to mention jamieparsons that there is a tool that makes scripting LSL much easier:

http://www.lsleditor.org/

It gives you code highlighting, builtin function dictionary, syntax checking, code indent, and the ability to test a lot of scripts including this one. Plus you can save and write your scripts on your computer and take them with you without being tied to the SL client.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-08-2008 10:27
From: Jesse Barnett
I guess my post #12 is invisible to the crowd today. You will see that the bitwise operator was correct and this bit : lList2String( llRandomizeList( lst, 1 ), 0 ); was already used.

generally, yeah, list randomize is gonna be friendlier, except perhaps as the list gets bigger, and for future direct access to the list a'la updates / reusability. comp sci teachers tend to be big on both of those, so it's considered a bad habit to develop. hence the reason I placed it as a form over function issue, and demo'ed the version that an instructor would likely prefer.

my philosphy there is to get them doing it in the 'proper' form, but let them know there are alternatives... that way later, habit is to make code easier to reuse, and knowledge is there to tweak it if there's a performance need, or be able to tweak it back if reusability is required (like stripping older scripts for useful functions)

just my thought, I don't disagree in practice, listrandomize is a simpler solution, heaven's knows I've used it
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
1 2