How to count messages and make decision
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
07-16-2005 23:20
Hello there, There are the root prim and 15 prims all linked. Each one judges and sends OK message to the root prim by llMassageLinked if it is OK. Meanwhile, the root prim receives thier messages and counts them. I want it to say "Congratulations" when they are all OK, but "Sorry, you lost" when not all. link_message(integer sender, integer num, string str, key id) { if(str == "OK") { i = i + 1 } if(i == 15) { llSay(0, "Congratulations!"); } } In case of above, I can't let it say, "Sorry, you lost". What should I do? Thanks.
_____________________
 Seagel Neville 
|
JayD Torgeson
Registered User
Join date: 24 May 2004
Posts: 5
|
07-16-2005 23:36
you need two seperate replies, one for ok and one for not ok so that you know when all the messages have been sent, otherwise you are waiting for messages that will never come.
|
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
|
07-16-2005 23:45
By your description, if only 1 of the 15 child prims do not send the message "OK" then the player loses. Is this correct? So, try this: link_message(integer sender, integer num, string str, key id) { if(str == "OK") { i = i + 1 } else { llSay(0, "Sorry, You Lose"); i = 0; // reset counter to start over (you may need to reset other variable here to restart game return; // exit this event immediately }
if(i == 15) { llSay(0, "Congratulations!"); } }
|
Minsk Oud
Registered User
Join date: 12 Jul 2005
Posts: 85
|
07-17-2005 00:01
Alternate suggestion: track "responses" and "successes" as separate variables. Another possibility if you feel creative (i.e. later) would be to use a counter for successes, one for failures and a timer event to trigger the final message. Advantage of that architecture is that it lets you change the number of child prims without modifying the parent code. Now, barring syntax errors and ignoring my different formatting, how about: link_message(integer sender, integer num, string str, key id) { /* If it was an OK, bump up the success count */ if (str == "OK") { oks = oks + 1; } /* Regardless, bump up the total count */ total = total + 1; /* If we have tallied all the responses... */ if (total == 15) { /* Report the results */ if (oks == 15) { llSay("Congratulations"); } else { llSay("You got owned"); }
/* Reset the counters, though this should probably be done elsewhere */ oks = 0; total = 0; } }
No real reason to count successes rather than failures, so you could quite easily use a "fails" variable and compare against zero.
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
07-17-2005 00:05
JayD, thanks. It seems to work well. I wonder why it didn't occur to me. That is the newbie. Champie, also thanks. But a lot of messages are corresponded with each other. Whenever corresponding, it would say, "Sorry, You Lose". But thanks for responding.  Minsk, also thanks. But the same reason with Champie's. So when it gets NG, I let it say, "Sorry, You Lose". Thanks all. 
_____________________
 Seagel Neville 
|
Minsk Oud
Registered User
Join date: 12 Jul 2005
Posts: 85
|
07-17-2005 16:25
Whoops, sorry. I assumed the "OK" meant you had already differentiated success and failure.
Now being curious, I will probably throw together the timer-based approach later.
<edit>Turns out a shared counter is easier than dealing with a timeout. I left a freebie at Morris 14,111 if the sample will be useful for anyone.</edit>
|
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
|
07-18-2005 02:44
From: Seagel Neville JayD, thanks. It seems to work well. I wonder why it didn't occur to me. That is the newbie. Champie, also thanks. But a lot of messages are corresponded with each other. Whenever corresponding, it would say, "Sorry, You Lose". But thanks for responding.  Minsk, also thanks. But the same reason with Champie's. So when it gets NG, I let it say, "Sorry, You Lose". Thanks all.  Ah, ok  I'm glad you have it worked out.
|