Having an item dragged out of inventory and right clicking an object that can be examined.

  • #1, by DrGonzoMonday, 27. February 2017, 09:23 7 years ago
    Hey there,
    the conflict I'm having is already described in the title.
    I'm making use of the so called "Broken Sword" control for my project.
    The inventory contains items that can be dragged. While I'm selecting an item and right click a scene object with the "immediate action" it not simply clears the dragged item, it also calls the examining action for the scene object. This only happens while I set "immediate action" on right click for examining the scene object.  If I use "Execution at destination" the clearing of the item works as it should, but of course this is not what I want. I want the right click generally to clear dragged items first and after that if a scene object can be examined require another right click as usual, "immediate" of course.
    Is there an efficient way to achieve this?

    If not, I thought of a workaround by making items just draggable by clicking on them and holding down the mouse button. After releasing the mouse button and if the item isn't dropped on a certain object/item it just gets cleared. I'm not sure how to achieve this either smile

    Hopefully I described it as clear as possible.
    Thanks for your help.

    Gonzo

    Newbie

    21 Posts


  • #2, by afrlmeMonday, 27. February 2017, 11:46 7 years ago
    This is why I switched to a command only based system. I scrapped using command + item & dragged item methods because both caused issues with on mouse over set command/cursor & right click actions.

    My solution to this was to create a single command called which I called "left_click" which I used as my main command. I then created a command per inventory item which allowed me to assign a custom cursor to each command, which is good because the images used for inventory items are often too large & when dragged the interaction position for them is automatically set to the very center of the image which isn't good. The other problem with using dragged items & command + item system is that there are no action part if queries available to check if character is holding an item - well there's command + item [any], I guess, but still... if you have loads of commands then it ends up getting complicated fast.

    Anyway, moving on... Using a command based system is good for both Broken Sword style interface system & for right click examine as on mouse over you can query if command = x to decide if cursor should be updated & because you are only using one command then if any other command is set besides the default command, it must be an item command.

    It's the same with right click interactions... you can query if command is default command then execute x action parts. If it isn't the standard command then right clicking will do nothing.

    By the way, you would need to add some actions or scripts to the right click action in mouse properties tab under game (cog icon) to reset the current command back to default after say 100ms pause or so as it won't reset back to standard command itself unless you enable always set standard command in game settings tab instead of after successful execution - this would depend on how you need that to be setup.

    Imperator

    7278 Posts

  • #3, by DrGonzoMonday, 27. February 2017, 12:14 7 years ago
    Hey AFRLme,

    thanks for your detailed reply.
    I see this is a common issue, well maybe not issue, more than a conflict I guess..
    Anyhow, you described the conflict pretty good so far. I understand the logic of it, but sadly I can not figure out of how to realize what you described by now...
    I played around with conditions which I set for each item that's been left clicked in the inventory. But I could not find a way to set/reset a kind of global condition for all items in the main game setting for the "right mouse button". This attempt was based on a few other threads I found including the "item_held" idea. Seems like I got that idea wrong.

    After failing with these methods I thought that my secondary solution of left_click and holding the mouse button on an item for dragging it and clearing it after releasing it on an object that can not interact with it would be the best solution.. I could not find a hold button action on items though...any idea on this? In addition, how about the item being attached to the default cursor instead of replacing the entire cursor?

    Sorry for my lack of understanding wink

    Newbie

    21 Posts

  • #4, by afrlmeMonday, 27. February 2017, 13:41 7 years ago
    No worries. I have actually posted screenshots in a recent thread over past couple of months - don't remember the thread name off the top of my head, sorry I reply to too many threads - of the system I use. * edit: found it: here you go. wink

    Problem for me with command + item is that while it lets you set a custom cursor, there's still no action part if query available to check if x command + item is held - there's also no guarantee the item will be removed from hand on successful execution.

    As for your other idea. Sure, you could create an actual dragged item system. It's not too complicated. Basically you need to create an interaction command action for each & every one of your inventory items in the inventory list to set that item with dragged ticked.

    The next step would be to create some actions inside of the mouse properties tab under game settings (cog icon) to clear the currently held item, which should be added to the mouse hold (released) actions. Set Item [empty] > Set Command "standard command" - or whichever you prefer.

    P.S: you could optionally if you prefer use Lua script with a mouseEvent handler to globalize the whole process so you don't have to create actions for each item.

    function mouseEvt(typ, pos)
    
        if typ == eEvtMouseLeftButtonDown and game.CurrentObject.isItem and game.UsedItem:isEmpty() then
            game.UsedItem = game.CurrentObject; game.DestinationItem Picked = true
        elseif typ == eEvtMouseLeftButtonUp or typ == eEvtMouseRightButtonDown then
            if not game.UsedItem:isEmpty() then clearLink(VGameUsedItem); game.ActiveCommand = Interfaces["example"].InterfaceStandardCommand end
        end
    
    end
    
    registerEventHandler("mouseEvent", "mouseEvt") -- start the mouse event handler on game launch
    


    Quick note: have no idea if this script will work as intended. Untested & written from the old noggin, with a bit of reference from the data structure page in the wiki. By the way, "example" in the script needs to be replaced with the name of the interface where the standard command for your game is stored.

    Imperator

    7278 Posts

  • #5, by stered86Thursday, 18. January 2018, 11:02 6 years ago
    Hi, I'm getting an error from this code and I don't know how to solve it. Here's my log, I hope someone can help me!

    10:58:54: Error: Failed to run string in Lua: [string "right_click_clear_item"]:5: '=' expected near 'Picked'
    
    10:58:54: Error: String content: function mouseEvt(typ, pos)
    
    
    
        if typ == eEvtMouseLeftButtonDown and game.CurrentObject.isItem and game.UsedItem:isEmpty() then
    
            game.UsedItem = game.CurrentObject; game.DestinationItem Picked = true
    
        elseif typ == eEvtMouseLeftButtonUp or typ == eEvtMouseRightButtonDown then
    
            if not game.UsedItem:isEmpty() then clearLink(VGameUsedItem); game.ActiveCommand = Interfaces["controllo"].InterfaceStandardCommand end
    
        end
    
    
    
    end

    Newbie

    62 Posts

  • #6, by afrlmeThursday, 18. January 2018, 13:31 6 years ago
    Sorry, my bad. Seems I accidentally added a space in between game.DestinationItem & Picked. It should all be one word like this: game.DestinationItemPicked.

    Imperator

    7278 Posts

  • #7, by stered86Thursday, 18. January 2018, 14:01 6 years ago
    Thank you very much, but now I got another error:

    13:57:55: Error: Failed to execute hook function 'mouseEvt': [string "right_click_clear_item"]:7: attempt to call global 'clearLink' (a nil value)
    
    13:57:56: Error: Unknown data-field "isItem".
    
    13:57:57: Error: Failed to execute hook function 'mouseEvt': [string "right_click_clear_item"]:7: attempt to call global 'clearLink' (a nil value)
    
    13:57:58: Error: Unknown data-field "isItem".
    
    13:57:59: Error: Unknown data-field "isItem".
    
    13:58:01: Error: Unknown data-field "isItem".

    Newbie

    62 Posts

  • #8, by afrlmeThursday, 18. January 2018, 14:41 6 years ago
    Ah, typo again. Sorry. Replace isItem with IsItem.

    I did mention in my original post that I wrote it off the top of my head. grin

    Imperator

    7278 Posts

  • #9, by stered86Friday, 19. January 2018, 10:19 6 years ago
    I'm really sorry to bother you. AFRLme, but the situation is very weird. I checked some lua reference, and it all looks legit, but I still get these two errors:

    10:15:36: Error: Unknown data-field "IsItem".
    
    10:15:37: Error: Failed to execute hook function 'mouseEvt': [string "right_click_clear_item"]:7: attempt to call global 'clearLink' (a nil value)

    Here's my code after your changes:

    function mouseEvt(typ, pos)
    
    
    
        if typ == eEvtMouseLeftButtonDown and game.CurrentObject.IsItem and game.UsedItem:isEmpty() then
    
            game.UsedItem = game.CurrentObject; game.DestinationItemPicked = true
    
        elseif typ == eEvtMouseLeftButtonUp or typ == eEvtMouseRightButtonDown then
    
            if not game.UsedItem:isEmpty() then clearLink(VGameUsedItem); game.ActiveCommand = Interfaces["example"].InterfaceStandardCommand end
    
        end
    
    
    
    end
    
    
    
    registerEventHandler("mouseEvent", "mouseEvt") -- start the mouse event handler on game launch

    Newbie

    62 Posts

  • #10, by afrlmeFriday, 19. January 2018, 16:17 6 years ago
    Try replacing IsItem with ObjectIsItem.

    Clearlink one should be correct, but you could replace that with game.UsedItem = emptyObject.

    Quick question: are you using VS5 or at least VS 4.2.5?

    Imperator

    7278 Posts

  • #11, by stered86Sunday, 21. January 2018, 10:23 6 years ago
    I'm using Visionaire 4.2.5. I was thinking about upgrading to Visionaire 5, but my project is nearly finished and it's working nice with the current version.

    Anyway, I tried those changes and now I only get this error:

    10:15:17: Error: Unknown data-field "ObjectIsItem".

    Here's the code line:

     if typ == eEvtMouseLeftButtonDown and game.CurrentObject.ObjectIsItem and game.UsedItem:isEmpty() then


    I really don't know why the command is not accepted. Could that be a conflict with another definition script? I have set my game so that items are defined with an animation and not a single image. I used this code.

    Newbie

    62 Posts