Jump to content

Need help with script to read notecard and call get a name and replace a holder name....


msw Tomorrow
 Share

You are about to reply to a thread that has been inactive for 4377 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I need help with how to insert a portion of script that will read a notecard and replace a place holder name in the primary script. I am trying to be able to load an object with options and have the note card modifiable to pick particular options. I am a very novice scripter with big ideas :-) Primary script below:

integer MSW_DELAY = 2;
integer ready = TRUE;

SetAlpha(integer bool)
{
	float alpha1;
	float alpha2;
	if (bool == TRUE)
	{
		alpha1 = 0.0;
		alpha2 = 1.0;
	}
	if (bool == FALSE)
	{
		alpha1 = 1.0;
		alpha2 = 0.0;
	}
	}

default
{
	state_entry()
	{
		ready = FALSE;
		llSetStatus(STATUS_PHANTOM, TRUE);
		SetAlpha(ready);
	}

	on_rez(integer param)
	{
		}		}

	touch_start(integer total_number)
	{
		if (ready)
		{
			ready = TRUE;
			//llSleep(5.0);
			llSetStatus(STATUS_PHANTOM, FALSE);
			llSetTimerEvent(2);
			//llTriggerSound("switch", 1.0);
			vector pos = llGetPos();
			pos.z += 0.8;
			pos.x -= 0.2;
			llRezObject("RD1", llGetPos() + <0.0, 0.0, 3.5>, <0.0, 0.0, 20.0>*llGetRot(), llGetRot(),2);
			ready = FALSE;
			llSetTimerEvent((float)MSW_DELAY);
			llSleep(2);
			llRezObject("RD2", llGetPos() + <0.0, 0.0, 3.5>, <0.0, 0.0, 21.0>*llGetRot(), llGetRot(),2);
			llSleep(2);
			llRezObject("RD3", llGetPos() + <0.0, 0.0, 3.5>, <0.0, 0.0, 23.0>*llGetRot(), llGetRot(),2);
			llSleep(2);
			llRezObject("RD4", llGetPos() + <0.0, 0.0, 3.5>, <0.0, 0.0, 21.0>*llGetRot(), llGetRot(),2);
			llSleep(2);
			llRezObject("RD5", llGetPos() + <0.0, 0.0, 3.5>, <0.0, 0.0, 22.0>*llGetRot(), llGetRot(),2);
			llSleep(1);
			llRezObject("RD6", llGetPos() + <0.0, 0.0, 3.5>, <0.0, 0.0, 20.0>*llGetRot(), llGetRot(),2);
		}
		else if (ready == TRUE)
		{
			ready = FALSE;
		}
		SetAlpha(ready);
		//  ready = FALSE;
		llSetTimerEvent((float)MSW_DELAY);
	}
		timer()
	{
		llSetStatus(STATUS_PHANTOM, TRUE);
		llSetTimerEvent(0.0);
		ready = TRUE;
	}
}

 

It is the RD1, RD2 etc that I want the note card to define. SO the note card would say something like:

RD1 = Object1

RD2 = Object5

etc....

So I need to addsometing to the above script to have it read the note card and replace that variable? Any help would be appreciated. Thank you!

Link to comment
Share on other sites

Did you locate a notecard reading script? Post the code and tell us what you don't understand. Most likely, you're going to have an initialization routine that is executed first. It reads a notecard in the inventory of the prim and sets some variables based on what is read from the notecard. Thereafter, your script proceeds as usual.

ETA: 

OK, from your reposted script, you already have a subroutine called SetAlpha. Create another called ReadNotecard or something.

You have on_rez in your script already. Revise your script so that ReadNotecard gets excecuted when the object is rezzed.

Link to comment
Share on other sites

Here is how to read data from a notecard.

I have made the "things that will be rezzed" a list so you can change this.  I also note that the position, rotation and start-parameter for each rezzed object is the same but that the velocities are different.  Expecting that might change depending on the object this script will read them from the notecard too.  Each line of the notecard should therefore be formatted as <Placeholder> = <Object Name> = <Velocity>, (eg; RD1 = First Object = <0.0, 0.0, 20.0>)

I've taken out your SetAlpha() as it does nothing and I couldn't see what you were trying to do with the timer and phantom settings so you'll probably want to add them back in.  In addition I've ignored the fact that you only have a 1s pause before rezzing the last object; I've just made them all the same for simplicity.  If those will change too you might like to add them to the notecard in the same way as Velocities have been added in this example.

integer NoteLine;string NoteName = "Notecard Name Here"; // <== Edit thiskey NoteRequest;list Placeholders = ["RD1", "RD2", "RD3", "RD4", "RD5", "RD6"];	// <== Anything, in the order to be rezzedlist Objects;list Velocities;default{	dataserver(key ResponseID, string Data){		// Check that the response ID matches the request		if(ResponseID == NoteRequest){			if(EOF == Data){				// Ready to go				llOwnerSay("Notecard read");			}else{				// Notecard format <Placeholder> = <Object> = <Velocity>				// First, split the data into the parts before and after '=', with or without spaces				list Parts = llParseString2List(Data, [" = ", " =, "= ", "=], []);				// Then see if the first part (<Placeholder>) is a valid one				integer Index = llListFindList(Placeholders, llList2List(Parts, 0, 0));				if(-1 != Index){					// Make sure the named object is in inventory					string Name = llList2String(Parts, 1);					if(llGetInventoryType(Name) == INVENTORY_OBJECT){						// Replace the 'bad' name and velocity with the specified ones						Objects = llListReplaceList(Objects, [Name], Index, Index);						Velocities = llListReplaceList(Velocities, [(vector) llList2String(Parts, 2)], Index, Index);					}				}				// Request the next notecard line				NoteRequest = llGetNotecardLine(NoteName, ++NoteLine);			}		}	}	state_entry(){		// Empty the lists of object details, then re-create them with 'bad' values		Objects = [];		integer Counter = llGetListLength(Placeholders);		while(Counter--){			Objects += ["Unknown"];			Velocities += ["Unknown"];		}		// Start reading from the first (0) notecard line, record the request UUID		NoteRequest = llGetNotecardLine(NoteName, (NoteLine = 0));	}	touch_end(integer HowMany){		// Initialise object-counter and position-offset		integer Counter;		string Name;		vector Position = llGetPos() + <0.0, 0.0, 3.5>;		rotation Rotation = llGetRot();		for(Counter = 0; Counter < llGetListLength(Objects); Counter++){			// Check each object has a valid name			Name = llList2String(Objects, Counter);			if("Unknown" != Name){				// Rez it and pause				llRezObject(Name, Position, llList2Vector(Velocities, Counter) * Rotation, Rotation, 2);				llSleep(2.0);			}		}	}}

 

Link to comment
Share on other sites

Correction to script: In the state_entry() event-handler the line "Velocities = [];" should follow "Objects = [];", although the script will work as written because an empty list is the default. (In practice you'd want to re-read the notecard when it's edited, etc.  With that sort of change you'd need to make sure the lists are re-initialised to blank and if you don't put that sort of thing in from the beginning it's bound to trip you up later.)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4377 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...