Results 1 to 2 of 2

Thread: cannot convert a boolean to a clr type

  1. #1

    cannot convert a boolean to a clr type

    This is driving me crazy. I'd really appreciate some help with this if anyone could.

    I'm trying to pull a card from a deck and place it at a specific position. That part works.

    I'm wanting to flip the card face up. By itself that works. But then I try to do other things, and those happen faster than the card finishes flipping, and everything becomes a huge mess. So I've tried implementing a Wait.condition() for the subsequent events to hold off until the flip is complete. This I cannot get to work at all.

    Here is an example of what I am attempting.
    Code:
    --[[ BEGIN --]]
    function onLoad()
    	GUID_deck = '013288'
    	taken = false
    
    	function stage1()
    		function report()
    			print("taken")
    			taken = true
    		end
    
    		deck = getObjectFromGUID(GUID_deck)
    		parms = {}
    		parms.flip     = true
    		parms.smooth   = true
    		parms.position = {-14,2,12}
    		parms.index    = 1
    		parms.callback_function = report()
    		card = deck.takeObject(parms)
    	
    		function watchTaken()
    			return taken
    		end
    	end --stage1
    	
    	function stage2()
    		function flipReport()
    			print("flipped")
    		end
    	
    		Wait.condition(flipReport(),card.flip())
    	end --stage2
    	
    	--MAIN
    	stage1()
    	-- must wait for the card taken from the deck to instantiate
    	Wait.condition(stage2(),watchTaken())
    end
    --[[ END --]]
    The problem is:
    1) The card ends up flipped but laying on top of the deck instead of the desired location. (If I leave out stage2 (the flip), the card ends at the desired location.)
    2) I get the output of both print statements.
    3) I also get the error:
    Error in Script (Global) function <onLoad>:chunk_3:(31,16-42): cannot convert a boolean to a clr type MoonSharp.Interpreter.Closure

    As best I can determine, this error is occurring in the Wait.condition() even though it is triggering its toRunFunc when the conditionFunc is true. But then the script dies here even though the toRunFunc runs.

    I've tried this with other functions and do not get this error. It seems to be related to the flip() function.

    The documentation at https://api.tabletopsimulator.com/object/#flip says flip() returns bool, and at https://api.tabletopsimulator.com/wait/#condition that the Wait.condition() conditionFunc "is watched until it returns true" which I am taking to imply a bool return. (The documentation there is severely lacking, but I can't find any better.)

    Any thoughts on what I'm doing wrong here?

  2. #2

    tricky

    You have created a monster! After going around several times following your reasoning, I realized you need a delay, not a wait.

    Here is code that should do the trick.
    Code:
    --[[ Lua code. See documentation: https://api.tabletopsimulator.com/ --]]
    deck = getObjectFromGUID("216b68")
    --[[ BEGIN --]]
    function onLoad()
    	GUID_deck = "216b68"
        stage1()
    end
    function stage1()
    	deck = getObjectFromGUID(GUID_deck)
    	parms = {}
    	parms.flip     = true
    	parms.smooth   = true
    	parms.position = {-14,2,12}
    	parms.index    = 1
    	parms.callback_function = report
    	card = deck.takeObject(parms)
    end --stage1
    function report()
        print("taken")
        Wait.time(function() print("flipping") card.flip() end, 0.5)
    end
    You can adjust the delay to the least that lets everything work consistently. Most folks wont really notice a wait on the order of a second.

    The trouble with condition is it doesn't itself create a delay The condition you had was immediately satisfied.
    In addition I was very confused by the way you were putting functions inside one another. Since the report function should be either owned by Global (top level , not inside another function) or by the object script (still top level) with function_owner = self as I understand it, that is how I made this code work.

Similar Threads

  1. [SOLVED] Need A Certain Type of Script
    By MusicGamer in forum Scripting
    Replies: 2
    Last Post: 01-23-2018, 12:41 AM
  2. Replies: 2
    Last Post: 12-28-2017, 05:03 PM
  3. Replies: 2
    Last Post: 07-17-2017, 01:51 PM
  4. Sorted Bag Type
    By McCheesyThePuff in forum Suggestions
    Replies: 7
    Last Post: 01-16-2016, 08:58 PM
  5. New object type?
    By Zinn in forum Suggestions
    Replies: 0
    Last Post: 06-15-2015, 07:50 AM

Tags for this Thread

Posting Permissions

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