Results 1 to 3 of 3

Thread: Object.call() question

  1. #1

    Object.call() question

    I have a bunch of objects with a button that calls a Global function. The code is below.

    Code:
    setupParams = {
                   charSheet = self,
                   location = {'Tokyo','87f386'},
                   assets = {'.18 Derringer'},
                   improve = 1
    }
    
    self.createButton({
                    click_function = 'setupInvestigator',
                    function_owner = self,
                    label = 'Set Up '..self.getName(),
                    position={0,1,1.9},
                    width = 1080,
                    height = 300,
                    font_size = 100
                  })
    
    function setupInvestigator()
      Global.call('setupInvestigator',setupParams)
      printToAll(self.getName()..' has entered the investigation!',{0.75,0.75,0})
      self.removeButton(0)
    end
    This code works perfectly well when I click the button. The problem however is when I get a reference to this object and try to call

    Code:
    Object.call('setupInvestigator')
    ...the function doesn't run. And if I try the following to get the setupParams table to call the Global function myself I get a nil table as a result.

    Code:
    Object.getTable('setupParams')
    I've been banging my head against this for a while and my gut tells me I need to go through and put the variable in onload() or something. After staring at this for hours, I think somebody else needs to put me out of my misery.

  2. #2
    Join Date
    May 2016
    Posts
    1,072
    Without seeing your global code, it is hard to say (at least for me). So I recommend:
    • Check Object in global, right before you try call or getTable, and make sure you are referring to the correct object. Print its guid and make sure its the right GUID for your scripted object.
    • Object.call() in global would have to be inside of some function (I use onLoad when doing testing, personally).

    If your problem is not stemming from either of those issues, please share your global. I personally tend to write up a short demo script that displays the problem. But my guess is that Object is not referencing the entity with the script on it.

  3. #3
    The Object.call() isn't coming from global, rather a function being executed on another object.

    I've tested that my object is referencing the correct thing, I used:

    Code:
    print(Object.getName())
    print(Object.getLuaScript())
    Everything comes back fine. My global script is currently over 1000 lines so it might be a bit of a pain to paste it here, but here's the script from the object that's trying to execute the Object.call() function. The "Object" here is "lurkerInv".

    The printToAll() line after the function call was my way of figuring out the line I was crashing on. We all have our own debugging methods

    Code:
    preludeStage = false
    
    function onload()
      titleText = getObjectFromGUID('082b95')
      ancientBag = getObjectFromGUID('996e2e')
    end
    
    function wrapUp()
      if preludeStage == false then
        buttonList = self.getButtons()
        for i=0,#buttonList do
          self.removeButton(i)
        end
        titleText.setValue('Choose a difficulty and set up an Ancient One')
        local ancientPos = ancientBag.getPosition()
        local currentPos = self.getPosition()
        ancientBag.setPosition(currentPos)
        self.setPosition(ancientPos)
        ancientBag.setRotation({x=0,y=180,z=0})
        Global.setVar('ancientExists',false)
        ancientBag.shuffle()
        ancientBag.createButton({
          position = {-3,0.25,4.5},
          height = 700,
          width = 1700,
          font_size = 500,
          label = 'Normal',
          click_function = 'setupNormal',
          function_owner = self
        })
        ancientBag.createButton({
          position = {3,0.25,4.5},
          height = 700,
          width = 1700,
          font_size = 500,
          label = 'Hard',
          click_function = 'setupHard',
          function_owner = self
        })
      else
        local selfButtons = self.getButtons()
        for i,v in pairs(selfButtons) do
          self.removeButton(v.index)
        end
        self.createButton({
          position = {-7,2,0},
          height = 1500,
          width = 3000,
          font_size = 1700,
          label = 'Draw 3',
          click_function = 'draw3',
          function_owner = self
        })
        self.createButton({
          position = {7,2,0},
          height = 1500,
          width = 3000,
          font_size = 1700,
          label = 'Draw 4',
          click_function = 'draw4',
          function_owner = self
        })
        self.createButton({
          position = {0,0.25,10},
          height = 1500,
          width = 3000,
          font_size = 1700,
          label = 'Done',
          click_function = 'wrapUp',
          function_owner = self
        })
        titleText.setValue('Draw and set up investigators')
        preludeStage = false
    
        local chosenPrelude = Global.getVar('chosenPrelude')
        if chosenPrelude == 'Lurker Among Us' then
          local drawParams = {
            drawFrom = self,
            drawCoords = {x=-34.57,y= 1.16, z=-23.32},
            drawRotation = {0,180,180},
            shuffle = true,
            callback = 'dl',
            callbackOwner = Global,
            drawSearch = 'Mark Harrigan'
        }
          local lurkerInv = Global.call('drawCard', drawParams)
          print(lurkerInv.getName())
          local setupParams = lurkerInv.getTable('setupParams')
          print(setupParams==nil)
          for i, v in pairs(setupParams) do
            print(i)
          end
          Global.call('setupInvestigator', setupParams)
          printToAll('lol',{1,1,1})
          drawParams = {
            drawFrom = Global.getVar('assetBag'),
            drawTo = lurkerInv,
            shuffle = true,
            drawRotation = {x=0,y=180,z=180},
          }
          Global.call('drawCard', drawParams)
          Global.call('getClue', lurkerInv)
          Global.setTable('preludeInfo', lurkerInv.getTable('setupParams.location[1].gate'))
        end
      end
    end
    EDIT:

    I've since moved everything to a separate function and started it as a coroutine, allowing me to yield and give the object more time to initialise. This seems to fix most of my problems.
    The callback function of takeObject() looks like it delays everything just long enough to start accessing some but not all parts of the object you pull out of a bag.
    Either way, I think this fixes my issues. Thanks Sir Stump!
    Last edited by frisbee09; 02-10-2017 at 12:37 PM.

Similar Threads

  1. [ADDED] Could really use an API call for: objectLeftContainer(object, container)
    By MrStump in forum Scripting Suggestions
    Replies: 9
    Last Post: 03-12-2017, 09:12 PM
  2. Call a global function from a local script
    By enigma in forum Scripting
    Replies: 2
    Last Post: 08-09-2016, 02:14 AM
  3. [Newbie question]Getting an object reference error
    By TheGentlemanGamer in forum Scripting
    Replies: 5
    Last Post: 07-11-2016, 10:45 AM
  4. Replies: 2
    Last Post: 03-10-2016, 03:52 AM
  5. object/graphic question
    By kasagawa in forum General Discussion
    Replies: 1
    Last Post: 08-23-2015, 09:30 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
  •