Jump to content
Sign in to follow this  
Artorius Constantine

If inventory_dropped object is this, then do this issue

Recommended Posts

I'm stumped. I have a Troll guarding a bridge, he wants a Fairy for dinner or you won't cross..

Got everything working except the testing of the Fairy to make sure it is a Fairy and not just any old object.

Any clues what I'm doing wrong? It's definitely leaving the default state but then nothing.

 

default
{
    state_entry()
    {
        llAllowInventoryDrop(TRUE);
    }                           
    changed(integer change)
    {
        if (change & CHANGED_ALLOWED_DROP);

        state test;
    }
}
state test
{
    state_entry()
    {
        string  ItemName;
        ItemName = llGetInventoryName(INVENTORY_OBJECT, 1);
         if (ItemName == "NaS-T Fairy") {
            llSay(0, "Thanks for the dinner!");
            llSleep(2);
            llSay(0, "You are a Winner!");
            llSleep(2);
            llSay(0, "The bridge is now clear");
            llSleep(2);
            llSay(0, "You may pass with no fear.");
      }
}

 

Share this post


Link to post
Share on other sites

Hi Artorius,

It's been ages since I've scripted, but I think your script should respond to the first object dropped into it, but it'll be dead after that. Your test state has no change event handler, so it'll execute on entry, handle the first dropped object, then go idle forever after.

Why not put your test code inside the change event and do away with the test state entirely? Also, the script will only test the identity of the first object dropped into it. A second person dropping something into the prim will, even if you fix the error I've mentioned, get whatever response the first dropper got. I think you want to test the name of the last object dropped into the prim, which you'd get using...

 

integer count = llGetInventoryNumber(INVENTORY_OBJECT);ItemName = llGetInventoryName(INVENTORY_OBJECT, count);

 

Or, better yet (because your bridge will eventually fill with objects), toss the object as soon as you get its name...

ItemName = llGetInventoryName(INVENTORY_OBJECT, 1);llRemoveInventory(ItemName);

 

ETA: I also recommend the liberal use of llOwnerSay() to print progress messages, so you know what's going on. You can comment them out once things are working, or make them conditional on a global variable you set/clear. Like this

if (debug){llOwnerSay("message");}

if you set debug = 1, every debug message will print, if you set debug = 0, everything goes quiet.

 

Share this post


Link to post
Share on other sites

Thx! I'll go at it again. Took a dinner break.

The testing object is a temp rezz object itself.

The Bridge rezzes the Troll on collision. The troll just delivers the chat message and then waits for the Fairy.

Once it gets a Fairy it will open the bridge then die and a new one will rezz for the next person.

Share this post


Link to post
Share on other sites


Artorius Constantine wrote:

Thx! I'll go at it again. Took a dinner break.

The rezzing object is a temp rezz object itself.

The Bridge rezzes the Troll on collision. The troll just delivers the chat message and then waits for the Fairy.

Once it gets a Fairy it will open the bridge then die and a new one will rezz for the next person.

Ah, kk. That solves the filling inventory problem. I still think the test state is unneeded, but can't explain why it doesn't work. The first (and only) object dropped on the thing should flip states and the test should work. Use llOwnerSay(ItemName) to make sure of the ItemName your capturing. (I added to my original post, reread it).

  • Like 1

Share this post


Link to post
Share on other sites

 

ItemName = llGetInventoryName(INVENTORY_OBJECT, 1);

Indexing inventory items starts at zero. So if the dropped Fairy is the only object in the trolls inventory, it should look like this:

 

 

ItemName = llGetInventoryName(INVENTORY_OBJECT, 0);

Or for the last object:

ItemName = llGetInventoryName(INVENTORY_OBJECT, llGetInventoryNumber(INVENTORY_OBJECT) -1);

 

 

Share this post


Link to post
Share on other sites

Try changing the change event to

    changed(integer change)    {        if (change & CHANGED_ALLOWED_DROP)        {              state test;         }    }

 

Also in the test state  you still have the inventory index number issue raised by arton 

Share this post


Link to post
Share on other sites


arton Rotaru wrote:

 
ItemName = llGetInventoryName(INVENTORY_OBJECT, 1);

Indexing inventory items starts at zero. So if the dropped Fairy is the only object in the trolls inventory, it should look like this:

 

 
ItemName = llGetInventoryName(INVENTORY_OBJECT, 0);

Or for the last object:
ItemName = llGetInventoryName(INVENTORY_OBJECT, llGetInventoryNumber(INVENTORY_OBJECT) -1);

 

 

Oops, that's the answer, Arton. I should have caught that.

Share this post


Link to post
Share on other sites

Yes that was the final answer. Got it done just before 2 AM lol

It worked, then it didn't then it did, bleeh.

After a long struggle I finally changed that 1 to a 0 an it works.

Using OnwerSay as a flow test worked a treat too. I forgot to do that too.

I think I was in to big a hurry.

Not sure how or why I messed that up but that was the issue. 1 instead of 0 that is.

I also changed the handler to INVENTORY_CHANGE instead of allowed drop.

I think because I am the owner it was ignoring my drops.

Either way it works a charm now! I'll drop you both a copy today when I get it packed up =)

Share this post


Link to post
Share on other sites

Madelaine McMasters wrote:

Oops, that's the answer, Arton. I should have caught that.

I bet Snugs did caught that right away, but kept you in the dark purposely. :matte-motes-little-laugh:

Share this post


Link to post
Share on other sites

another suggestion would be llGetInventoryType

changed(integer change)    {        if(change & CHANGED_INVENTORY)        {            if(llGetInventoryType("NaS-T Fairy") == INVENTORY_OBJECT)            {                //do something            }        }    }

or add even more of a test, to make sure someone's not cheating llGetInventoryCreator

changed(integer change)    {        if(change & CHANGED_INVENTORY)        {            if(llGetInventoryType("NaS-T Fairy") == INVENTORY_OBJECT)            {                key objcreator = llGetInventoryCreator("NaS-T Fairy");//creator of the object                key scriptcreator = llGetInventoryCreator(llGetScriptName());//creator of this script                if(objcreator == scriptcreator)//they both have the same creator, so this person was not cheating                {                    //do something                }            }        }    }

Share this post


Link to post
Share on other sites

I tried the Get creator call. I think the infamous "semi colon after the if statement" got me. It was late and I was seeing funny.

Complex if/ else gets it. Simple if doesn't, or the other way around. What's a quarternion anyway? =p

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...