|
Eric Stuart
Registered User
Join date: 5 Jul 2006
Posts: 203
|
06-17-2008 07:33
I have a project I'm working on (first fully customized coding) and I'm doing all I can to make the LSLWiki hit their bandwidth limit for this month, but I'm just having some problems working on one of the portions of the script. I'm trying to create a variable string that will be able to be changed by voice command, and stay changed. I have an LLListen command that creates the message on a specific channel into the string variable. Right now, to test it, I've implemented it to do an if/then and if a certain keyword was used, it would state the variable through LLSay, stating it was changed. I realized this may not work as well as I hoped at the start, so I added a second variable and whenever a certain string was stated on the channel, it would change the second string. For instance:
-One variable, player1statustrue, is set to normal before the script starts -The LLListen command was set to listen to statements on channel 20. It would pull the message as a string called Player1Status. -Using IF statements, it would look to see if (player1status == normal) or a list of other strings. -If the message string matched one of the if statement strings, it would state "Player 1 Status Changed to Normal" or whatever the status is. -After stating the status, it changes player1statustrue to the accepted status
Now, the reason I'm doing this is because I'm working on a game that requires certain status settings for events to happen to you or your opponent. So I would need to be able to set a way of changing and keeping the change made through both player1statustrue and player2statustrue, and be able to check to see through whatever way (I considered a call and respond between the scripts) that the specific status was in place for both players. Now, this is where the problems come about.
I added in a test that would include a second if statement inside the original if statements that would check to see if (player1statustrue == normal) then to state that the status was already at normal and needed no change. This isn't necessary, but I did it to see if the variable was changing for the "true" string. Likewise, I had it state, if (player1statustrue != normal) then to do what the original statement did...state the change of status and change the "true" string to the new status. However, no matter how many times I attempt to change the "true" string, whenever I test it against the normal status to see if it will change instead of stating it already is set to normal, it won't state a change. My guess is that the "true" string isn't even changing, or if it is, it isn't staying changed.
I can provide a demo (not now, later tonight) for anyone that wants to take a look and could potentially help. I'm still new to fully custom scripts, though I've torn apart scripts before and rewrote things to work the way I need them, so I've got some knowledge but know I have alot to learn. Thanks in advance!
|
|
Imnotgoing Sideways
Can't outlaw cute! =^-^=
Join date: 17 Nov 2007
Posts: 4,694
|
06-17-2008 07:37
Vairable scope is all about placement. If you initialize the variable before default{} it will hold whatever value it got last until the whole script is reset. At first glance, it looks like you're doing everything right though. It might be that the line you have to change it might not be running. When I suspect that I put a lot of llOwnerSay("1"  ; .... llOwnerSay("2"  ; and so on to see if all the if{} statements are working correctly. (^_^)y
|
|
Eric Stuart
Registered User
Join date: 5 Jul 2006
Posts: 203
|
06-17-2008 08:53
Alright, seeing as I cant access SL right now, can someone test this and let me know what they find? Thanks! string player1statustrue = "normal"; default { state_entry() { llListen(20,"",NULL_KEY,""  ; } listen(integer channel, string name, key id, string player1status) { if (player1status == "normal"  { if (player1statustrue != "normal"  { llSay(0, "Player 1 Status changed to Normal"  ; player1statustrue = "normal"; } else if (player1statustrue == "normal"  { llSay(0, "Player 1 Status is already set to Normal"  ; } } else if (player1status == "stunned"  { if (player1statustrue != "stunned"  { llSay(0, "Player 1 Status changed to Stunned"  ; player1statustrue = "stunned"; } else if (player1statustrue == "stunned"  { llSay(0, "Player 1 Status is already set to Stunned"  ; } } } }
|
|
Imnotgoing Sideways
Can't outlaw cute! =^-^=
Join date: 17 Nov 2007
Posts: 4,694
|
06-17-2008 09:28
I have the habit of declaring variables without values unless I'm making constants. This may just be me being silly... But try this... Change: string player1statustrue = "normal"; to: string player1statustrue; And change: state_entry() { llListen(20,"",NULL_KEY,""  ; } to: state_entry() { player1statustrue = "normal" llListen(20,"",NULL_KEY,""  ; } (^_^)y
|
|
Eric Stuart
Registered User
Join date: 5 Jul 2006
Posts: 203
|
06-17-2008 09:41
Ok, I'll give that a try. Thanks!
EDIT: IT WORKS! Thanks again!
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
06-17-2008 10:20
Your script appears to work as intended, Eric. However, instead of using a long if/else chain to test if the incoming message matches a keyword, try putting the keywords into a list. When a message is received, search the list for that message, and if found, take the appropriate action: list keywords = [ "normal", "stunned" ]; string player1statustrue = "normal";
default { state_entry() { llListen( 20, "", NULL_KEY, "" ); }
listen( integer channel, string name, key id, string player1status ) { integer i = llListFindList( keywords, (list)player1status );
if( i != -1 ) { if( player1statustrue != player1status ) { player1statustrue = player1status; llSay(0, "Player 1 Status changed to " + player1statustrue ); } else llSay(0, "Player 1 Status is already set to " + player1statustrue ); } } }
|
|
Eric Stuart
Registered User
Join date: 5 Jul 2006
Posts: 203
|
06-17-2008 11:16
Oh wow...yeah, that cleans up the script and will save alot of copy/paste stuff. Thanks, I'll give it a try!
|