Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

To Loop or Not to Loop

Wicc Cunningham
Registered User
Join date: 25 Jun 2004
Posts: 52
02-12-2007 13:47
Yesterday I had something happen that caused a visitor to my store and myself some grief. I have a "billboard" in my store that show pictures of various sites and hands out a landmark to that site. I had intended to sell this item at one time, so I built in an info box tacked to it that would give out a notcard about how someone can add their own "ad" to it. Of course I used a simple notecard giving script. Someone visited my store and clicked the infobox and got a notecard. Not unexpected. For some reason it started spamming him with notecards. I started getting messages about "the user is in busy mode, your message will be displayed etc...". Not sure why I was getting the busy mode message. I jumped in world and reset the script and it stopped.

What I am believed caused the problem is that in my touch event I use a for loop. I do this mostly out of habit from normal programming practices. Since I have a known number if interations and want to respond to all the avatars who touch the item it seemed like a good idea. Most the time when I see scripts posted by various people they will use the index of zero when using fuctions like llDetectedKey() in conjunction with the touch event.

So I ask my fellow scriptors what I the better practice? I would expect it would depend on the application. I would also expect that there would be an issue of creating "lag" when using a loop with touch events or any that can potentially have multiple avatars interacting with the object.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
02-12-2007 16:19
My understanding is that you only need the for loop in a touch event, not a touch_start or touch_end event. And for scripts that need to detect a simple click, it's better to use touch_start. In the touch event, if a person touches and holds... then a second person touches, the second person will be #1 rather than the usual #0.

Technically, the same thing could happen in a touch_start, but it'd require both touchers to click at precisely the same time, not likely. And even if it does happen, the worst case in a notecard giver is that one of the clickers gets no card... so they click again a second later and get their card anyway.