|
Electra Rehula
Registered User
Join date: 17 May 2007
Posts: 9
|
05-23-2007 06:29
i created a very simple script for a sliding door using llMovetotarget. The program works perfectly, need to set the two door positions, opened ed closed moving it in edit mode. Then the position are toggles touching in it. But the strange (for me) is that exiting from edit the doors back in its older position and if i reset the script it's fly away always leaving the object edit mode. I checked that my function aren't called. someone can help me? integer door_state=0; integer work_mode=0; vector opened_position=<0,0,0>; vector closed_position=<0,0,0>; default { state_entry() { llListen(0, "", "", ""  ; door_state=0; work_mode=0; } listen(integer channel, string name, key id, string message) { if ( ".set_closed_pos" == llGetSubString(message, 0, 15) ) { llSay(0,"Closed position setted"  ; closed_position = llGetPos(); } if ( ".set_opened_pos" == llGetSubString(message, 0, 15) ) { llSay(0,"Opened position setted"  ; opened_position = llGetPos(); } if ( ".set_work_mode" == llGetSubString(message, 0, 14) ) { llSay(0,"Work Mode Enabled"  ; work_mode=1; } if ( ".set_edit_mode" == llGetSubString(message, 0, 14) ) { llSay(0,"Edit Mode Enabled"  ; work_mode=0; } } touch_start(integer total_number) { if (work_mode==0) {llSay(0,"Set work mode to take control"  ; return; } llSetStatus(STATUS_PHYSICS | STATUS_PHANTOM, TRUE); if (door_state==0) { llMoveToTarget(opened_position,1); door_state=1; } else { llMoveToTarget(closed_position,1); door_state=0; } } }
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-23-2007 06:56
If you reset the script ALL variable data is reset i.e. your positions are cleared to 0,0,0
_____________________
I'm back......
|
|
Electra Rehula
Registered User
Join date: 17 May 2007
Posts: 9
|
05-23-2007 08:54
no, isn't a reset variables problem, and the reset condiction is handled by the variable work_mode.
|
|
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
|
05-23-2007 09:41
Electra, in the future please put your script between "[php ]" and "[/php]" tags (omitting the space), so that we can read it easily. Thanks!
BTW, past tense of "set" is also "set", not "setted".
I can't see what's causing your problem. Be sure to try again; sometimes SL is acting up.
And I bet you know better than to leave that open listen in once you're finished.
|
|
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
|
05-23-2007 10:50
From: Learjeff Innis Electra, in the future please put your script between "[php ]" and "" tags (omitting the space), so that we can read it easily. Thanks!
[/php] Check the Linden post on the top of all the forums, all codes are currently disabled. Electa: First, you should be using else if statements within your listen event, that will reduce the processing required for your script. Not a huge deal, but it adds up. Secondly, you shouldn't manually Edit the positions of objects that are being moved by script. Not at the same time at least. Third, you have nothing stopping work_mode from being toggled before your other positions being set. Meaning the door could very well be moving itself to 0,0,0. Forth, llInstantMessage or llWhisper would be better than your llSay to reduce spam. But you may only have those in there for debugging. Fifth, try using the at_target and not_at_target events. Currently you never stop the llMoveToTarget so even after it reaches its goal, it will still be eating up CPU and if its manually Edited later it will likely try to get back to that position. This force is probably continuing even after a script reset, it may just be trying to reach the <0,0,0> loc at that point. So make sure you are calling llStopMoveToTarget(); From the Wiki for llMoveToTarget: "Note: The force created by calling this function persists until llMoveToTarget is called again with another target, is called with a tau of 0.0, or llStopMoveToTarget is called. This can be either helpful or hindersome, especially when using a combination of llApplyImpulse and llMoveToTarget."
|
|
Electra Rehula
Registered User
Join date: 17 May 2007
Posts: 9
|
05-24-2007 05:45
I found the bug, problems is that after used llmovetarget the Physics status must be resetted: ----- > llSetStatus(STATUS_PHYSICS|STATUS_PHANTOM, FALSE); in this way all works perfectly here the code without bugs:
//**************** EDITABLE ZONE *****************************
list admitted=[
"xxxxxxxx yyyyyyy", "zzzzzzzzz hhhhhhh", "sssssssss jjjjjjjjjjjjj"
// Add name : "Name", Max 100 names // Last name without coma
];
integer speed=1; // Speed Default=1 - Range from 0.1 to 10
//************** END EDITABLE ZONE ****************************
integer door_state=0; integer work_mode=0;
vector opened_position=<0,0,0>; vector closed_position=<0,0,0>;
// is name on admitted list? integer check_admitted_list (string name) { if ( llListFindList(admitted, [name]) >= 0 ) { return TRUE; } else { return FALSE; } }
default { on_rez(integer arg) { llResetScript(); } state_entry() { llListen(0, "", "", ""); llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE); llSetStatus(STATUS_PHYSICS, FALSE); door_state=0; work_mode=0; llSay(0,"Portable Sliding Door"); llSay(0,"Commands: '.set_edit_mode' , '.set_work_mode' , '.set_opened_pos' , '.set_closed_pos'"); } listen(integer channel, string name, key id, string message) { if ( ".set_closed_pos" == llGetSubString(message, 0, 15) ) { if (work_mode) return; llSay(0,"Closed position recorded"); closed_position = llGetPos(); llSetStatus(STATUS_PHYSICS, FALSE); llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE); } if ( ".set_opened_pos" == llGetSubString(message, 0, 15) ) { if (work_mode) return; llSay(0,"Opened position recorded"); opened_position = llGetPos(); llSetStatus(STATUS_PHYSICS, FALSE); llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE); } if ( ".set_work_mode" == llGetSubString(message, 0, 14) ) { if (opened_position==<0,0,0> ) return; if (closed_position==<0,0,0> ) return; llSay(0,"Work Mode Enabled"); work_mode=1; llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE); } if ( ".set_edit_mode" == llGetSubString(message, 0, 14) ) { llSay(0,"Edit Mode Enabled"); work_mode=0; llSetStatus(STATUS_PHYSICS, FALSE); }
if ( ".reset_position" == llGetSubString(message, 0, 15) ) { if (closed_position==<0,0,0> ) return; work_mode=0; llSetStatus(STATUS_PHYSICS, TRUE); llSetPos(closed_position); llSetStatus(STATUS_PHYSICS, FALSE); }
}
touch_start(integer total_number) { // When touched, check the position of // the object, save it to "position", // then convert it into a string and // say it. if (work_mode==0) {llSay(0,"Set work mode to take control"); return; } string name = llDetectedName(0); if (!check_admitted_list (name)) { llSay(0,"Sorry you can't control this door"); return; } llSetStatus(STATUS_PHYSICS|STATUS_PHANTOM, TRUE); if (door_state==0) { llMoveToTarget(opened_position,speed); door_state=1; } else { llMoveToTarget(closed_position,speed); door_state=0; } } moving_end() { llSetStatus(STATUS_PHYSICS|STATUS_PHANTOM, FALSE); if (work_mode==0) return; if (door_state) llSetPos(opened_position); else llSetPos(closed_position); } }
|