Check with Lua Script if an item is Dragged?

  • #1, by MortoAllegroWednesday, 25. February 2015, 12:52 9 years ago
    there is a way to check via script if an item menu is Dragged?
    there is a property like "game.itemDrag.state == true" that i can check it via scripting?
    i mean, i need a way to know if an item in the menu are dragged and in use on screen, and if they are not, than change inventary state.

    any clue?

    Newbie

    44 Posts


  • #2, by SimonSWednesday, 25. February 2015, 15:25 9 years ago
    If you are dragging an item it is in game.UsedItem.
    So you can test game.UsedItem:getId().id ~= -1

    Thread Captain

    1581 Posts

  • #3, by afrlmeWednesday, 25. February 2015, 15:57 9 years ago
    If you are dragging an item it is in game.UsedItem.
    So you can test game.UsedItem:getId().id ~= -1


    I used...
    if not game.UsedItem:isEmpty() then
     -- do something
    end
    


    I suppose Simon's method is fine too. There is actually a field for determining if an item is dragged, but it's more to do with destination action / command. Checking if an item is held, should be enough regardless of whether it is dragged or has been manually set with the set item command.

    Imperator

    7278 Posts

  • #4, by MortoAllegroWednesday, 25. February 2015, 19:46 9 years ago
    thank you for the quikcly response.

    according to your script i'll try to change the state of my 'Mouse interface' via script but i do not find nothing on the wiki like setCommand("the_interface_name") or changeCommand, or changeInterface..

    if not game.UsedItem:isEmpty() then
      setCommand("the_interface_name") <-- this part is only for what i mean..
    end
    


    i have attached this script in the right mouse action on visionaire.

    there is around a Glossary that explain how to interact with visionaire?

    Newbie

    44 Posts

  • #5, by afrlmeWednesday, 25. February 2015, 20:08 9 years ago
    You are wanting to set the command?

    game.ActiveCommand = Buttons["button_name"]
    

    or... (alternative to specific command)
    game.ActiveCommand = Interfaces["interface_name"].InterfaceButtons["button_name"]
    

    or... (set standard command)
    game.ActiveCommand = Interfaces["interface_name"].InterfaceStandardCommand
    

    Imperator

    7278 Posts

  • #6, by MortoAllegroThursday, 26. February 2015, 11:34 9 years ago
    thank You for the script explanation..
    that was useful ^^

    Newbie

    44 Posts

  • #7, by MortoAllegroThursday, 26. February 2015, 12:32 9 years ago
    hi AFRLme ^^

    ok. i was warking on this script:

    function onMouseEvent(eventType, mousePosition)
      if eventType == eEvtMouseLeftButtonDown and game.UsedItem:getId().id ~= -1 then
        -- mouse left was activated, do something
    	Conditions["Dropped_si"].ConditionValue = true
      end 
     if eventType == eEvtMouseRightButtonDown and Conditions["Dropped_si"].ConditionValue == true then
        -- mouse right was activated, do something
    	game.ActiveCommand = Interfaces["base_cursore"].InterfaceStandardCommand
    	Conditions["Dropped_si"].ConditionValue = false
      end 
    end
     
    registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp, eEvtMouseWheelUp, eEvtMouseWheelDown})
    


    i have two interface:
    the general pointer that i use to walk around my character
    and another one that contain "look" and "use" command that i switch and use only on the inventory and active obj.

    the problem occurred when i'm back by a dragged item, when i press the right click on mouse.
    in this case the cursor change back to the base cursor that i'll use to walk around but maintain the text "use" that belong to the inventory interface.

    that's why i'll try to restore my character interface by clicking on right mouse via script.
    i was thinking that i'll need this because i have two action in one upon the right click.

    one action is "next command" that i use to switch upon action like "look" and "use", only on activeobject and inventory,
    and the other one is to prevent a bug of mine that occurred when i'm back on dragged item that need to change the interface back to the normal walking cursor.

    i do not know if i have explained myself in the right way. ^^

    Newbie

    44 Posts

  • #8, by afrlmeThursday, 26. February 2015, 12:51 9 years ago
    Only one interface should contain command buttons.

    Quick question: do you really need to have additional commands if you are only planning on having use & look? You might as well use a single command (broken sword) interface.

    A single command interface consists of one command: left_click, which would be used for all interactions. You define in the actions that right click or double click or whatever should be used for looking at objects, characters & items. You can change cursors with the set cursor action part on mouse over of objects, that way you can define exactly what cursor you need to be displayed such as: use, take, examine, push, pull, etc...

    Personally I always use single click interfaces myself, as they are a lot faster to rig up & use, than multiple command interfaces. plus they are good for cross-compatibility too - mobiles & tablets etc.

    P.S: you don't have to add the == true part to your scripts query. Lua automatically detects true or false for boolean values. So you can simply write...
    if Conditions["test"].ConditionValue then -- if condition test is true
    

    or...
    if not Conditions["test"].ConditionValue then -- if condition test is false
    

    ...however, you can use whichever method you like! wink

    P.P.S: You don't technically have to add all the mouse event parameters to the mouse event handler. If you don't add any flags then it will automatically make them all available. You only need to declare parameters if you only want to be able to access certain ones.
    registerEventHandler("mouseEvent", "onMouseEvent")
    

    Imperator

    7278 Posts

  • #9, by MortoAllegroThursday, 26. February 2015, 13:20 9 years ago
    uhm.. i have 3 interface on my game.

    i have 3 interface on my game.

    1) an interface that i active on action area that change my icon set to "left right and down" way (they are arrow for change scene)
    2) an interface that i use for inventory/objc that contain " look and use"(that i switch between them by press right click)
    3) the cursor base (the pointer that i use for walk around)

    the problem is on dragged inventory system that does not restore the pointer when i quit by pressing right click..(the pointer change back but "use" text still remain.)

    i need always and only two interaction on scene object and inventory object, that are "look and use", and i need to switch between them by pressing right click.
    but always and only if i'm upon an object even if they are in scene or in inventory

    do you think single interaction works like this?

    Newbie

    44 Posts

  • #10, by MortoAllegroThursday, 26. February 2015, 13:28 9 years ago
    sorry i have forgot the interface for character interaction.

    the problem are that i have different icon set for different interaction.

    example:
    interaction with characters are "speech and look" and i need to switch between them by pressing right mouse click.
    another are object interaction that have "use and look" icon set that need to switch.

    if i have one interface, when i press right click and add "set command next" on it i switch between all the buttons command.

    this is the problem.

    Newbie

    44 Posts

  • #11, by afrlmeThursday, 26. February 2015, 13:49 9 years ago
    What I meant is that only one single interface should contain the command buttons. If you have multiple interfaces with command buttons associated with the character, then it is probably confusing the engine. There should be no reason to spread out command buttons over multiple interfaces. The command interface should be the one at the top of your interface list & the rest of interfaces, such as: inventory, ui & mini-games, etc, should all be listed below.

    Imperator

    7278 Posts