|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
09-30-2006 11:37
I have a script that adjust the Beats Per Minute timer for a project I'm working on. The following script works just fine with multiple button presses. integer BPM=60;
default { link_message(integer sender_num, integer num, string str, key id) { if(str=="+100BPM" && (BPM + 100)<=180) { BPM=BPM+100; } if(str=="-100BPM" && (BPM - 100)>=60) { BPM=BPM - 100; } if(str=="+10BPM" && (BPM + 10)<=180) { BPM=BPM+10; } if(str=="-10BPM" && (BPM - 10)>=60) { BPM=BPM - 10; } if(str=="+1BPM" && (BPM + 1 )<=180) { BPM=BPM + 1; } if(str=="-1BPM" && (BPM - 1 )>=60) { BPM=BPM - 1; } llSetText((string)BPM + " beats per minute",<1,1,1>,1); } }
This script will only update the BPM once before it stops doing anything (no script error it just stops running through the if-statements it appears. integer BPM=60;
default { link_message(integer sender_num, integer num, string str, key id) { if(str=="+100BPM" && (BPM + 100)<=180) { BPM=BPM+100; } if(str=="-100BPM" && (BPM - 100)>=60) { BPM=BPM - 100; } if(str=="+10BPM" && (BPM + 10)<=180) { BPM=BPM+10; } if(str=="-10BPM" && (BPM - 10)>=60) { BPM=BPM - 10; } if(str=="+1BPM" && (BPM + 1 )<=180) { BPM=BPM + 1; } if(str=="-1BPM" && (BPM - 1 )>=60) { BPM=BPM - 1; } integer ones=BPM%10; integer tens=((BPM-ones)%100)/10; integer hundreds=(BPM-BPM%100)/100; llMessageLinked(LINK_SET, ones, "ones", NULL_KEY); llMessageLinked(LINK_SET, tens, "tens",NULL_KEY); llMessageLinked(LINK_SET, hundreds, "hundreds",NULL_KEY); llSetText((string)BPM " beats per minute.",<1,1,1>,1); } }
any idea why this is? [Edit] Getting around this using llSay works just fine, but I'd rather keep my messages for within this link set communicated on llMessageLinked [/edit] *clarification on what my object is doing* You can select the tempo's BMP by clicking on 6 buttons which will adjust the 1's,10's, and 100's numbers on the BPM rate. These buttons let this script above know they've been pressed with the llmessageLinked. The buttons work perfect, and adjusting the BPM works perfect. it's when I attempt to send out a link message whenever the BPM are adjusted (which means I need to do so within the link_message state), that the script will accept the very first button input, and then not do anything after that.
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
09-30-2006 14:41
This may be it, I can't remember if a script is supposed to be able to hear it's own link messages...
Change LINK_SET to LINK_ALL_OTHERS. You may have made yourself an infinite loop.
|
|
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
|
09-30-2006 14:44
I believe a script will get it's own link messages if it is listening. So, you get the first message, then send another which isn't caught in you if's and then send another, which gets caught.....
You might want to test that you're getting a legal input and only send a message if it is to break the loop.
|
|
Jopsy Pendragon
Perpetual Outsider
Join date: 15 Jan 2004
Posts: 1,906
|
09-30-2006 15:06
You definitely have an endless feedback loop going because your second script ALWAYS sends a broadcast message, whether it received the expected input or not. My own coding style uses the "integer" parameter in linked messages as a message identifier, not as a value, (often because I have multiple message types floating about). A button would send a llMessageLinked(LINK_ALL_OTHERS, 1, (string) 10, NULL_KEY) (if I were being too lazy to find out the specific link number of it's target first, which I usually do) the handler prim would have link_message( integer sibling, integer msgtype, string msg, key id ) { if ( msgtype != 1 ) return; // Not for me! // Do stuff... } You might also want to consider putting in "else" statements between your if's that way it doesn't need to process each check each time. I'm not sure what you have listening in the rest of your object, but my own spin on your code might be more like: (pardon the manglage, the php tags got dropped accidentally and I can't stand re-formatting code in a browser window! =)) integer BPM=60; default { link_message(integer sender_num, integer num, string str, key id) { if ( num != 1 ) return; if(str=="+100BPM" && (BPM + 100)<=180) { BPM=BPM+100; } else if(str=="-100BPM" && (BPM - 100)>=60) { BPM=BPM - 100; } else if(str=="+10BPM" && (BPM + 10)<=180) { BPM=BPM+10; } else if(str=="-10BPM" && (BPM - 10)>=60) { BPM=BPM - 10; } else if(str=="+1BPM" && (BPM + 1 )<=180) { BPM=BPM + 1; } else if(str=="-1BPM" && (BPM - 1 )>=60) { BPM=BPM - 1; } vector bpms = < BPM%10, (BPM-ones)%100)/10, (BPM-BPM%100)/100 >; llMessageLinked(LINK_ALL_OTHERS, 2, (string) bpms, NULL_KEY); // extract with: vector bpms=(string) msg; and use bpms.x, bpms.y, bpms.z llSetText((string)BPM " beats per minute.",<1,1,1>,1); } }
</div>
_____________________
* The Particle Laboratory * - One of SecondLife's Oldest Learning Resources. Free particle, control and targetting scripts. Numerous in-depth visual demonstrations, and multiple sandbox areas. - Stop by and try out Jopsy's new "Porgan 1800" an advanced steampunk styled 'particle organ' and the new particle texture store!
|