heres some very basic script i cooked up.
CODE
default
{
state_entry()
{
llListen(-1, "","","");
}
listen(integer chnl, string s, key k, string msg)
{
vector x = llGetPos
if( (integer)msg <= number)
{
move up
llSleep(1)
move to x
}
}
}
thank you
These forums are CLOSED. Please visit the new forums HERE
whack-a-mole |
|
Natsely Amaterasu
Registered User
Join date: 30 Sep 2008
Posts: 19
|
08-20-2009 12:17
I'm trying to build a whack-a-mole game but i came to problem of not bieng able to touch the "mole" while its moving.
heres some very basic script i cooked up. CODE
|
Scarecrow Grossmann
Registered User
Join date: 18 Aug 2009
Posts: 10
|
08-20-2009 12:46
Don't use llSleep. you cannot detect events (ie, touches, collisions, etc. ) during a sleep, use a timer instead.
|
Meade Paravane
Hedgehog
![]() Join date: 21 Nov 2006
Posts: 4,845
|
08-20-2009 12:52
Don't use llSleep. you cannot detect events (ie, touches, collisions, etc. ) during a sleep, use a timer instead. Yep. Everything in LSL is (sorta) an event and you only get to deal with one event in a script at a time. If you don't return from the event handler because you're in an llSleep, no other event handler will get called. _____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224 - If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
08-20-2009 14:42
How are you touching the mole? Your short schematic script listens for a command on channel -1 (which means that it's expecting a verbal command from an object, not an avatar). If you expect it to react to a mouse click, you'll need to use a touch_start event instead.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....
![]() Look for my work in XStreetSL at |
Natsely Amaterasu
Registered User
Join date: 30 Sep 2008
Posts: 19
|
08-24-2009 07:57
Ok ty for the advise
Here's what I have now CODE
Any tweaking? |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
08-24-2009 08:31
Well, let's see..... What's the listen event for? It looks like you still expect some object to give the script an integer (Has to be an object.... it's a negative channel), but it doesn't do anything with the integer except see whether it is == 1. If you're just using this chat signal as a switch, it doesn't really matter what the message is. Try this...
CODE
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....
![]() Look for my work in XStreetSL at |
Vance Adder
Registered User
Join date: 29 Jan 2009
Posts: 402
|
08-24-2009 09:52
I can't test this, but it should oscillate between the "on" and "off" position.
The only caveat is if you reset the script, it'll use its current position as the starting position. There are a few ways I can think of to fix that problem... CODE
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
08-24-2009 10:36
I haven't tested it either, but since it really doesn't matter what the message on channel 1 is, I think you can just do this, which is a hybrid of the last post and the suggestion I made earlier.
CODE
ETA: BTW, did anyone else notice that Vance managed to post his script without adding a space after the "<" symbol? Did the Linden gods actually fix the forums? WooHoo! ![]() ETA again: Ooops! Forgot the touch_start event. Added above. _____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....
![]() Look for my work in XStreetSL at |
Vance Adder
Registered User
Join date: 29 Jan 2009
Posts: 402
|
08-24-2009 12:12
![]() I can rarely tell if what I'm posting is coherant. ![]() |
Natsely Amaterasu
Registered User
Join date: 30 Sep 2008
Posts: 19
|
08-26-2009 11:15
the point of
listen(integer chnl, string s, key k, string msg) { if((integer)msg > 0 && (integer)msg <= 1) { llSetTimerEvent(1); } } is because i have nine diferent moles, i have a timer set to be on and of with touch but when its on its says a random number from 0-9.1(i want to make sure i can check for 9) and sends it through the -1 channel. All the moles check for a different range of numbers 0-1, 1.00001-2, 2.00001-3 and so on. This mole only checks if the number sent is from 0-1 and if so moves up. Then it sets it own timer to move back down....does that makes sense? |
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
08-26-2009 12:07
OK, that's a different approach so it would require rebuilding this logic, but it's a perfectly good way to frame the scripting challenge.
If you want to try what Vance and I were suggesting, though, all you have to do is use a different negative channel for each mole, duplicating this script to put a slightly different one in each mole, and then replace the llSetTimerEvent(nFlag = !nFlag) line that I wrote in the listen event with .. nFlag = (integer)message; llSetTimerEvent(nFlag); Just be sure that the message you send to each mole is either "1" (on) or "0" (off). The variable nFlag is doing double duty here. It's controlling the timer and reversing the direction of the mole, depending on whether it's set by the listen even or the touch_start event. The difference in our approaches is just a matter of deciding whether you prefer to send the same signal to each mole on its own private channel or whether you want to send a privately-coded message to each mole on a common channel. Both ways work. BTW, either way you probably want to use a less common channel than -1 to avoid interference from other speaking scripts in the area. Try a big negative number. _____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....
![]() Look for my work in XStreetSL at |