Results 1 to 10 of 10

Thread: Could really use an API call for: objectLeftContainer(object, container)

  1. #1
    Join Date
    May 2016
    Posts
    1,072

    Could really use an API call for: objectLeftContainer(object, container)

    Request: objectLeftContainer(object, container) and possible objectEnterContainer(object, container)

    Reason: We currently have no simple way to check for an object leaving a container. You can use onObjectSpawned to run a check every time an object is created on the table to check if it is within the area of a scripting zone, but if the bag is moved that method becomes much messier. You can put an onLoad() on the item leaving the bag that triggers when it exits the bag, but again we're using a scripting zone to check around it to see if it just left the bag, which can get complicated.

    As for objectEnterContainer(), we current use onCollisionEnter to detect things touching a bag, but this throws false positives as well as multiple reports for a single action.

    --------

    Basically, this would simplify a lot of code that has to run often, dig through lists of objects in scripting zones, etc. Ideally it could work for stacks of tiles+chips as well as decks and bags. Although, admittedly, I have only ever had a need for it with bags or, maybe, decks.
    Last edited by MrStump; 03-12-2017 at 09:13 PM.

  2. #2
    Added to my list of missing events: [url]http://www.berserk-games.com/forums/showthread.php?3541-TTS-Scripting-is-missing-essential-events[/url]

  3. #3
    How about this:

    Store a variable inside the bag:
    Code:
    lastAmountOfItems = 0
    function onLoad()
        lastAmountOfItems = #self:getObjects()
    end
    Then every time an object is spawned, compare the object's position and the bag's position to work out whether it was taken from the bag and then compare the new amount of items with the old amount of items. If it's different, setVar() the old value to the new value and viola you have your bag object.

    Of course it would be easier to have this function as well as a lot of others for convenience's sake...

  4. #4
    Join Date
    May 2016
    Posts
    1,072
    Yeah, there are workarounds. So far, the least-impact way I have found is using onCollisionEnter on a bag and updating a list (which gets saved by onSave) of its contents. Then use the new onObjectSpawn on the bag so any time a new object is spawned, you compare the old list to the current contents and if one is missing it can be assumed that it was taken from the bag. And my method won't work on infinite bags or decks that run out. I worry that it might miss things, too.

    As for your method, I do enjoy using distance as a way to avoid scripting zones, but I worry about false positives if they have an object near the bag.

    I agree it would be a convenience function, but I also worry that any solution I've seen can potentially miss things. For example, for a recent project I had a scripting zone that I wanted to scan for an object in when it was loaded out of a bag. So I put a trigger on the object in the bag for onload. When it came out, the code would run but it wouldn't detect itself. It had "loaded" but not in such a way that the scripting zone would detect it. I had to make a coroutine and yield for 1 frame to actually detect it. =/

  5. #5
    Quote Originally Posted by MrStump View Post
    Yeah, there are workarounds. So far, the least-impact way I have found is using onCollisionEnter on a bag and updating a list (which gets saved by onSave) of its contents. Then use the new onObjectSpawn on the bag so any time a new object is spawned, you compare the old list to the current contents and if one is missing it can be assumed that it was taken from the bag. And my method won't work on infinite bags or decks that run out. I worry that it might miss things, too.

    As for your method, I do enjoy using distance as a way to avoid scripting zones, but I worry about false positives if they have an object near the bag.

    I agree it would be a convenience function, but I also worry that any solution I've seen can potentially miss things. For example, for a recent project I had a scripting zone that I wanted to scan for an object in when it was loaded out of a bag. So I put a trigger on the object in the bag for onload. When it came out, the code would run but it wouldn't detect itself. It had "loaded" but not in such a way that the scripting zone would detect it. I had to make a coroutine and yield for 1 frame to actually detect it. =/
    If you pull an object from the bag, held_by_color also won't be nil (unless you hold the bag and alt+right click to drop the object out).

  6. #6
    Join Date
    May 2016
    Posts
    1,072
    Good point. Another loophole is that it depends on container (so a "deck style" container wouldn't always use heldbycolor).

    Yeah, I'd really enjoy a universal solution lol

  7. #7
    This got added today, but I realized we don't have the inverse objectEnterContainer(object, container) which would be equally useful I think.

  8. #8
    Join Date
    May 2016
    Posts
    1,072
    At least we have onCollisionEnter for that, which works fairly well. It was the taking out that was more difficult to deal with haha I'm very pleased!

  9. #9
    Join Date
    Nov 2015
    Location
    Canada
    Posts
    89
    Would onObjectLeaveContainer( Object container, Object leave_object ) work? It gives you the container it left, and the object being spawned.

  10. #10
    Join Date
    May 2016
    Posts
    1,072
    Yes, that was added recernly to solve this issue. I'll mark it solved =)

Similar Threads

  1. Use multiple additional arguments to obj.call()
    By my_hat_stinks in forum Scripting Suggestions
    Replies: 2
    Last Post: 03-09-2017, 12:50 PM
  2. Object.call() question
    By frisbee09 in forum Scripting
    Replies: 2
    Last Post: 02-10-2017, 12:17 PM
  3. Puzzles lock when taken out of a container
    By customKarma in forum Bug Reports
    Replies: 1
    Last Post: 11-29-2016, 12:43 PM
  4. Call a global function from a local script
    By enigma in forum Scripting
    Replies: 2
    Last Post: 08-09-2016, 02:14 AM
  5. Replies: 2
    Last Post: 03-10-2016, 03:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •