Advice on using a state change for this script?
|
|
Tripp Baxton
Registered User
Join date: 29 May 2008
Posts: 13
|
02-28-2009 21:33
Howdy Ya'll ... working on a few things and am tinkering around with a prim counter here. Now please forgive me for any terms that are not correct as I am a learning scripter but need desperate advice and help here. Using a state change is fairly easy using touch from what ive been able to see in the wiki. but the question is what about a listen or a linked message. The script below i'd like to place into a Hud and when selected via a menu option for on or off display or not display. The thing is I believe i will have too have 2 seperate states. One where the text is set and one where it is not (ie: "" and not "Text here". So that it will appear as if it is being turned off and on. Here is the script obtained from a public libray. default { state_entry() { llSetTimerEvent(1.0); } timer() { integer intTotal = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TOTAL, FALSE); integer intMaxPrims = llGetParcelMaxPrims(llGetPos(), FALSE); integer intTemp = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TEMP, FALSE); integer intOther = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_OTHER, FALSE); llSetText("Land Information\nTotal: " + (string)intTotal + " of " + (string)intMaxPrims + "\n Temporary Prims: " + (string)intTemp + "\n Other's Prims: " + (string)intOther, <1.0, 1.0, 1.0>, 1.0); } } Just cant seem to figure out how to get it to change states using a listen event for the words "On or Off" on a high channel. It may be to complicated to set it up so that its done via a linked message. If anyone has a moment and can show me or explain to me how to implement that state change so that it appears it is being turned off and on It would be of most help. If you want compensation it can be discussed I suppose  Tripp Baxton
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
02-28-2009 21:53
From: Tripp Baxton Howdy Ya'll ... working on a few things and am tinkering around with a prim counter here. Now please forgive me for any terms that are not correct as I am a learning scripter but need desperate advice and help here. Using a state change is fairly easy using touch from what ive been able to see in the wiki. but the question is what about a listen or a linked message. The script below i'd like to place into a Hud and when selected via a menu option for on or off display or not display. The thing is I believe i will have too have 2 seperate states. One where the text is set and one where it is not (ie: "" and not "Text here". So that it will appear as if it is being turned off and on. Here is the script obtained from a public libray. default { state_entry() { llSetTimerEvent(1.0); } timer() { integer intTotal = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TOTAL, FALSE); integer intMaxPrims = llGetParcelMaxPrims(llGetPos(), FALSE); integer intTemp = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TEMP, FALSE); integer intOther = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_OTHER, FALSE); llSetText("Land Information\nTotal: " + (string)intTotal + " of " + (string)intMaxPrims + "\n Temporary Prims: " + (string)intTemp + "\n Other's Prims: " + (string)intOther, <1.0, 1.0, 1.0>, 1.0); } } Just cant seem to figure out how to get it to change states using a listen event for the words "On or Off" on a high channel. It may be to complicated to set it up so that its done via a linked message. If anyone has a moment and can show me or explain to me how to implement that state change so that it appears it is being turned off and on It would be of most help. If you want compensation it can be discussed I suppose  Tripp Baxton You can go that route (multiple states) if you want, but you can just as easily create a simple toggle, and check for it when you go to display (or not). For example... touch_start (integer foo) { if (testFlag) // if the test flag is true... { testFlag = FALSE; } else { testflag = TRUE; } }
then... in your timer event...
timer () { if (testFlag) { // display here.... } else { // dont display here... }
Now, you'll get some people saying no, do use states, it's too simple of a task, which is how I feel, but I won't go so far as to tell you not to use states. You can if you want and it's perfectly ok, but this task is simple enough to be handled by a toggle flag. Using states in this case will work just fine, but it's more coding than needed to get the job done. Hope that helps.
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Lily Cicerone
Registered User
Join date: 25 Jan 2007
Posts: 30
|
02-28-2009 22:37
I would avoid states. There's nothing to a state change on a listen event -- it works exactly the same as a state change on touch, except you could use the message event data in the conditional, as in
listen ( integer channel, string name, key id, string message ) {
if ( message == "ON" ) { state on; }
else { state off; }
}
The problem is, an extra state is going to require extra events, whereas in this case, I see no reason why you could not do anything you would want to without a stage change by placing the code within the default event or by defining your own function. Johan's example is a good place to start.
|
|
Tripp Baxton
Registered User
Join date: 29 May 2008
Posts: 13
|
03-01-2009 07:18
Thank you for the help , im doing my best to decipher your explanations ... please do forgive me this is a bit of a challenge for a beginner however , I find it best to learn by getting thrown to the sharks.
here is what I have come up with ... A toggle using a touch action. It is a state change however given my experience its what i understand the most.
It simply changes the text to basicly nothing since hover text is a prim property and not easily removed.
default { state_entry() { // State Is Off And No Text Displayed llSetTimerEvent(0.1); } timer() { llSetText("", <1.0,1.0,1.0>, 0); } touch_start(integer num_detected) { // Touching switches to on state state on; } } state on { state_entry() { // State Is On And Text Is Displayed llSetTimerEvent(0.1); } timer() { integer intTotal = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TOTAL, FALSE); integer intMaxPrims = llGetParcelMaxPrims(llGetPos(), FALSE); integer intTemp = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TEMP, FALSE); integer intOther = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_OTHER, FALSE); llSetText("Land Information\nTotal: " + (string)intTotal + " of " + (string)intMaxPrims + "\n Temporary Prims: " + (string)intTemp + "\n Other's Prims: " + (string)intOther, <1.0, 1.0, 1.0>, 1.0); } touch_start(integer num_detected) { // touching switches to default or off state state default; } }
The issue im having here is changing this from a touch start or touch activated script to a listen activated script. Ie ... Owner says Prim On or Prim Off on a high channel.
when i try and add the lllisten in place of the touch_start I get a syntax at the lllisten. I do realize im probally going about it all wrong but how would i go about making the script listen for a command from the owner only on a specified channel. using one command for state on and another for state off?
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
03-01-2009 08:10
One step at a time. Here is how to do your script in a single state and clarification on how a switch works: integer switch = 1;//integer 1 also = TRUE
setText(){ integer intTotal = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TOTAL, FALSE); integer intMaxPrims = llGetParcelMaxPrims(llGetPos(), FALSE); integer intTemp = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TEMP, FALSE); integer intOther = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_OTHER, FALSE); llSetText( "Land Information" + "\nTotal: " + (string) intTotal + " of " + (string) intMaxPrims + "\n Temporary Prims: " + (string) intTemp + "\n Other's Prims: " + (string) intOther, <1.0, 1.0, 1.0 >, 1.0 ); }
default { touch_start(integer num_detected) { if(switch){ //This reads as if(switch == TRUE) setText();//This way you do not have to wait the timer interval the first time llSetTimerEvent(5.0);//a timer of 0.1 is pretty harsh on the sim } else{ llSetTimerEvent(0.0); llSetText("", <1.0, 1.0, 1.0 >, 0); } switch = !switch;//every time it is touched it changes switch between 0 & 1 (TRUE & FALSE) } timer() { setText(); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
03-01-2009 09:19
Hopefully you take the time to absorb the script posted above instead of skipping straight to this post  To change from touch to listen you just have to define a listen and then the two conditions that will replace to the conditions in the touch event and then paste their contents there:
setText(){ integer intTotal = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TOTAL, FALSE); integer intMaxPrims = llGetParcelMaxPrims(llGetPos(), FALSE); integer intTemp = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_TEMP, FALSE); integer intOther = llGetParcelPrimCount(llGetPos(), PARCEL_COUNT_OTHER, FALSE); llSetText( "Land Information" + "\nTotal: " + (string) intTotal + " of " + (string) intMaxPrims + "\n Temporary Prims: " + (string) intTemp + "\n Other's Prims: " + (string) intOther, <1.0, 1.0, 1.0 >, 1.0 ); }
default { state_entry() { llListen(73, "", llGetOwner(), ""); } listen(integer channel, string name, key id, string msg) { if (msg == "on") {//chat /73 on setText();//This way you do not have to wait the timer interval the first time llSetTimerEvent(5.0);//a timer of 0.1 is pretty harsh on the sim } else if (msg == "off") {//chat /73 off llSetTimerEvent(0.0); llSetText("", <1.0, 1.0, 1.0 >, 0); } } timer() { setText(); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Tripp Baxton
Registered User
Join date: 29 May 2008
Posts: 13
|
03-01-2009 10:47
So by using a switch im not only saving time ofcourse with less scripting but in turn using less resources of the sim?
Is this any way similar to a boolean?
And again ty for the help , im actually reading all that has been written from everyone and while using wiki experiemtning with each event and state. kindof a trial and error but it helps me see what does what.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-01-2009 13:00
Yes, the switch value is being used like a boolean. Like C, LSL doesn't have a dedicated boolean type. Instead, it evaluates integers with a non-zero value as true and zero as false. I'm not sure if it is specified which of the 2^32-1 true values are returned by the logical operators (or if it depends on the value of the operands), but scripts really shouldn't rely on it anyway. Just treat them as zero or non-zero, false or true. There are two constants, FALSE and TRUE, which have the expected boolean interpretations.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-01-2009 13:01
Yes, the switch value is being used like a boolean. Like C, LSL doesn't have a dedicated boolean type. Instead, it evaluates integers with a non-zero value as true and zero as false. I'm not sure if it is specified which of the 2^32-1 true values are returned by the logical operators (or if it depends on the value of the operands), but scripts really shouldn't rely on it anyway. Just treat them as zero or non-zero, false or true. There are two constants, FALSE and TRUE, which have the expected boolean interpretations. See http://www.lslwiki.net/lslwiki/wakka.php?wakka=boolean
|
|
Tripp Baxton
Registered User
Join date: 29 May 2008
Posts: 13
|
03-01-2009 13:30
Alright will do , makes a bit more sense now. One last question and I wont bug ya's no more lol this is more of a general question , midly related to the above script but more for my general knowledge. you have a script like above which is listening for a command .. ill use the above as an example. llListen(73, "", llGetOwner(), ""  ; Is waiting for the owner to isse=ue a command on channel 73. however because of the llGetOwner() another script cannot issue the command with an llsay? Im guessing because the llGetOwner means Owner , means myself and will not hear or recognize a script saying hello on channel 73. is there a way around that conserving privacy and minimizing interference without using a linked message. if we used say a dialog to issue the command on channel 73 ... the script with llListen(73, "", llGetOwner(), ""  ; would not recognize it because of the llGetOwner. But would if we took out the llGetOwner. Is Linked message the only way in this case so that someone with the same object or item within that radious isnt controlling there script and mine?
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-01-2009 14:28
You cannot filter a listen using the owner of the speaker, so you have to leave the listen unfiltered (use NULL_KEY instead of llGetOwner()) and do your own filtering within the 'listen' event handler. For example, you could get whether the result of giving llGetOwnerKey() the key of the speaker results in a value of llGetOwner(), meaning the speaker is either the owner or an object within the same sim owned by the owner. It typically looks like: integer CHANNEL = ...;
default { state_entry() { llListen(CHANNEL, "", NULL_KEY, ""); }
listen(integer channel, string name, key id, string message) { if (llGetOwnerKey(id) != llGetOwner()) { return; }
// do something } }
|