Difference between revisions of "User:DoteDote Edison"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 5: Line 5:
Not a Wiki pro, so using this page to figure out how to format properly.
Not a Wiki pro, so using this page to figure out how to format properly.


<(pre)>...<(/pre)> works for script formatting until <(lsl)>...<(/lsl)> is up.
====Example Scripts for the Examples page once it's formatted:====
=====Toggle On/Off via State=====
An example script showing how [[state]] changes can be a useful method to switch between two script modes, in this case, On or Off.  When the script first runs, it begins in the '''default''' state and the [[state_entry]] event is executed. When a user interacts with the object by touch, the script switches to the '''on''' state. The '''on''' state executes its state_entry event, then waits for a user touch to trigger a state change back to the '''default''' state.
<pre><lsl>
// Toggle On-Off via State


Also, I made a header/footer with links to common pages, since there didn't seem to be a way to get back to [[LSL Portal]].
default {
    state_entry() {
// run this code when entering the default state
// displays red "OFF" as floating text above the prim
llSetText("OFF", <1,0,0>, 1.0);
}
    touch_start(integer num_detected) {
// when touched, switch to state named 'on'
state on;
}
}
 
state on {
state_entry() {
// run this code when entering state 'on'
// displays green "ON" as floating text above the prim
llSetText("ON", <0,1,0>, 1.0);
}
touch_start(integer num_detected) {
// when touched, switch to the default state
state default;
}
}
</lsl></pre>

Revision as of 18:11, 30 January 2007


Not a Wiki pro, so using this page to figure out how to format properly.

Example Scripts for the Examples page once it's formatted:

Toggle On/Off via State

An example script showing how state changes can be a useful method to switch between two script modes, in this case, On or Off. When the script first runs, it begins in the default state and the state_entry event is executed. When a user interacts with the object by touch, the script switches to the on state. The on state executes its state_entry event, then waits for a user touch to trigger a state change back to the default state.

<lsl>
// Toggle On-Off via State

default {
    state_entry() {
		// run this code when entering the default state
		// displays red "OFF" as floating text above the prim
		llSetText("OFF", <1,0,0>, 1.0);
	}
    touch_start(integer num_detected) {
		// when touched, switch to state named 'on'
		state on;
	}
}

state on {
	state_entry() {
		// run this code when entering state 'on'
		// displays green "ON" as floating text above the prim
		llSetText("ON", <0,1,0>, 1.0);
	}
	touch_start(integer num_detected) {
		// when touched, switch to the default state
		state default;
	}
}
</lsl>