Wednesday, June 19, 2013

Full Erupt Mode: Part IV. The Hard Part

Scripting is a bitch!

I mean ONE little typo and...

The scripts I write aren't full of the estoteric database calls the whizbang kids use, but they're complex. My scripts create sounds, particles, and movement, and only when they're supposed to. Before, every prim that needed to act required its own simple script. Since Linden Lab introduced the llSetLinkPrimitiveParams and llSetLinkPrimitivePramsFast commands, I'm using one script per linkset-- and it has to talk to its child prims and to other linksets as well.

It's complicated to, say, script a broom that grabs itself and sweeps the floor or a rocket that blasts you into the stratosphere or a giant electromagnet that grabs a robot, moves 80 meters, and drops that robot into a bin, then moves back to its original position, ready to do it all again.

I do use listens when linksets are far from one another, as in the electromagnet, which is is a couple of dozen meters from its controller. I used quite a few-- twenty, maybe-- at the robot sanatorium, but then it's one of the most highly interactive places in Second Life. I used, I think, four for controlling the volcano Pele.

Pele has four modes-- extinct, inactive, active, and erupt. The rocks and lava have a distinct texture for each mode. The lava is solid when the volcano is inactive or extinct, and phantom when she's active and erupting. Pele creates hissing and rumbling sounds when active (and a huge roar when she's erupting); inactive and extinct modes are silent, with no particles. Active calls little puffs of light gray smoke, and erupt mode makes huge clouds of black smoke.

Above the caldera, five tiki masks hold stones in their mouths, letting onlookers know their function. Touch the tiki, and you change the mode. The mode remains set for three minutes, then Pele becomes active again. I like her best in active mode.

The fifth mask makes Pele throw huge smoking, steaming boulders dozens of meters into the air. It functions only when Pele is in active or erupt modes. The launchers, phantom and invisible, are inside the lava pool and the rocks can't escape when the lava is solid. That's why the rock launcher is turned off in active and erupt modes.

Touching a mask makes a number of things happen. First, the lava in the caldera is set accordingly, and smoke and sound turned on or off, as appropriate. Texture animation is switched on or off. Liquid lava moves; solid lava doesn't. The rocks lining the volcano also change texture-- and as of the other night, the lava flow that falls 60 meters to sea level changes mode accordingly

Scripting all this required a lot of attention to detail, and it was complex, but not all that complicated. By that I mean a lot is going on, but I'm really changing only a few characteristics of the prims-- color, texture, texture movement, transparency, brightness and glow, and switching sound and particles on and off.

When a mask is touched, it chats a command word. A script in a sixth tiki mask hears it and relays the command the three linksets that change the rocks and lava. Then it sets its timer to zero. If it hasn't heard another command by the time the timer reaches 180 seconds, it sets the lava to active mode. Three linksets-- the lava in the caldera, the rocks in the caldera, and the prims in the lava flow, listen and change the prims when they hear the command to change mode.

In Pele's initial erupt mode on Whimsy, I didn't include the relay. Poor Pele grew confused when masks were repeatedly touched. Each mask did its own counting, so if a visitor selected inactive and then, 160 seconds later, extinct, Pele would go active just 20 seconds later. Now the modes last the full three minutes, unless another mask is touched, in which case the mode will change immediately and the newly selected mode will last for three minutes.

I'm happy to say the scripting is all done-- it took perhaps four hours, but then the already existing erupt mode provided much of the code. Barring weirdness like solid rock moving or liquid rock not moving, smoke where there shouldn't be smoke, and silence where there should be sound, Pele has a new and improved erupt mode.

No comments: