Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Touch as a toggle?

Sator Canetti
Frustrated Catgirl
Join date: 20 Sep 2005
Posts: 130
11-19-2005 09:34
I'm using code I've used before on other projects for the positioning and rotation, so I'm fairly sure that it works.

However, this time, I'm trying to use touch as a toggle instead of voice commands, and I am getting some weird behavior, like it running through the entire process 3 times before returning to it's original state.

the controller code:

CODE
string screen = "open";
default
{

touch_end(integer total_count)
{
if ( screen == "open")
{
llMessageLinked(-2, 0, "close", NULL_KEY);
screen = "closed";
}

if ( screen == "closed" )
{
llMessageLinked(-2, 0, "open", NULL_KEY);
screen = "open";
}
}
}
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
11-19-2005 09:39
try this

CODE
integer toggle;
default
{

touch_end(integer total_count)
{
if (toggle)
{
llMessageLinked(-2, 0, "close", NULL_KEY);
}

else
{
llMessageLinked(-2, 0, "open", NULL_KEY);
}
toggle = !toggle;
}
}


You will also want to compare llDetectedKey(0) with llGetOwner if you want to filter out all touches except for your own. Hope that helped.
_____________________
Sator Canetti
Frustrated Catgirl
Join date: 20 Sep 2005
Posts: 130
11-19-2005 09:46
Ah, yes, it does, thank you :D

As for owner only, I haven't decided if I will yet, and that stuff is easier to manage... for me it's just getting things to move around properly, then moving on to the control limits.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
11-19-2005 19:38
Hey, Cid, are your script able to reopen when it is closed?
I think it should be just replace "if ( screen == "closed" )" by "else if ( screen == "closed" )".

Sorry, Cid, I missed your "toggle = !toggle;" were out of if-else conditions. :o
_____________________
:) Seagel Neville :)
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
11-19-2005 20:30
There's another way to do this too, if you are interested. It involves states.

CODE

default
{
state_entry()
{
}

touch_start(integer numdetected)
{
// switch on.
state on;
}
}

state on
{
state_entry()
{
}

touch_start(integer numdetected)
{
// switch back to default.
state default;
}
}


There are many interesting things you can do with states depending on what you are trying to accomplish. Don't forget them! :D
Sator Canetti
Frustrated Catgirl
Join date: 20 Sep 2005
Posts: 130
11-19-2005 20:52
Well, it's just me closing a laptop cover.

But I'm a newbie scripter so I like any ideas on how to go about doing things.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-19-2005 21:27
pfft

CODE

integer toggle;
default
{
touch_end(integer total_count)
{
llMessageLinked(LINK_SET, 0, llList2String(["closed","open"], toggle = !toggle), NULL_KEY);
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-19-2005 21:29
CODE

integer v_state;

default
{
touch_start (integer whatever)
{
if (v_state == 0)
{
llWhatever(stuff);
v_state = 1;
}
else
{
llWhatever(stuff);
v_state = 0;
}
}


yet another way to do it (heh not really)
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
11-20-2005 03:14
From: Strife Onizuka
pfft

CODE

integer toggle;
default
{
touch_end(integer total_count)
{
llMessageLinked(LINK_SET, 0, llList2String(["closed","open"], toggle = !toggle), NULL_KEY);
}
}

Well played. :D
_____________________
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
11-20-2005 13:49
From: Strife Onizuka
pfft

CODE

integer toggle;
default
{
touch_end(integer total_count)
{
llMessageLinked(LINK_SET, 0, llList2String(["closed","open"], toggle = !toggle), NULL_KEY);
}
}
You're hoping that Mono will let you script in Perl, right? :)

Actually, that looks like something I'd have written ten or twenty years ago, back when I was an IOCCC finalist and seeing how much Postscript I could cram into the 4 lines allowed in a sigfile.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-20-2005 14:51
From: Argent Stonecutter
You're hoping that Mono will let you script in Perl, right? :)

Actually, that looks like something I'd have written ten or twenty years ago, back when I was an IOCCC finalist and seeing how much Postscript I could cram into the 4 lines allowed in a sigfile.


I grew up coding on a calculator that had very limited memory and it would leak memory. I learned how to write ugly tight code. C++ is my language of choice. I could care less about Perl; As long as the floating-point module that LL decides to use is decent i'll be happy.

LSL is an un-optimisized language at present.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
11-21-2005 08:36
Er, yeh, but even a simple code generator would generate pretty much the same code for the straightforward source and the "compressed" source.

Though I'm not much impressed by the LSL compiler technology. It seems to do greedy tokenization of negative numbers, so "i - 1" is legal but "i-1" is a syntax error because it's interpreting it as an identifier followed by a negative number.
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
11-21-2005 10:51
Strife wins. :D
Beatfox Xevious
is THOUSANDS OF PEOPLE
Join date: 1 Jun 2004
Posts: 879
11-21-2005 12:56
From: Zodiakos Absolute
Strife wins. :D

If we're judging by compactness of code, yes. If we're judging by readability (and, by extension, maintainability), I think the prize would go to you here. :)
_____________________
My Beatworks: Zephyr Chimes wind chimes, the KanaMaster Japanese kana tutor, and the FREE Invisibility Prim Public. Look for them at the Luskwood General Store in Lusk (144, 165).

"You have been frozen. You cannot move or chat. A pony will contact you via instant message (IM)."
- mysterious system message I received after making off with Pony Linden
Lindsey Dassin
Fallen Angel
Join date: 14 Sep 2005
Posts: 33
11-21-2005 13:26
From: Strife Onizuka
pfft

CODE

integer toggle;
default
{
touch_end(integer total_count)
{
llMessageLinked(LINK_SET, 0, llList2String(["closed","open"], toggle = !toggle), NULL_KEY);
}
}


Wow, your response looks a lot like what first came to mind for me:

CODE

list TOGGLE_STATUS = [ 0xdeadbeef, 0xfeedface ];

integer toggle;

default {
touch_end( integer total_num ) {
toggle = !toggle;

llMessageLinked( LINK_SET,
llList2Integer( TOGGLE_STATUS, toggle ),
"",
NULL_KEY
);
}
}


The biggest difference that i see is that i did integers instead of strings. This is because i've done enough C programming to distrust and stray away from strings wherever humanly possible. However it is that LSL does its message passing, comparison, assignment, etc., a four-byte integer has got to be more efficient than a string of characters.

It would be really nice to be able to write assembly for whatever byte-code LSL scripts translate to. That way if you needed something efficient it wouldn't have to be uber-ugly-tight ... or otherwise weird looking. LSL scripts for self-documenting code, LSL assembly for efficiency.