Skip to content

Instantly share code, notes, and snippets.

@antonyfairport
Created March 9, 2015 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonyfairport/b28961dac515861040fd to your computer and use it in GitHub Desktop.
Save antonyfairport/b28961dac515861040fd to your computer and use it in GitHub Desktop.
Quick and dirty RLV command line. Drop in a prim, touch to turn on, say RLV commands in local.
//////////////////////////////////////////////////////////////////////
// RLV REPL
// By Antony Fairport
//
// RLV REPL - Quick and dirty "REPL" for testing RLV commands.
//
// Revision history:
// ------------------------------------------------------------
//
// 2015-03-09
// Initial revision.
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Start out in the idle state.
state Idle;
}
}
//////////////////////////////////////////////////////////////////////
// Idle state.
state Idle
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Show that we're idle.
llSetColor( < 1.0, 0.0, 0.0 >, ALL_SIDES );
llSetText( "RLV REPL idle", < 1.0, 0.0, 0.0 >, 1.0 );
}
//////////////////////////////////////////////////////////////////
// Handle a touch event.
touch_end( integer _ )
{
// If it's our owner touching us...
if ( llDetectedKey( 0 ) == llGetOwner() )
{
// ...fire up the REPL.
state REPL;
}
}
}
//////////////////////////////////////////////////////////////////////
// Active REPL state.
state REPL
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Show that we're working.
llSetColor( < 0.0, 1.0, 0.0 >, ALL_SIDES );
llSetText( "Listening for RLV commands from\n" + llKey2Name( llGetOwner() ), < 0.0, 1.0, 0.0 >, 1.0 );
// Listen to local chat from the owner.
llListen( 0, "", llGetOwner(), "" );
}
//////////////////////////////////////////////////////////////////
// State exit.
state_exit()
{
// Ensure all restictions are cleared.
llOwnerSay( "@clear" );
}
//////////////////////////////////////////////////////////////////
// Handle incoming listen events.
listen( integer channel, string name, key id, string message )
{
// Local chat?
if ( channel == 0 )
{
// Belt and braces. Yes, I know, we filter when we make the
// listen but, hey, it can't hurt to be really sure, right?
if ( id == llGetOwner() )
{
// Looks like an RLV command?
if ( llGetSubString( message, 0, 0 ) == "@" )
{
// Seems so.
llOwnerSay( message );
llOwnerSay( "Executed: " + message );
}
}
}
}
//////////////////////////////////////////////////////////////////
// Handle a touch event.
touch_end( integer _ )
{
// If it's our owner touching us...
if ( llDetectedKey( 0 ) == llGetOwner() )
{
// ...go idle.
state Idle;
}
}
//////////////////////////////////////////////////////////////////
// Handle changes.
changed( integer change )
{
// Owner has changed?
if ( change & CHANGED_OWNER )
{
// They have. Reset all the things.
llResetScript();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment