How to play a sound when u click an item in inventory?

  • #10, by AkcayKaraazmakFriday, 11. September 2015, 13:48 9 years ago
    Yea Lee but there is no possibity to write an action for the left click. Just double click, right click, mose roll over etcc but no left click :\

    Great Poster

    440 Posts


  • #11, by sebastianFriday, 11. September 2015, 13:50 9 years ago
    the problem is that there is no "left click" available on the items itself.

    But i guess you were also able to just use the mouse properties in the main game tab and there under "left click" check if an item exists and play the sound...

    Thread Captain

    2346 Posts

  • #12, by AkcayKaraazmakFriday, 11. September 2015, 13:50 9 years ago
    @Sebastian, Great it worked mate. If current object is item. Thank you so much mate again! You are always a life-saver!

    Great Poster

    440 Posts

  • #13, by afrlmeFriday, 11. September 2015, 13:54 9 years ago
    Ah you meant for the left click action. Got you. I wonder why the items don't have an immediate left click action for them...

    Imperator

    7278 Posts

  • #14, by AkcayKaraazmakFriday, 11. September 2015, 14:12 9 years ago
    Yes Lee. But Sebastian's solution is great, its like using left click grin

    Great Poster

    440 Posts

  • #15, by ke4Friday, 11. September 2015, 14:18 9 years ago
    You can also use the eventHandler as Lee mentioned. It would looks something like that.

    function itemClick()
    if mouseStatus == 1 then
    local items = game:getLinks(VGameItems)
    for i = 1,  #items do
    if game.GameCurrentObject:getName() == items[i]:getName() and game.GameUsedItem:isEmpty() then
    startSound("vispath:soundpath.ogg")
    end
    end
    end
    end
    
    registerEventHandler("mainLoop", "itemClick")
    


    mouseStatus = nil
    
    function onMouseEvent(eventType, mousePosition)
    if eventType == eEvtMouseLeftButtonDown then mouseStatus = 1 end
    end
     
    registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseLeftButtonDown})
    

    Key Killer

    810 Posts

  • #16, by afrlmeFriday, 11. September 2015, 14:19 9 years ago
    I think I'll add it as a request to the dev bug / feature tracker & see if it might be possible to include in a future update.

    Imperator

    7278 Posts

  • #17, by afrlmeFriday, 11. September 2015, 14:24 9 years ago
    You can also use the eventHandler as Lee mentioned. It would looks something like that.

    function itemClick()
    if mouseStatus == 1 then
    local items = game:getLinks(VGameItems)
    for i = 1,  #items do
    if game.GameCurrentObject:getName() == items[i]:getName() and game.GameUsedItem:isEmpty() then
    startSound("vispath:soundpath.ogg")
    end
    end
    end
    end
    
    registerEventHandler("mainLoop", "itemClick")
    


    mouseStatus = nil
    
    function onMouseEvent(eventType, mousePosition)
    if eventType == eEvtMouseLeftButtonDown then mouseStatus = 1 end
    end
     
    registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseLeftButtonDown})
    


    um not quite. wink

    I was talking mouse event handler only. Query on left click if object below cursor exists & if so... is it an item? if yes then we call a called by other action containing a play sound action - I don't think the openAL Lua sound engine stuff is working correctly at the minute?

    Also for on mouse move, we create a state variable "isItem = false" which we use to determine if we have already triggered the mouse enter item action. So if item below cursor exists, is an item & isItem = false then call action containing the play sound, then set isItem to true, elseif object below cursor does not exist & isItem = true, then set isItem to false. Similar to using a condition in the editor.

    Imperator

    7278 Posts

  • #18, by ke4Friday, 11. September 2015, 14:35 9 years ago
    Don't know if it works correctly but it plays the sound, not sure about settings volume etc.

    Yeah i use more then one mouse event for mouse events so i'm use to separe it into loops...

    Is there a better way to chceck if object is an item rather then looping through a table?

    Key Killer

    810 Posts

  • #19, by afrlmeFriday, 11. September 2015, 14:46 9 years ago
    Yeah there's actually a data structure field.
    if game.CurrentObject.IsItem then -- IsItem returns boolean true or false
     -- do something
    end
    


    P.S: you don't really need multiple mouse events. You could create functions which you call from inside of the mouse events instead.

    
    onMouseEvent(eventType, mousePosition)
     if eventType == eEvtMouseLeftClick then
      function_one(); function_two()
     end
     if EventType == eEvtMouseMove then
      function_one()
     end
    end
    
    function function_one()
     print( (game.ScrollPosition.x + getCursorPos().x), (game.ScrollPosition.y + getCursorPos().y) )
    end
    
    function function_two()
     print("true")
    end
    
    registerEventHandler("mouseEvent", "onMouseEvent")
    

    Imperator

    7278 Posts

  • #20, by ke4Friday, 11. September 2015, 15:05 9 years ago
    Thanks it's useful field & right no need to have more loops, didn't realize that. :-)

    Key Killer

    810 Posts