5E Product Walkthrough Playlist
  1. #1

    Need help grabbing a token

    So... I am having another issue... suprise suprise... lol

    I am trying to add a functionality to move a specific token when you press the mouseclick down on a token...

    The problem I am having is, I can select the token using
    Code:
    image.selectToken(token, true);
    but when I move the mouse with the button still held... it still moves the originally pressed on token...

    code thus far... I kept it simple to try to isolate the function at this time...

    Code:
    function onInit()
    	Token.onClickDown = onClickDown;
    end
    
    function onClickDown(token, button, image)
    	if not Input.isControlPressed() and (button == 1) then
    		image.clearSelectedTokens();
    		local imgTokens = image.getTokens();
    		for _, v in pairs(imgTokens) do
    			local nodeChar = CombatManager.getCTFromToken(v);		
    			local sClass, sRecord = DB.getValue(nodeChar, "link", "", "");
    			if sClass == "charsheet" and sRecord ~= "" then
    				local sOwner = DB.getOwner(sRecord);
    				if sOwner == "Players" then
    					Debug.console("Players Owned Token = ", v);
    					image.selectToken(v, true);
    				end
    			end
    		end
    	end
    end
    so in this example, when the left mouse button is pressed onto a token, I want the token owned by "Players" to be selected (grabed by mouse) and then that token moved when the mouse moves...

    I do not want the token originally pressed onto to move... I want that token to not be grabbed...

    The correct token in the Debug.console in the script is coming up as "selected"... but it is not being dragged by the mouse movement...

    I am at a bit of a loss... I have tried to Debug.console(dragdata); and put that in a onDrag, onDragStart, onDrop, and onDragEnd... and dragdata always comes up nil... so I am kind of at a loss...

    Any help would be appreciated!
    ~Diablobob
    Last edited by Diablobob; August 2nd, 2019 at 03:56.

  2. #2
    You're not returning true in your onClickDown function to let the client know that the token should continue to get mouse events. When you return nil, it performs the default behaviors. I didn't follow exactly what you are doing (and it's admittedly late for me), but that might help get you going.

    Regards,
    JPG

  3. #3
    it still isn't working... I am having issues figuring out where return true; would be placed... I have tried to place it in every level of the script before the end; 's with no luck...

    so I fleshed out the script a little more... you can likely tell what the end-result is at this point...

    I pushed all secrecy aside on this one, as it is being VERY frustrating, and I think I'm overlooking something super simple... I added comments with thought processes to help travel down the rabbit hole and figure out where I took the wrong turn at Albuquerque...


    Code:
    function onInit()
    	-- client side processing
    	if not User.isHost() then
    		Token.onClickDown = onClickDown;
    	end
    end
    
    function onClickDown(token, button, image)
    	-- if control (targeting button) and shift (ignore key for script) are not pressed then if left mouse button is clicked, do stuff
    	if not Input.isControlPressed() and not Input.isShiftPressed() and (button == 1) then
    		-- get username
    		local usr = User.getUsername();
    		-- get token position
    		local tPosi = token.getPosition();
    		-- get list of tokens on the map
    		local imgTokens = image.getTokens();
    
    		-- time to sort through the tokens
    		for _, v in pairs(imgTokens) do
    			-- if the target token and the token from list are at the same position, process the token stack to find user owned tokens
    			if tPosi == v.getPosition() then
    				-- find the ct node of the list token
    				local nodeChar = CombatManager.getCTFromToken(v);		
    				-- parse the ct node link 
    				local sClass, sRecord = DB.getValue(nodeChar, "link", "", "");
    					-- determine if there is a charsheet
    					if sClass == "charsheet" and sRecord ~= "" then
    						-- find owner of list token
    						local sOwner = DB.getOwner(sRecord);
    						-- determine if owner of list token is the same as the user clicking on it
    						if sOwner == usr then
    							-- select the list token if the user owns it
    							image.selectToken(v, true);
    						else 
    							-- unselect the list token if the user does not own it
    							image.selectToken(v, false);
    						end
    					end
    			end
    		end
    		return true ;
    	end
    	-- need to find the correct place to return true; so that when the mouse is moved, only the user owned tokens are dragged out of the stack.
    end
    After I crack this egg, I plan to figure out how to add in the ability to determine if there is a movement vector ontop of the token (if not owned) and select the movement vector instead... these together should resolve token stacking... if for some reason 2 tokens of the same owner are stacked, click moving will move the stack of owned tokens... if the player wishes to separate the stacked tokens, they can use shift to grab a token to move without grabbing the stack... at least that's my plan...

    Again, any assistance with this is greatly appreciated...

    V/r,
    ~Diablobob
    Last edited by Diablobob; August 2nd, 2019 at 19:16.

  4. #4
    Mouse Events
    You should return a true value if you want the client to not apply standard behavior to the event.

    For controls, whenever a mouse event is triggered, the client will call any registered Lua events.
    If the registered Lua event returns true, then the event is consumed and the default mouse event handling is not used.
    If the event function returns false, then the event is ignored and passed to the next control/window up the hierarchy.
    If the event function returns nil, then the standard behavior for the event for that control is engaged.

    For tokens, it works slightly differently, since multiple event functions can be registered.
    If any registered Lua event function returns true, then the event is consumed after calling all registered event functions, and the default mouse behavior is not used.
    Otherwise, the default mouse behavior is used.

    Movement Vectors
    There are no APIs to interact with token planned movement vectors.

    Regards,
    JPG

  5. #5
    Thank you Moon Wizard!... I was able to fully resolve token stacks in FG!...

    It was a little finicky at first, but when I really dig into what you said, I was able to get it working.

    There was one amazingly good unintended side-effect as well! With token stacks resolved, the player can now grab and continue their movement through another token in the map! So ironically, the next “plan” I stated previously... actually happened... lol

    I found this peculiar, as it tends to lending itself as the token is effectively at position a and position b t the same time (programmatically)... but none the less, i got it to work!

    Thanks again for all the help guys!

  6. #6
    rob2e's Avatar
    Join Date
    Sep 2015
    Location
    Spokane, WA
    Posts
    1,422
    Blog Entries
    13
    rob2e - Join me on Discord!
    Become a Patron!
    Follow me on the Twitters
    Come watch the Twitches... twitch.tv/rob2e
    Also my YouTube Channel
    Available on the FORGE
    My Dungeon Master's Guild Material

  7. #7
    Lol... thanks!...

    the token stacking demo doesn’t start until 42:19 on the video... Incase anyone wanted to jump to it... but the Wildshape automation is cool as well!

    Thanks again Rob!!!
    Last edited by Diablobob; August 26th, 2019 at 12:51.

  8. #8
    rob2e's Avatar
    Join Date
    Sep 2015
    Location
    Spokane, WA
    Posts
    1,422
    Blog Entries
    13
    Quote Originally Posted by Diablobob View Post
    Lol... thanks!...

    the token stacking demo doesn’t start until 42:19 on the video... Incase anyone wanted to jump to it... but the Wildshape automation is cool as well!

    Thanks again Rob!!!
    Ya. If you click on the link, the video starts there. I’m smart.
    rob2e - Join me on Discord!
    Become a Patron!
    Follow me on the Twitters
    Come watch the Twitches... twitch.tv/rob2e
    Also my YouTube Channel
    Available on the FORGE
    My Dungeon Master's Guild Material

  9. #9
    I did not know you could scrub the time in a link... awesome! I learned another new thing today! Booya!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in