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

  • #10, 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


  • #11, by afrlmeSunday, 21. January 2018, 14:36 6 years ago
    Strange. It should return a true or false boolean value.

    & you are right it could be a conflict issue due to the other script. Only one mouse event handler is allowed per project. Only mainLoop event handlers can have multiple instances.

    Imperator

    7278 Posts

  • #12, by stered86Sunday, 21. January 2018, 15:07 6 years ago
    So that's probably it.
    Do you think it would be possible to combine those two codes or would it be too complicated?

    Newbie

    62 Posts

  • #13, by afrlmeSunday, 21. January 2018, 16:13 6 years ago
    Maybe, not 100% sure though. You could try inserting the code near the top of the other function, you will have to change all instances of typ in the script you are pasting in, to eventType though because that's what Sebastian as called the input variable in his script.

    Imperator

    7278 Posts

  • #14, by stered86Wednesday, 11. April 2018, 11:47 6 years ago
    I'm really sorry to keep instisting on this topic, but I still couldn't find a solution to my problem and my publisher is about to kill me with his bare hands.

    Brief recap: when I have a dragged item over an active object and I press the right button of the mouse, I'd like the engine to clear the dragged item without executing the code associated with that active object.

    My problem is that I have two different codes which use the mouse event handler, while VS only allows to use one. I tried to write a single definition script containing both codes, but to no avail.

    Now I have another idea to solve this issue but I don't know if this can be actually achieved: in every right click action I could insert an "execute a script" action part which should basically say to the engine:

    If game.UsedItem = emptyObject
    execute the rest of the actions listed below
    else
    just clear the currently held item

    As always, my problem is I don't know a thing about lua, therefore I don't have the slightest idea if there is a way to write such a code. Again, I'm in your hands!

    Newbie

    62 Posts

  • #15, by sebastianWednesday, 11. April 2018, 12:10 6 years ago
    do you use the standard drag & drop from VS or built something own?

    With the builtin Version the right click always clears a hold item and as far as i know will not trigger a right click function inside the global mouse actions or anywhere else. Its just doesnt get forwarded. 

    Thread Captain

    2346 Posts

  • #16, by stered86Wednesday, 11. April 2018, 12:28 6 years ago
    I use the standard drag&drop and my version is Visionaire 4.2.5

    In the mouse properties I set the right click to "send character to objects only". I just noticed the problem wouldn't arise if I set it to "do not send character to cursor", but that's not how I want the character to behave (I always want him to face an object before examining it).

    Newbie

    62 Posts

  • #17, by sebastianWednesday, 11. April 2018, 12:37 6 years ago
    to understand it correctly :
    right click is used here for either interacting with an item/object and also it should clear an held item (and therefore not triggering the general right click?) 
    This should work out of the box... 

    you also make use of a mouse handler to do what exactly? 

    could you post the scripts? 

    Thread Captain

    2346 Posts

  • #18, by stered86Wednesday, 11. April 2018, 12:50 6 years ago
    You understood it correctly. I really don't understand why the behaviour of my build is so strange, perhaps I messed something setting up the interfaces or with some definition script. 
    Anyway, these are the scripts. Both codes use the mouse event handler and both codes work, but if I add a third code (provided by AFRLme earlier on this topic) that doesn't work:

    CODE 1 (allows the player to scroll the items of the inventory if he is dragging an item)

    -- author: SimonS (edited by ste red)
    -- Inventory scrolling by mouse wheel
    registerEventHandler("mouseEvent", "mouseEvtHandler") 
    
    function mouseEvtHandler(evt)
        if evt == eEvtMouseWheelUp then
    if not game.UsedItem:isEmpty() then
       wheelUp()
    end
        end
        if evt == eEvtMouseWheelDown then
    if not game.UsedItem:isEmpty() then
       wheelDown()
        end
    end
    end
    
    function wheelUp ()
      local items = game:getLink(VGameCurrentCharacter):getLinks(VCharacterItems)
      local len = table.getn (items)
      local usedItem = game:getLink(VGameUsedItem)
    
      if len == 0 then
          game:setValue(VGameUsedItem,getObject("(-1,-1)"))
      else
          if usedItem:isEmpty() then
            game:setValue(VGameUsedItem,items[1])
          else
            for index = 0, len-1, 1 do
              if items[len-index]:getName() == usedItem:getName() then
                if len-index == len then
                   game:setValue(VGameUsedItem,items[1])
                else
                  game:setValue(VGameUsedItem,items[len-index+1])
                end
                break
              end 
            end
          end
      end
      game:setValue(VGameUsedItemPicked,true)
    end
    
    
    function wheelDown ()
      local character = getObject("Game.GameCurrentCharacter")
      local items = character:getLinks(VCharacterItems)
      local len = table.getn (items)
      local usedItem = game:getLink(VGameUsedItem)
    
      if len == 0 then
          game:setValue(VGameUsedItem,empty)
      else
        if usedItem:isEmpty() then
          game:setValue(VGameUsedItem,items[len])
        else
          for i = 1, len, 1 do
            if items[i]:getName() == usedItem:getName() then
              if i == 1 then
                game:setValue(VGameUsedItem,items[len])
              else
                game:setValue(VGameUsedItem,items[i-1])
              end
              break
            end 
          end
        end
      end
      game:setValue(VGameUsedItemPicked,true)
    end

    CODE 2 (when the player is dragging an item and the cursor reach an active object, the script changes the image of the item:

    function onItemDrag(eventType)
    
        -- set object under cursor and item which is (maybe) dragged
        local curObj=game:getLink(VGameCurrentObject)
    
    
        if not game.UsedItem:isEmpty() then
    
    
     -- if an item gets dragged, get its animation
     local anim = getObject("ActiveAnimations["..game:getLink(VGameUsedItem):getName().."]")
    
     -- dynamically set the frames for the inactive state to the first half of whole animation and the active part to the second half. This results in having also animated items with an inactive/active state
     -- needs a VALUE called "Frames" INSIDE the ITEM. This Value must be set to the same amount of Frames in the whole animation.
    
    
     local framecount = getObject("Objects["..game:getLink(VGameUsedItem):getName().."].ObjectValues[Frames]"):getInt(VValueInt)
    
    
     local inactive_first = 1
     local inactive_last = framecount/2
     local active_first = (framecount/2) +1
     local active_last = framecount
    
     -- debug
     -- print(""..inactive_first.." "..inactive_last.." "..active_first.." "..active_last.."")
    
     -- if mouse moves over an object or NPC character (current char doesn't get tracked)
     if eventType == eEvtMouseMove and (curObj:getId().tableId == eObjects or curObj:getId().tableId == eCharacters ) then
     -- set animation to ACTIVE
       anim:setValue(VAnimationFirstFrame, active_first)
       anim:setValue(VAnimationLastFrame, active_last)
     else
     -- else set animation to INACTIVE to reset it
       anim:setValue(VAnimationFirstFrame, inactive_first)
       anim:setValue(VAnimationLastFrame, inactive_last)
     end
    
     -- if an item gets dragged and a a CLICK action was used, the animation of the item should also be resetted to prevent "always active items" after successful action
      if eventType ~= eEvtMouseMove and not game.UsedItem:isEmpty() and anim ~= nil then
    
           anim:setValue(VAnimationFirstFrame, inactive_first)
           anim:setValue(VAnimationLastFrame, inactive_last)
    
           return true
      end 
    
         end
    end
    
    registerEventHandler("mouseEvent", "onItemDrag", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp}) 
    

    This is the code I'd like to use to force the engine to clear the dragged item instead of executing an action on a object:

    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

  • #19, by sebastianWednesday, 11. April 2018, 13:53 6 years ago
    ok...

    so you are scrolling through the inventory while holding an item? and the cursor changes by scolling? Nice idea.

    You can get rid of your first mousehandler by executing wheelUp() and wheelDown() in the global mouse actions. you just need to include a further "if not game.UsedItem:isEmpty()" check inside wheelUp()/wheelDown() to prevent executing the rest if there is no item active as cursor.

    The second script is for changing the image. Works fine as you already mentioned.
    But here you have a lot of extra flags given to the handler:
    registerEventHandler("mouseEvent", "onItemDrag", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp}) 

    because your script asks for "everything else" in line 40:
    if eventType ~= eEvtMouseMove and not game.UsedItem:isEmpty() and anim ~= nil then
    

    and also return true, it will prevent further code execution and maybe also prevents the engines standard behaviour to clear the held item. 
    You Could try to remove the rightclick flags so they will get ignored by your script and therefore will be handled by the engine.


    The third script uses a mixed bag of old and new methods on getting objects. Maybe 4.25 isnt aware of the newer methods (im not sure here). Maybe the above solution would make this script irrelevant, too.
    The normal D&D System from Visionaire only needs the "allowing dragging of items in inventory" and the "can drag items" checkbox ticket for your "drag command".


    kind regards
    Sebastian

    Thread Captain

    2346 Posts

  • #20, by stered86Wednesday, 11. April 2018, 15:04 6 years ago
    This is becoming stranger and stranger. Before trying your suggestions, I tried removing EVERY definition script to understand if there was a conflict going on and... nothing, the behaviour of the right click is still the same.

    Then I proceeded to download one of the templates in the downloads section (magical potions) and I found out that there is exactly the same problem in that game. Can it be that there is a problem when using a "broken sword" kind of interface?


    Newbie

    62 Posts