Jump to content

Pressure plates


Tattooshop
 Share

You are about to reply to a thread that has been inactive for 93 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

53 minutes ago, Profaitchikenz Haiku said:

Something for you to bear in mind: as given above the code won't work because when you detect plate 1 being collided with, you replace gState(1)'s value to show is set.

But list elements start from 0, and since you don't have a plate named "0" you will never change the first element of gState from 0 to 1.

therefore, if you have 9 plates named 1 to 9, and nine elements in the list, the element that you must change from 0 to 1 for plate "n" is actually n - 1, so for plate 1 you do llListReplaceList(gState, [1], 0, 0) 

and for plate 2

llListReplaceList(gState, [1], 1, 1)

Your naming convention does allow you to do this:


integer index = (string) plate; // so plate "2" generates integer 2

gState = llListReplaceList(gState, [1], index -1, index - 1); // replaces the correct list element 0 to 8 
                                                              // corresponding to plate "1" to "9"

But I'd suggest you leave that for later and for now just manually add the numbers in, remembering to subract 1 when accessing the list locations

 

Thank you so much! It works! I am very grateful to you! :D


You have helped not only me, but also my friend, he is making a sim dedicated to Egypt, so if this sim appears one day, you contributed to its creation! ;)👍

 

list gState = [0, 0, 0, 0, 0, 0, 0, 0, 0];

default
{
    state_entry()
    {
        llSetTimerEvent(0.0);
    }

    collision_start(integer num)
    {
        integer ii;
        string plate;
        if (llListFindList(gState, [1]) < 0) // we've only just begun
        {
            llSetTimerEvent(30.0);
        }

        for (ii = 0; ii < num; ii++)
        {
            plate = llGetLinkName(llDetectedLinkNumber(ii));
            if (plate == "1") // plate name check
            {
                // do something
                llSay(0, "plate number 1 pressed");
                gState = llListReplaceList(gState, [1], 0, 0);
            }
///----------------------------------------------------------------------
            if (plate == "9")
            {
                llSay(0, "plate number 9 pressed");
                gState = llListReplaceList(gState, [1], 8, 8);
            }
            //add in all the other plates here in a similar manner
        }

        if (llListFindList(gState, [0]) < 0)
        {
            // do MAIN_ACTION();
            llSetTimerEvent(0.0);
            llSay(0, "all plates are pressed");
            llResetScript();
        }
    }
          
    timer()
    {
        llSetTimerEvent(0.0);
        llSay(0, "Bad luck, move faster next time");
        llResetScript();
        // and reset the script to have another go
    }
}

 

Link to comment
Share on other sites

9 hours ago, Profaitchikenz Haiku said:

Looks good, but should there be code to implement not adding in the same link number more than once? (Which I assume will be a simple bitwise & to see if that power of 2 is already set)

is what happens when I type stuff off the top of my head

Quistessa's & Prof's corrections: don't record the same task twice and handle 1 | -1 = -1

integer link = llGetDetectedLinkNumber(num);
integer task = 1 << (link - 2);
if (!(tasks & task))
{  // do task
   tasks = tasks | task;
   // slppf(link [ plate down ];

}

i hope

Edited by Mollymews
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

6 minutes ago, Mollymews said:

!(tasks & task)

Spins my brain a bit, but I'm not sure this gives you the result you expect when tasks == 0 (nothing has happened yet) and task == -1 (I still haven't checked if the result of 1<<-1 is non-zero)

Wouldn't it be much simpler to just check that (task>0)?

  • Thanks 2
Link to comment
Share on other sites

17 minutes ago, Quistessa said:

Spins my brain a bit, but I'm not sure this gives you the result you expect when tasks == 0 (nothing has happened yet) and task == -1 (I still haven't checked if the result of 1<<-1 is non-zero)

Wouldn't it be much simpler to just check that (task>0)?

yes

it should be: if (~task && !(tasks & task))

just say tho that Prof's approach in using a task/state list is more flexible.  With a list then can provide task information in a more readable way. Can also more easily change the order in which tasks are to be done (shuffle task order list). Player completes the first task. The game random chooses the next task, and so on

Edited by Mollymews
forgot the not
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 93 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...