Change font size
It is currently Mon Nov 19, 2018 10:35 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 2   [ 13 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Notecard Reader Script
PostPosted: Sat Oct 15, 2011 5:10 am 

Joined: Sun Mar 06, 2011 2:42 pm
Posts: 6
Hi all
Can anyone help please?... I am looking for a Notecard Reader Script that, upon touch, selects to read just one notecard, randomly, from a collection of notecards stored in the prim...
Then once it has selected the notecard... read lines from that notecard (in order of how they are typed), at timed intervals... say every 10 seconds.
Is this possible?
Thanks for any help given.
Geoff


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Sat Oct 15, 2011 11:02 am 

Joined: Sun Mar 06, 2011 2:42 pm
Posts: 6
Ok I have this so far, but need to add the random selection of one notecard from many in the same prim.... any ideas??


//This is the name of the notecard to read
string gCard = "Test Card";
//This is the pause between each line.
float gPause = 2;
//
key gReadKey;
integer gLine = 0;
default
{
touch_start(integer num_detected)
{
gLine = 0;
gReadKey = llGetNotecardLine(gCard, gLine);
gLine++;
}
dataserver(key queryid, string data)
{
if(queryid == gReadKey)
{
if(data != EOF)
{
llSay(0, data);
llSleep(gPause);
gReadKey = llGetNotecardLine(gCard, gLine);
gLine++;
}
}
}
on_rez(integer start_param)
{
llResetScript();
}
}


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Sun Oct 16, 2011 1:13 am 
OSG Elite
User avatar

Joined: Sat Jun 14, 2008 12:28 am
Posts: 384
Location: Australia
Here is my way of adding random selection of one of 3 notecards in the prims inventory,
llFrand will select a random floating decimal number and assign it variable FloatValue
We need to work with integer so we round the float to integer IntValue,
In this case IntValue will be an int between 0 and 2 (counting always begins with 0)
if you want 5 notecards, then use llFrand(4)
Change the names of the notecards if you like just ensure all names in inventory match names in script, delete line that announces what card is being read if you like (it is mainly for debug purposes)
{L_CODE}:
//This is the name of the notecard to read
string gCard ;//= "Test Card";
//This is the pause between each line.
float gPause = 2;
//
key gReadKey;
integer gLine = 0;
default
{   
touch_start(integer num_detected)
{
   float   FloatValue;
   integer IntValue;
        FloatValue  = llFrand(2);//change (2) to number of notecards minus 1 to account for number zero
        IntValue    = llRound(FloatValue);
             if (IntValue == 0) {gCard = "Test Card 1";}
       else if (IntValue == 1) {gCard = "Test Card 2";}
       else if (IntValue == 2) {gCard = "Test Card 3";}
      llSay(0, "reading from "+gCard);// remove this line if you like.
     
gLine = 0;
gReadKey = llGetNotecardLine(gCard, gLine);
gLine++;
}
dataserver(key queryid, string data)
{
if(queryid == gReadKey)
{
if(data != EOF)
{
llSay(0, data);
llSleep(gPause);
gReadKey = llGetNotecardLine(gCard, gLine);
gLine++;
}
}
}
on_rez(integer start_param)
{
llResetScript();
}
}

have fun


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Sun Oct 16, 2011 1:20 am 

Joined: Sat Jul 24, 2010 5:07 pm
Posts: 20
Dataservers are EVIL. They add more code to a script that should be really simple. Instead of using the dataserver to read the notecard, try something like this, showing you two methods of getting a notecard's contents :

{L_CODE}:
string NoteCardName = "testcard";
integer n;

default
{
    state_entry()
    {
        string NoteCardContents = osGetNotecard(NoteCardName); //Read the notecard, and store its contents in a string
        llOwnerSay(NoteCardContents); // Read the string to the owner of the object
       
    }
   
    touch_start(integer numdet)
    {
        integer NumLines = osGetNumberOfNotecardLines(NoteCardName);  // Get the number of lines in the notecard
        for(n=0;n<NumLines;++n)
        {
            string NoteCardLine = osGetNotecardLine(NoteCardName,n); // Read a single line from the notecard, and store it/
            llOwnerSay(NoteCardLine);   // Read the single line to the object's owner
        }       
    }
}


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Sun Oct 16, 2011 3:10 am 
OSG Elite
User avatar

Joined: Sat Jun 14, 2008 12:28 am
Posts: 384
Location: Australia
Hey Fritigern, good way to streamline the notecard system, I hadnt dealt with osGetNotecard functions yet, this looks like some good stuff.
Well Geoff, do you think you can combine this osGetNotecard script with the llFrand function on my mod, and the timer to your script, to create the script you need?
Also Geoff your script uses llSleep which tends to hog resources because the script constantly runs while it sleeps, its best to try to use a timer http://www.lslwiki.net/lslwiki/wakka.php?wakka=timer because the script releases the thread during the wait time and does not hog a thread constantly like llSleep.
This is only an issue if the script is expected to run for some time, if its just a short burst then llSleep is fine.


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Sun Oct 16, 2011 12:24 pm 

Joined: Sun Mar 06, 2011 2:42 pm
Posts: 6
Hi all
Just seen your posts... thanks everyone... I'll try the suggestions, and report back.
Thanks again
Geoff


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Mon Oct 17, 2011 4:02 am 

Joined: Sun Mar 06, 2011 2:42 pm
Posts: 6
Hi again
Cam.. your section of the script works great, but in answer to your question of combining Fritigerns amendment... no I cant... I just haven't got the scripting skills...
What I'm trying to do is create a game, using multiple prims (probably displayed as a hud) where the player touches one box, and gets text (from random notecards), which leads to a decision on which of the other boxes to press next...
This leads me to my next question...
If you imagine say 8 of the boxes, with the above script inside, in a row... is there a way of disabling boxes 2 to 7, until the random process reveals a certain word or line in box 1, at which point another box becomes "touchable"?
Thanks once again for all your help.
Geoff


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Mon Oct 17, 2011 9:11 am 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
You can do it, but it is not a simple task..

Basically, the easiest yet dirtiest way would be listeners.

The proper and low-lag way to do it would be to use Link Messages combined with touch_start and/or touch_end - assuming these boxes being part of a HUD are linked together.

So yes, I can see how you could do it, but that's a pretty lengthy group of scripts to just come up with and post. Maybe someone will have something similar already written up?

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Mon Oct 17, 2011 10:56 pm 
OSG Elite
User avatar

Joined: Sat Jun 14, 2008 12:28 am
Posts: 384
Location: Australia
I agree with Haplo, suddenly the scrips just got a whole lot more complicated, also there would need to be a different script in each of the 8 prims so they all behave differently, it is hard to think of a shortcut without knowing the exact requirements, from what you said, if behaviour of each prim is dependant on the result of another script, then it all becomes co-dependant and tricky, maybe post more info on the desired result and someone might come up with a simpler solution.
Regards
Cam


Top
 Profile  
 
 Post subject: Re: Notecard Reader Script
PostPosted: Tue Oct 18, 2011 6:34 am 

Joined: Sat Jul 24, 2010 5:07 pm
Posts: 20
I'm thinking of a combination of llSetLinkPrimitiveParams, and llDetectedLinkNumber, thus keeping everything in one single script.
I can't play with that right now, so i can't provide you with a complete an working script, but this should help anyone on their way who is willing to give it a go.
Otherwise, i will have to play with it once my life has become a lot less hectic. Although that could take a few more weeks, maybe months.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 13 posts ]
Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net