Results 1 to 8 of 8

Thread: Problems with placing objects....

  1. #1

    Problems with placing objects....

    Still trying to finish off this script I am working on and I have run into a strange problem, that is all though my script.

    Basically, even using exact position / rotation and scale values (taken from copying data from a save file)... objects are getting placed slightly differently than I am expecting.

    Now in most cases this is not an issue. As I move the objects slightly above where they are supposed to go and then they drop, as they drop they snap to the snap point below them.

    Still there are a few objects that are causing problems, mainly map objects. These objects I wish to come in locked and when they come in everything's all strange. Now there are some other locked objects that have the same problem but it is undetectable by the player so I never noticed it until I found the map errors.


    Here is an example of the problem on an object I do not care about... see how it is kinda "inside" the table?

    See even though the values are taken either from the file or from that helper object tool Markimus wrote (I tried up to 9 decimal places) form the object when it is stitting on the ground properly, the object when it is locked onto the table is kinda wonky.


    Same object after unlocking it

    If I make the object move above the ground plain of the table it locks in mid air and freezes there.

    Now as I understand it there is a system in place called "callback" but I do not really know how to use it. Is there a way to have the object lock after completely finishing its movement, so I could move it to the spot form the bag, maybe a tiny but off the table, it drops, and THEN freezes.

    At the moment my code just freezes it instantly as soon as it is placed.

    Code:
        if TrueBag ~= nil then
            local takeParams = {}
            local function cb() end
            takeParams.callback = "cb"
            takeParams.callback_owner = self
    
            for i = 1, #TrueBag:getObjects() do
                if coreMissionBags[bm][i] ~= nil then
    
                    if coreMissionBags[bm][i].locked ~= nil then
                        table.insert(lockObj, TrueBag:takeObject(coreMissionBags[bm][i]))
                    elseif coreMissionBags[bm][i].shuffle ~= nil then
                        table.insert(shuffleObj, TrueBag:takeObject(coreMissionBags[bm][i]))
                    elseif coreMissionBags[bm][i].drawsigs ~= nil then
                        signelDrawPile = TrueBag:takeObject(coreMissionBags[bm][i])
                    elseif coreMissionBags[bm][i] ~= nil then
                        TrueBag.takeObject(coreMissionBags[bm][i])
                    end -- END IF
    
                end -- END NIL TEST
            end -- End For Loop
    
            if lockObj[1] ~= nil then
                for i=1, #lockObj, 1 do
                    lockObj[i]:setLock(true)
                end
            end
    
            if shuffleObj[1] ~= nil then
                for i=1, #shuffleObj, 1 do
                    shuffleObj[i]:shuffle()
                end
            end
    
            if signelDrawPile ~= nil then
                signelDrawPile:shuffle()
                signelDrawPile:setLock(true)
            end
    
            if coreMissionSignels[bm] ~= nil then
                for i = 1, #coreMissionSignels[bm] do
                        signelDrawPile.takeObject(coreMissionSignels[bm][i])
                end
            end
        end -- END 1st IF Statment of if bag was empty
    [url]http://pastebin.com/8iC6REfA[/url]

    This is my code for drawing the objects from the bag....

    Basically I have a variable value in addition to the position/rotation called "locked" (as well as others for drawing and shuffeling).. during the get form bag stuff, it looks for that flag "locked" and if it is locked adds the objectID into a variable called lockObj... then as long as that variable is not equal to nil it will loop through it and lock all the objects it contains. (or shuffle them or draw from them or w/e)

    So.. assuming my 1 week of self taught coding makes any sense.. can anyone point me to a way to fix this strange error?

    See this video for visual examples... in it I show the error in the map tiles using the tool for position data and then I paste in "exact" data copied directly from the save file where I manually placed everything.

    [url]http://screencast-o-matic.com/watch/cbnXn76iIk[/url]

  2. #2
    I think I have this working now.. I had to completely redo the loading function from scratch and I got a lot of help from stump... still it seams to have fixed the problem by correctly using "call back".... .

    [url]http://screencast-o-matic.com/watch/cbnXQx6irO[/url]

    As you can see it looks very different.. you can even see the event deck shuffling (the one that is many parts falling into one deck) so that is cool... and the signals (the last 3 small hexes moving out) come out much more delayed and stuff..... but the important part is now the objects are sitting on the table correctly (even though they are still locked)\

    So thanks for everyone's help...

    the only problem I have now is that in my old script I destroyed the setup button when I was done.. but now the same code destroys it before everything is finished and screws up the end of the put to table : (

    Code:
            --Delete Button Object
                local killme=getObjectFromGUID("1306c6")
                killme.destruct()
    I tried adding a "wait" function but it got a error about core processors and stuff I do not understand...

    Code:
    function waitFrames(ms)
    t = os.clock()
        while t + ((ms * 0.001) * 16.67 ) > os.clock() do
        coroutine.yield(0)
        end
    you trigger it with "waitFrames(40)" or something.

    Any suggestions on how to remove the button completely when done?
    Last edited by Tragic; 02-11-2017 at 04:41 AM.

  3. #3
    Join Date
    May 2016
    Posts
    1,072
    Wait will only work in a corotuine, not in a callback (if that is where you were using it).

    Try this wait function by Mark, time is in seconds:

    Code:
    function wait(time)
      local start = os.time()
      repeat coroutine.yield(0) until os.time() > start + time
    end
    You could also just remove the button not the object itself, leaving that burried in the table

    local killme=getObjectFromGUID("1306c6")
    killme.removeButton(indexOfButton) --or killme.clearButtons()

  4. #4
    Quote Originally Posted by MrStump View Post
    Try this wait function by Mark, time is in seconds:
    Wait, that's by me? I don't recognise that...

    And yes, you can't coroutine.yield() outside of a coroutine.

    Try this function:
    Code:
    function waitFrames(frames, function_name)
        function actualWaitFramesCoroutine()
            for i = 1, frames do
                coroutine.yield()
            end
            _G[function_name]()
            return 1
        end
        startLuaCoroutine(Global, "actualWaitFramesCoroutine")
    end
    Then you can chain functions, like this:
    Code:
    function onLoad()
        print("Hello!")
        waitFrames(5, "printNextMessage")
    end
    
    function printNextMessage()
        print("Hello can you hear me!?")
    end

  5. #5
    Join Date
    May 2016
    Posts
    1,072
    lol WHOOPS I mean Sancho's. I got mixed up lol I was just crediting you for your informational index cards and I got all mixed up!

  6. #6
    Join Date
    Sep 2016
    Posts
    219
    For the record I stole it from Google somewhere

  7. #7
    Join Date
    May 2016
    Posts
    1,072
    Like half of all my scripting knowledge came from Google too lol

  8. #8
    There are no "programmers" anymore.. just Stack Exchange : P

Similar Threads

  1. [SOLVED] Image Problems
    By Tynion in forum Technical Support
    Replies: 2
    Last Post: 10-13-2016, 05:40 AM
  2. Tool for easily placing many items, such as domino chains?
    By 00Dani in forum General Discussion
    Replies: 4
    Last Post: 03-29-2016, 06:18 PM
  3. Replies: 1
    Last Post: 03-29-2016, 12:24 PM
  4. [SOLVED] Problems with mod loading.
    By rusty_dragon in forum Technical Support
    Replies: 2
    Last Post: 01-03-2016, 07:32 AM
  5. Replies: 0
    Last Post: 11-25-2015, 09:24 PM

Posting Permissions

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