Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help with note card reader

wholesale Bing
Registered User
Join date: 27 Jun 2007
Posts: 24
09-13-2007 16:15
ok before you read my cut and paste attempt at coding ,and spit out your coffee you been drinking , exclaiming " what a idiot ! " , ill explain i never really progressed from programing my spectrum 25yrs ago , everyone moved away from basic ,and c left me scratching my dumb head ,im finding this sl scripting just as confusing .


can,t get this to work ,want the lift to go ,as high as what is written in a note card called fred


CODE



// SN_Elevator was made by Seagel Neville as public domain, Dec 2005.

list heightList = [data]; // You have to put down the height of each floor here
list menuList = ["go up"]; // Dialog box's list. Go along with heightList.

key av;
float height;
integer CHANNEL;
integer HANDLE;
vector StartPos;

StopSitAnim() // Don't sit on the floor.
{
llStopAnimation("sit_generic");
llStopAnimation("sit");
llStartAnimation("impatient"); // Needed keyframes of legs' parts.
} // If you want to know this more, make sure to replace this for "stand".














ElevatorMove()
{
vector TargetPos = <StartPos.x, StartPos.y, StartPos.z + height>;
while(llVecDist(llGetPos(), TargetPos) != 0)
{
llSetPos(TargetPos);
}
llUnSit(av);
llSleep(1);
while(llVecDist(llGetPos(), StartPos) != 0)
{
llSetPos(StartPos);
}
}

key kQuery;
integer iLine = 0;


key kQuery;
integer iLine = 0;
default {

state_entry() {
llSay(0, "Reading notecard...");
kQuery = llGetNotecardLine("FRED", iLine);
}

dataserver(key query_id, string data) {

if (query_id == kQuery) {
// this is a line of our notecard
if (data == EOF) {

llSay(0, "No more lines in notecard, read " + (string)iLine + " lines.");

} else {

// increment line count
llSay(0, "Line " + (string)iLine + ": " + data);

//request next line
iLine++;
kQuery = llGetNotecardLine("FRED", iLine);

}
}
}








{
llSay(0, "Reading notecard...");
kQuery = llGetNotecardLine("FRED", iLine);
}

dataserver(key query_id, string data) {

if (query_id == kQuery) {
// this is a line of our notecard
if (data == EOF) {

llSay(0, "No more lines in notecard, read " + (string)iLine + " lines.");

} else {

// increment line count
llSay(0, "Line " + (string)iLine + ": " + data);

//request next line
iLine++;
kQuery = llGetNotecardLine("FRED", iLine);

}
}
}










llSetSitText("Get on");
StartPos = llGetPos();
}
// look
llSitTarget(<0, 0, 1.0>, ZERO_ROTATION);
}
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
av = llAvatarOnSitTarget();
if(av != NULL_KEY)
{
llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
}
}
}
run_time_permissions(integer perm)
{
StopSitAnim();
CHANNEL = llRound(llFrand(1000000) - 10000000);
HANDLE = llListen(CHANNEL, "", "", "");
llDialog(av, "To what floor do you go?", menuList, CHANNEL);
}
listen(integer channel, string name, key id, string message)
{
height = llList2Float(heightList, llListFindList(menuList, [message]));
llListenRemove(HANDLE); // Is this a manner?
ElevatorMove();
}
}
}


}
CODE
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
09-13-2007 19:19
Sorry, I can't be bothered to try to read the code above since it's so mangled.

Normally we can read the code with indentation by hitting the "Quote" button, but it doesn't help in this case -- evidently you pasted it in without good indentation.

Here's what I use for reading configuration. It reads all cards with ".cfg" in the name and processes them all the same way. Might be a little more sophisticated than you need but should serve the purpose.

CODE

// Multi-file configuration
// Learjeff Innis, 2007

// Places where you change the code are marked with "%%%"

// Example config variables -- replace these with meaningful stuff! %%%

// For this example, we allow the user to configure any number of "foos",
// with an integer parameter for each foo. There's also a float "bar"
// parameter.

list Foos; // all foos configured
list FooVals; // value for each foo configured
float Bar; // a configurable parameter

// Static parameters for reading card config %%%
integer ConfigRequired = FALSE; // whether to fail if no config cards
string ConfigNotecardSuffix = ".cfg"; // string identifying config notecards
float ConfigTimeout = 60.0; // seconds per card to wait for slow server

// Globals for reading card config
integer ConfigLineIndex;
key ConfigRequestID;
list ConfigCards; // list of names of config cards
string ConfigCardName; // name of card being read
integer ConfigCardIndex; // index of next card to read

integer Debug; // Whether to print debug text


config_init()
{
say(NULL_KEY, "Reading configuration");
// Initialize all configurable global variables here %%%
Foos = [];
Bar = 20.7;
}

// print the configuration -- primarily for debugging.

config_dump(key id)
{
// Replace this example code with your config %%%
say(id, "Foos: " + llList2CSV(Foos));
say(id, "FooVals: " + llList2CSV(FooVals));
say(id, "Bar: " + (string) Bar);
}


// Example notecard line parser.
//
// Comments lines begin with a slash
// Each line begins with a command followed by optional arguments
// Equals-sign ("=") separates command and arguments (and args from each other)
// Unrecognized commands are ignored -- good for forwards-backwards notecard compatibility
// cardName and lineNum are in case you want to print error messages.

config_parse(string str, string cardName, integer lineNum)
{
str = llStringTrim(str, STRING_TRIM_HEAD); // delete leading spaces

// lines beginning with slash are comments -- ignore them
if (llGetSubString(str,0,0) == "/") {
return;
}

list ldata = llParseString2List(str, ["="], [""]);
string cmd = llList2String(ldata,0);
string arg1 = llList2String(ldata,1);
string arg2 = llList2String(ldata,2);

// Example commands -- replace this code with meaningful stuff! %%%

if (cmd == "foo") {
// another Foo configured: remember it
Foos += [arg1];
FooVals += [(integer) arg2];
} else if (cmd == "bar") {
Bar = (float) arg1;
}

// this one is a good one to keep
else if (cmd == "debug") {
Debug = (integer) arg1;
}
}


// Post-process any config, if necessary
config_done() {
if (Debug) {
config_dump(NULL_KEY);
}
}


// ==== Utilities ====

// Say something. If key is NULL_KEY, it whispers. Otherwise it IM's.
//
// You can make your object less chatty by commenting out the whisper,
// or using llSayOwner, or whatever.

say(key id, string str)
{
if (id == NULL_KEY) {
llWhisper(0, str);
} else {
llInstantMessage(id, str);
}
}

debug(string str)
{
if (Debug) {
llWhisper(0, llGetScriptName() + ": " + str);
}
}

// return TRUE if there is a config card

integer next_card()
{
if (ConfigCardIndex >= llGetListLength(ConfigCards)) {
return (FALSE);
}

ConfigLineIndex = 0;
ConfigCardName = llList2String(ConfigCards, ConfigCardIndex);
ConfigCardIndex++;
ConfigRequestID = llGetNotecardLine(ConfigCardName, ConfigLineIndex);
say(NULL_KEY, "Reading " + ConfigCardName);
return (TRUE);
}


// ========== STATES =============

// Default state can do any init you need that doesn't require configuration.

default
{
state_entry() {
state s_config;
}
}

// This state is only used to get into s_config, because going from
// s_config to s_config won't redo it's state_entry. But we might
// not want to redo anything we might have put in default state entry.

state s_reconfig
{
state_entry() {
state s_config;
}
}

// Read card config
// Multiple notecard version - read all cards with the given extension

state s_config
{
state_entry() {
llWhisper(0, "Reading configuration ...");
config_init();

string item;
ConfigCards = [];
integer n = llGetInventoryNumber(INVENTORY_NOTECARD);
while (n-- > 0) {
item = llGetInventoryName(INVENTORY_NOTECARD, n);
if (llSubStringIndex(item, ConfigNotecardSuffix) != -1) {
ConfigCards += [item];
}
}

ConfigCardIndex = 0;
if (next_card()) {
llSetTimerEvent(ConfigTimeout);
} else if (ConfigRequired) {
say(NULL_KEY, "Configuration notecard missing.");
state s_unconfigured;
} else {
state s_active;
}
}

dataserver(key query_id, string data) {
if (query_id == ConfigRequestID) {
if (data == EOF) {
if (next_card()) {
llSetTimerEvent(ConfigTimeout);
} else {
state s_active;
}
} else {
config_parse(data, ConfigCardName, ConfigLineIndex);
ConfigRequestID = llGetNotecardLine(ConfigCardName, ++ConfigLineIndex);
}
}
}

timer() {
say(NULL_KEY, "ERROR - Dataserver time out: touch to retry");
llSetTimerEvent(0);
}

touch_end(integer tot) { state s_reconfig; }

on_rez(integer num) { state s_reconfig; }

changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_reconfig; }
}

state_exit() {
llSetTimerEvent(0);
config_done();
}
}

// The fun starts here!

state s_active
{

// %%% Your code goes here!

// Every state should usually have this, or something like it.
changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_reconfig; }
}
}

// State to go into if notecard is required but missing.
// You can delete this and the code above that refers to it,
// or just set ConfigurationRequired to FALSE.
state s_unconfigured
{
state_entry() {
llSetText("Configuration missing", <1.0,1.0,1.0>, 1.0);
}

changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_reconfig; }
}

state_exit() {
llSetText("", <1.0,1.0,1.0>, 1.0);
}
}