Can an IF statement contain a Touch state change?
|
|
Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
|
06-14-2008 02:54
I am making a prim where the script checks on a color state change through IF. It will check until the IF statement is true and change the color of the prim, then it has a second value to compare with an IF statement, and if that becomes true it changes the color yet again and also sets the prim to die. What I wish to know is whether I can insert a statement inbetween the first and second IF cycles to check if the prim was touched or not, only during the time that the first IF statement remains true? Basically something like: IF x = 1 { llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1.0,0.0,0.0>, 1.0]); can I imbed some sort TOUCH state check here; {llGiveInventory(llGetOwner(), "object"  ; } } IF x = 2 { llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1.0,0.0,0.0>, 1.0]); }
_____________________
Screwdrivers are so 90's...
|
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
06-14-2008 03:17
One easy method is to set a flag in the touch event and then check it in your code. eg:
integer touched = FALSE;
default { touch_start(integer total_number) { touched = TRUE; } }
and then in your code
IF x = 1 { llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1.0,0.0,0.0>, 1.0]); if(touched) { llGiveInventory(llGetOwner(), "object"); } }
IF x = 2 { llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1.0,0.0,0.0>, 1.0]); }
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
06-14-2008 07:11
From: Dumisani Ah statement contain a Touch state change? What I wish to know is whether I can insert a statement inbetween the first and second IF cycles to check if the prim was touched or not, only during the time that the first IF statement remains true?
What you are saying does not make sense. A touch will trigger a Touch event when it happens independently of what your code is doing at the moment. Your code ( the one with the IF statements ) is initiated by some event as well. To give you a more detailed advise I would need to see more of your code.
_____________________
From Studio Dora
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
06-14-2008 10:09
You'd need a second script that sets a prim property (such as description) when a touch occurs. The sequence would go:
1.) Main script resets touch status in prim property at beginning of if statements. 2.) Secondary script sets touch status in prim property on touch. 3.) Main script checks touch status in prim property between if statements.
This is not guaranteed. Events may not be processed in a timely enough fashion to catch the touch event, depending on how much script delay there is (the 0.2 second delay for your llSetPrimitiveParams() might give a sufficient period for the user to touch and for it to be processed before you main script continues).
You could also setup a fast timer to execute the second if statement 0.25 seconds after the beginning of the first if statement though. That SHOULD work about as well as the second script hack.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
06-14-2008 12:48
Just declare x as a global and check it in the touch event. If it is true then give inventory in that event instead: default { touch_start(integer n) { if(x)//since you are checking for 1 & integer 1 also means true llGiveInventory(llGetOwner(), "object"); } }
_____________________
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
|
|
Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
|
06-14-2008 14:03
Hi everyone, mmm, the advise given is all great, but I can understand that I need to give more info possibly. Remember my fruit trees that rezz fruit? Well, now I have sculpted a watermelon plant that works the same, growing the fruit prim on x,y and z axis, using z axis only as the control factor, ie. if z > a then change fruit prim color from green to red (ripe), if z > b then change the fruit prim color to grey (rotten), rezz a new green fruit as a child, make fruit prim physical to fall away from tree (except in the case of the watermelon where this is not set as it is already a ground level plant), and set fruit prim to die. In this sequence of events I now want to add a section where for fun when the fruit prim is touched while ripe, i.e. when z axis > a but < b, it will rezz a slice of watermelon for the touching avatar to eat, with built in animation for eating too  So it seems Jessy and Beverley may have hit it on the head for me, whilst I'm considering Hewee's suggestion of two scripts only because I am interested in making memory use more economical. Still learning so that may be over the top, but hey, this is all about experimenting Again where's Sneaky to see just how good this forum helps and the lot of you who so selflessly assists every single time! 
_____________________
Screwdrivers are so 90's...
|
|
Kain Cleaver
Registered User
Join date: 24 Jan 2006
Posts: 178
|
06-16-2008 00:14
From: Dumisani Ah Hi everyone, mmm, the advise given is all great, but I can understand that I need to give more info possibly. Remember my fruit trees that rezz fruit? Well, now I have sculpted a watermelon plant that works the same, growing the fruit prim on x,y and z axis, using z axis only as the control factor, ie. if z > a then change fruit prim color from green to red (ripe), if z > b then change the fruit prim color to grey (rotten), rezz a new green fruit as a child, make fruit prim physical to fall away from tree (except in the case of the watermelon where this is not set as it is already a ground level plant), and set fruit prim to die. In this sequence of events I now want to add a section where for fun when the fruit prim is touched while ripe, i.e. when z axis > a but < b, it will rezz a slice of watermelon for the touching avatar to eat, with built in animation for eating too  So it seems Jessy and Beverley may have hit it on the head for me, whilst I'm considering Hewee's suggestion of two scripts only because I am interested in making memory use more economical. Still learning so that may be over the top, but hey, this is all about experimenting Again where's Sneaky to see just how good this forum helps and the lot of you who so selflessly assists every single time!  or you can use States to represent each stage. default { state_entry { state young; } } state young { state_entry { llSetTimerEvent(60); } timer() { state ripe; } } state ripe { state_entry { llSetTimerEvent(60); } touch_start(integer num_detected) { give slice here } timer() { state rotten; } } you know.. something silly like that.. but each state would have its own timer.. and die when you want it to. you can adjust each lifespan seperately. so if you wanted the ripe fruit to last longer then the dead fruit you can.. like stages.. but thats me and my simple "long way around" method
|
|
Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
|
06-16-2008 01:09
Hi Kain, Shoot, I wish I had learned about states much earlier in my attempts to script. Thing is I only discovered it during the making of this one  . They work extremely well I agree, and your suggested train of states during the development of a 'creation' of mine is exactly what I am going to apply to a seasonal plant, one that changes depending on seasons (self generating at the moment since they're non existant in SL ) and either produces fruit or flowers. I managed to produce a pretty good version of what I wanted to achieve using flags as suggested by Jesse and Beverley. Now when touched and ripe, the fruit will give the owner of the plant its harvest, slices of watermelon. Otherwise when touched as unripe or rotten it ignores the touch by resetting the flag if all conditions were not met. So basic, but o such fun!!!  and I gave away my hard work in world by mistake when I accidentally left a gift of my melon tree with Transfer perms and now its out in the wild free. O well, we live and learn  .
_____________________
Screwdrivers are so 90's...
|