Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

MORE trials of a burn tower: Touch Counter?

Cera Dreadlow
Registered User
Join date: 9 Jul 2008
Posts: 21
08-05-2008 10:23
OK, I've searched (unsuccessfully) for a script that will count how many times an object is touched. Here's the current scenario: I have an axe that has a (modified door) animation script on it. Currently, when touched, the axe swings and triggers a hole to open in the wall. (See /54/c7/137951/1.html ).

Well, what I would REALLY like to happen is for people to have to "chop" the wall 3 times before the it opens up. I assume this would require some sort of counter of how many times it has been touched, but I have NO CLUE how to go about doing that. It doesn't need to be so code-heavy that it has to detect WHO touched it (if that isn't intrinsic for the script to function), 'cause if someone only touches it twice and then gives up, I really don't mind if the next person only has to chop at it once. Not a big deal.

Along with the assistance of setting up this touch counter thing, I will probably also need help in getting it to re-loop the animation for the second and third touches.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-05-2008 10:46
I'm assuming the axe swings to hit the wall, and then it sends a command to the door somehow (chat, probably) which makes the door open? I.e. the axe movement and the door movement are separate things, and you want the axe to swing 3 times, and the door to open on the 3rd touch/swing.

Try this... not in-world, so untested:


integer touchCount = 0;

default
{
touch_start(integer num)
{
// Play animation, since that always needs to be played
// Call "make axe move" function

// Increment the touch counter by 1
touchCount++;

// See if we need to open the door
if (touchCount == 3)
{
// Do whatever you're doing to make the door open
llSay(something, I guess);

// Also reset the touch counter for the next round
touchCount = 0;
}
}
}
Cera Dreadlow
Registered User
Join date: 9 Jul 2008
Posts: 21
08-06-2008 08:29
THAT was INCREDIBLY helpful! Thank you so much! My only problem is that I couldn't get it to function as all one script. I ended up having to make the animation one script and the touch counter and switch in another. It's best for efficiency if they're one script, right? You probably saw, I IMed you in-world. I can either TP you when we're both in so you can help me combine them, or I can post the script(s) here... Whichever you prefer.

I should probably mention that the script compiles just fine. It's just that I can't get the switch to function, no matter how many times the axe swings...
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-06-2008 08:34
If you don't mind posting your scripts here, that's much easier for me these days than trying to meet in-world.

From: someone
It's best for efficiency if they're one script, right?


A little bit, but I wouldn't worry about it too much.

You can also try debugging the script by sprinkling llOwnerSay's in there, with comments like "The value of X is now blah blah", "Now I'm in the if block and am about to do this", things like that. That can sometimes help you figure out why a script isn't doing something.