Thread: Need help grabbing a token
-
August 2nd, 2019, 03:49 #1
- Join Date
- Jun 2018
- Posts
- 112
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);
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
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!
~DiablobobLast edited by Diablobob; August 2nd, 2019 at 03:56.
-
August 2nd, 2019, 07:49 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
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
-
August 2nd, 2019, 19:11 #3
- Join Date
- Jun 2018
- Posts
- 112
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
Again, any assistance with this is greatly appreciated...
V/r,
~DiablobobLast edited by Diablobob; August 2nd, 2019 at 19:16.
-
August 2nd, 2019, 21:38 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
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
-
August 23rd, 2019, 18:09 #5
- Join Date
- Jun 2018
- Posts
- 112
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!
-
August 26th, 2019, 04:56 #6
...and now this!
https://www.youtube.com/watch?v=_r6L...outu.be&t=2566rob2e - 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
-
August 26th, 2019, 12:09 #7
- Join Date
- Jun 2018
- Posts
- 112
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.
-
August 26th, 2019, 15:49 #8rob2e - 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
-
August 26th, 2019, 17:05 #9
- Join Date
- Jun 2018
- Posts
- 112
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