Change font size
It is currently Tue Jul 17, 2018 11:28 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 4 posts ]
Author Message
 Post subject: Broken fluorescent light script
PostPosted: Fri Aug 05, 2011 12:03 pm 
OSG Elite

Joined: Wed Aug 05, 2009 1:59 am
Posts: 417
My first, self made, script ever!! 8-)

It isn't the best of all scripts in the known universe, but it seems to do what want it to do! (self-hug to oddy!)

I wanted to make a broken fluorescent light, that randomly turns on and off..
Here it is:

{L_CODE}:
//--------------------------------------
// Random Prim Glow (on/off) and lightning (on/off
// By Oddball Otoole
//--------------------------------------
// This program is free software; you can redistribute it and/or modify it.
// License information must be included in any script you give out or use.
// This script is licensed under the Creative Commons Attribution-Share Alike 3.0 License
// from http://creativecommons.org/licenses/by-sa/3.0 unless licenses are
// included in the script or comments by the original author,in which case
// the authors license must be followed.

//-------------------------------------
//Global Variables
float glow;
float time;

//-------------------------------------
// Main program
default
{
    state_entry()
    {
  llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
        state begin;
    }
}

//-------------------------------------
// Begin state
state begin
    {
        state_entry()
        {
        glow = (integer) llRound(llFrand(1)); // Random on or off
        time = (float) llFrand(2); // Random wait time
            llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, glow]); //Set Prim glow on/off
            llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 1.0>, glow, 5.0, 0.5]); // Set prim light on/of
            state wait; // Go to the Wait State
        }
    }

//-------------------------------------
// Wait state
state wait
    {
        state_entry()
        {
            llSetTimerEvent(time); //Wait
        }
        timer()
        {
           llSetTimerEvent(0.0); //remove the timer
           state begin; // Go back to the Begin State
        }
    }



Last edited by Oddball Otoole on Sat Feb 04, 2012 5:06 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Broken fluorescent light script
PostPosted: Thu Sep 15, 2011 2:34 am 

Joined: Fri Jul 09, 2010 12:15 am
Posts: 33
Looks good! Congrats on writing your first script.

One suggestion... llSleep is best avoided if possible, as it doesn't *really* make your script sleep, but runs null operations until it's time for your script to resume (as I understand it). I've heard that it's better to use a timer when possible. If you felt like it, you could re-write the "wait" state to the following:

{L_CODE}:
state wait
    {
        state_entry()
        {
            llSetTimerEvent(time); //Wait
        }
        timer()
        {
           llSetTimerEvent(0.0); //remove the timer
           state begin; // Go back to the Begin State
        }
    }


Top
 Profile  
 
 Post subject: Re: Broken fluorescent light script
PostPosted: Thu Sep 15, 2011 8:17 am 
OSG Elite

Joined: Wed Aug 05, 2009 1:59 am
Posts: 417
Thanks for the tip Joe!

Odd.


Top
 Profile  
 
 Post subject: Re: Broken fluorescent light script
PostPosted: Thu Sep 15, 2011 5:00 pm 

Joined: Fri Jul 09, 2010 12:15 am
Posts: 33
No problem! Feel free to contact me if you ever need help with something scripting related.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 4 posts ]


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:  
cron


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