llDialog Question
|
|
Bad Fluffy
Registered User
Join date: 21 Jan 2006
Posts: 13
|
10-13-2006 07:34
Quick question regarding menus, since I'm baffled by a problem I'm currently having. I'm working on sheathe/unsheathe scripts for a weapon I'm making, and obviously want to have a menu on both the sword and sheathe for controlling this... I've been using the script below (and tried a different approach later, to no avail) and can't see any flaws in it, but for some reason it's not communicating with my weapon. I've tested the menu on channel 0 and it says the commands there just fine, and I can only presume it's still talking on channel 7... So the problem might lie elsewhere, but that makes no sense... When I manually type out "/7 draw", it does it just fine... So it has to be this menu. Anyway, if someone could just tell me that everything down there is okay or not, I'll at least know where the problem lies. Would be much appreciated. integer dialog_channel= 22; list menu = [ "Draw", "Sheathe"]; default { state_entry() { llListen( dialog_channel, "", NULL_KEY, ""); }
touch_start(integer total_number) { llDialog( llDetectedKey( 0 ), "Options:", menu, dialog_channel ); }
listen(integer channel, string name, key id, string choice ) {
if ( llListFindList( menu, [ choice ]) != -1 ) { if ( choice == "Draw" ) { llSay(7,"Draw"); } else if ( choice == "Sheathe" ) { llSay(7, "Sheathe"); } } } }
|
|
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
|
10-13-2006 08:07
A couple of comments: I would suggest using negative channel numbers < -1000 or so to avoid cross talk. Avatars can't talk on negative channels. Is your weapon listening for "Draw" or "draw"?
|
|
Travis Lambert
White dog, red collar
Join date: 3 Jun 2004
Posts: 2,819
|
10-13-2006 08:11
The script you posted looks ok to me. One thought: Is this script going in the same object as your weapon? If so, objects can't listen to themselves. If you want to communicate script to script within the same object, use llMessageLinked(). MessageLinks are far superior to listens when you can use them. Good luck! 
_____________________
------------------ The ShelterThe Shelter is a non-profit recreation center for new residents, and supporters of new residents. Our goal is to provide a positive & supportive social environment for those looking for one in our overwhelming world.
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
10-13-2006 08:45
Because llDialog makes your AV say the content of pressed buttons, this can be simplified to: integer command_channel= 7 list menu = [ "Draw", "Sheathe"]; default {
touch_start( integer total_number ) {
key contact = llDetectedKey(0); if( contact != llGetOwner() ) return; // ignore other people llDialog( contact, "Options:", menu, command_channel ); } }
with this approach your AV should issue command which can be recognized by the weapon itself directly on the weapon's command channel, skips the unnecessary listen() and comparisons ^^;
|
|
Bad Fluffy
Registered User
Join date: 21 Jan 2006
Posts: 13
|
10-13-2006 17:15
Hm... No joy. Here's what I just attempted, with the negative channel since I don't want to be say-spamming the commands, it's tacky. For clarification, the weapon is its own object, the sheathe is it's own object, so I don't think I can make much use of MessageLinks. The weapon itself has a dialog script that gives you one "Sheathe" option if clicked, and the sheathe has the same and only offers the "Draw" option, and the parts should alternatively disappear depending on which is clicked... the "receiver" scripts have been making use of channel 7 for the time being, since my dialogs don't work and I've been having to say the commands manually. integer channel=-21; list menu = [ "Draw" ]; default { state_entry() { llListen(channel, "", NULL_KEY, ""); }
touch_start(integer total_number) { key contact = llDetectedKey(0); if( contact != llGetOwner() ) return; // ignore other people llDialog( contact, "Options:", menu, channel ); }
listen(integer channel, string name, key id, string choice ) { if ( llListFindList( menu, [ choice ]) != -1 ) { if ( choice == "Draw" ) { llSay(7, "Draw"); llSay(0, "Test. Is drawing their weapon."); } } else { llSay(0, "Error"); } } } It did say the bit "Test. Is drawing their weapon.", so I can only presume it functions, but the weapon isn't vanishing like it's supposed to. Here's the alpha-switching scripts I'm currently using, which were opensource and rumored to function just fine. The example below is used in the sheathe, not the weapon, and basically functions as... if it hears sheathe, the scabbard should make itself visible. If it hears draw, it should be set to transparent (since the "sheathe" is just a duplicate of the weapon, and I want it to entirely vanish... It's not an typical sheathe for holding the item.) The above example dialog waits for answers on channel -21, while the one I have in the weapon is on -22, since they conflict otherwise... integer channel = 7; string s = "Sheathe"; string d = "Draw";
default { state_entry() { llListen(channel,"",llGetOwner(),""); }
listen(integer channel,string blah,key x,string message) { if(message == s) { llSetLinkAlpha(LINK_SET, 1, ALL_SIDES); } if(message == d) { llSetLinkAlpha(LINK_SET, 0, ALL_SIDES); } } on_rez(integer start_param) { llResetScript(); }
}
So that would be, in summary, a script in the sheathe listening on channel 7 waiting to alpha or not alpha, and the same thing in the weapon itself which tells it when to appear or not based on the dialog command chosen. Keep in mind, I'm relatively new to scripting and may be totally floundering around in the dark and butchering this code, so... Cookies and worship for anybody who bothers to read all that and offer suggestions. 
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
10-13-2006 17:29
Well, replace your touch script with this: integer channel=7; list menu = [ "Draw", "Sheathe" ]; default { touch_start(integer total_number) { key contact = llDetectedKey(0); if( contact != llGetOwner() ) return; // ignore other people llDialog( contact, "Options:", menu, channel ); } } that'll work just fine. Or, if you must have it relayed twice, in the remote scripts (doing the alpha changes) replace llListen(channel,"",llGetOwner(),""  ; with llListen(channel,"",NULL_KEY,""  ; and precede the conditionals in the listen event with if(llGetOwnerKey(id) != llGetOwner()) return; thus: integer channel = 7; string s = "Sheathe"; string d = "Draw"; default { state_entry() { llListen(channel,"",NULL_KEY,""); } listen(integer channel,string blah,key x,string message) { if (llGetOwnerKey(x) != llGetOwner()) return; if(message == s) { llSetLinkAlpha(LINK_SET, 1, ALL_SIDES); } if(message == d) { llSetLinkAlpha(LINK_SET, 0, ALL_SIDES); } } on_rez(integer start_param) { llResetScript(); } }
|
|
Bad Fluffy
Registered User
Join date: 21 Jan 2006
Posts: 13
|
10-13-2006 18:02
It's aliiiive! At least, for the time being (until it breaks again, which I wouldn't be surprised if it does with my luck...), it works as intended with that nicely minimized code. Still not entirely sure how the object was listening for the owner to speak and how I could change it to otherwise, but with some fiddling which I can't remember in detailed steps, it now seems to work. Heh.
Thank you very, very much. <3
P.S. - Does anybody know if CONTROL_ML_LBUTTON (for lltakecontrol) is broken currently? Not broken, but... wonky. The only way I can get my weapon to attack in mouselook is by using CONTROL_LBUTTON, whereas if I use the ML one and leftclick, it'll attack when *not* in mouselook. It's totally reversed.
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
10-13-2006 19:33
From: Bad Fluffy Hmm. With that particular line, I'm getting a "Function call mismatches type or number of arguments" error. And... Typo. The second sound be llGetOwner() And I just tried the following in world and it worked fine: integer channel=7; list menu = [ "Draw", "Sheathe" ]; default { touch_start(integer total_number) { key contact = llDetectedKey(0); if( contact != llGetOwner() ) return; // ignore other people llDialog( contact, "Options:", menu, channel ); } } The reason your script isn't working is it's listening for the owner to speak, but you're having an object speak.
|