Inventory slot processing.

  • #1, by minibigsTuesday, 20. January 2015, 22:50 9 years ago
    OK, so I have my wonderful game inventory built, fully working & shown as a pop up on the screen byu pressing the "i" key.
    The player left clicks/ holds down on the inventory & drags an item out to use it.

    The actions coded are:

    If object below cursor is an item
    Save object
    Set command 'use'
    Execute command on saved object
    Change condition 'item_held' to true
    End if

    'use' is set up as a Combined command & set so items can be dragged with it... I've got "Allow dragging of items from inventory" set on.

    What happens is the item is merrily dragged by the user to whatever object on the scene they want to try to interact with, BUT the item image still remains in the inventory until I delete it (Remove item 'blah' from character 'Current Character').

    What I actually want to happen is that the item image is removed from the inventory when the item is dragged out & then replaced if the intended action fails or the user drag & drops it back (this drag & drop works already).

    The problem being I can't see how to refer to the object/item... i.e. I can't do "remove item(current item)" or equivalent unless I'm missing something?

    The only way I can think of doing it (& please excuse my ignorance, I might be talking rubbish here) is to call a bit of Lua script when user Left clicks on item & use GameUsedItem to determine what is picked up .i.e.

    Say we have 2 items in the game, a ball & a fish....

    Set up following actions:

    remove_ball
    Remove item "ball" from character 'Current Character

    remove_fish
    Remove item "fishl" from character 'Current Character


    New Actions for left click on inventory:

    If object below cursor is an item
    Save object
    Execute script 'what_item_dragged'
    Set command 'use'
    Execute command on saved object
    Change condition 'item_held' to true
    End if


    what_item_dragged script....

    if game:getLink(VGameUsedItem):getName() = "ball" then startAction(wherever.I.stored.it(remove_ball))
    if game:getLink(VGameUsedItem):getName() = "fish" then startAction(wherever.I.stored.it(remove_fish))

    So, is something like the above needed or have I missed a non scripting solution?

    If scripting is needed , am I on the right lines? ... I'm so bad at scripting that I'd appreciate knowing if I've got the general idea before wasting my time.

    Cheers,
    Steve



    Newbie

    79 Posts


  • #2, by afrlmeTuesday, 20. January 2015, 23:18 9 years ago
    You can't remove the item from the inventory, otherwise it would also get dropped completely & you wouldn't be able to use it.

    Someone else asked about this before. My suggestion was to add an image above each of the item slots, so you take note of which slot you have taken the item from & then you display the image over the top of the item. The image would be the graphic of the background/slot. Alternatively you could add as an animation to each of the slots & then play/stop animations as needed.

    In regards to your script: queries need 2 =='s as 1 = is used for setting data. Also you need to include else or elseif's & close of your queries with end.

    if game.UsedItem:getName() == "ball" then
     startAction("Actions[remove_ball]")
    elseif game.UsedItem:getName() == "fish" then
     startActions("Action[remove_fish]")
    end
    


    Personally I think that method would take forever! If you used the same kind of prefix for each action & item name then you could achieve the same thing without having to write millions of queries.

    function removeItem()
     startAction("Actions[remove_" .. game.UsedItem:getName() .. "]")
    end
    

    ...basically I've triggered an action with prefix "remove_" + name of saved item. However as I mentioned above, removing item would not be the way to go about this.

    Imperator

    7278 Posts

  • #3, by minibigsWednesday, 21. January 2015, 00:39 9 years ago
    "Someone else asked about this before. My suggestion was to add an image above each of the item slots, so you take note of which slot you have taken the item from & then you display the image over the top of the item. The image would be the graphic of the background/slot. Alternatively you could add as an animation to each of the slots & then play/stop animations as needed."

    I tried the image over the top before I asked the question, but couldn't work out how to turn the image on & off, so abandoned it (it looks like you can only adjust Scene object visibility from Editor, not items?).

    I tried the single frame animation approach earlier before posting this as well, but again could not get it working & assumed it didn't work ... but reading your reply made me try again as I knew it should work & I've sorted it now thanks.

    I was defining an animation on the actual button I had defined as an item placeholder which did not work because the item image was in front of it covering it on the screen (I only cottoned on when I changed the animation frame to a red square instead of a background match)... Solution ... define an Action area button in front of the item placeholder button & stick the animation in there.

    Cheers,
    Steve

    Newbie

    79 Posts

  • #4, by afrlmeWednesday, 21. January 2015, 01:29 9 years ago
    By applying a condition to the properties tab of each of the buttons containing the cover images. The conditions have to unique to each button. When you apply a condition to a scene object or button, the conditions boolean value will determine if the scene object / button is visible / active, or hidden / disabled. In other words it's as simple as flipping a switch. wink

    P.S: there is no visibility option for button sprites. Visibility is only applicable for scene objects, characters & interfaces.

    P.P.S: maybe the devs would be willing to add an option to the engine which allows you to determine if held item image should be visible or hidden on item hold.

    Imperator

    7278 Posts

  • #5, by minibigsWednesday, 21. January 2015, 01:57 9 years ago
    That might be worth a request to the devs, it would be a nice addition & I'd imagine not too hard to implement.

    Arrgh, of course... I used conditions on Scene objects after you pointed me in the right direction with disabling them to stop object text displaying before I wanted it too... but didn't think of using them on buttons.

    I've got it all working fine with single frame animations & hiding / playing them at the appropriate times....
    Is there much of an overhead playing infinite single frame animations as opposed to condition switching?

    Newbie

    79 Posts

  • #6, by afrlmeWednesday, 21. January 2015, 03:45 9 years ago
    Don't think it makes much difference to be honest, whether it's an image or a looping single frame animation. If you are concerned about loop speed then just add an higher number like 999. wink

    Imperator

    7278 Posts

  • #7, by minibigsSaturday, 31. January 2015, 01:46 9 years ago
    I've revisited this now as I'm doing some more work on my inventory processing.

    When you trigger a "use" command, picking up & dragging an item from the inventory, the item image is removed from the inventory slot, but as it is still in the inventory, when you mouse over it you get the items object name displayed over the empty slot & you can click on it to form combined commands ...

    E.g Assume inventory slot 1 holds item "fish". We select by right clicking, with is defined to command "use".
    We now get a draggable image of a fish, complete with the text "use fish with" & because of the animation fiddle as above, iinventory slot 1 appears empty.
    But if we move over apparently empty inventory slot 1 with the dragged fish, we get "use fish with fish", which looks very odd.

    Any ideas welcome.

    Newbie

    79 Posts

  • #8, by ke4Saturday, 31. January 2015, 09:53 9 years ago
    I was trying to figure this out recently, but i didn't find how to do it with the tile images method to make everything work. I had problems with setting the tile's visibility back. I had in mouse right click properties change chodition for the visibility, but it changed the condition always on second click, on the first just the game droped the item, also with left click with clicking somewhere where isnt any interaction the item kept held.

    Maybe if there would be function which would returns true or false depending on if any item is curently held.
    But as you mentioned there is the problem with the interaction of item with the item itself.


    Key Killer

    810 Posts

  • #9, by minibigsSaturday, 31. January 2015, 12:39 9 years ago
    What I do to detect item held or not is to use "if object below cursor is an item" when the player clicks the "use" mouse button & set a condition "item_held" to true. I set this in the inventory "action on leaving" under it's Properties tab.

    I've got it all working great with using Animations (that are single frame & the same image as the empty slot) rather than actual images as I had the same problems as you with images. You can then play or hide the animation.

    I don't know if it's related to your double clicking problem, but I seem to remember having to change everything to use "Immediate" execution types for my Action scripts rather than "Execution at destination".

    At the moment this looks like a show stopper for me, so I will probably have to change my inventory processing so item images remain in the inventory which you are using the item.



    Newbie

    79 Posts

  • #10, by chronologicFriday, 05. January 2018, 09:02 6 years ago
    I've revisited this now as I'm doing some more work on my inventory processing.

    When you trigger a "use" command, picking up & dragging an item from the inventory, the item image is removed from the inventory slot, but as it is still in the inventory, when you mouse over it you get the items object name displayed over the empty slot & you can click on it to form combined commands ...

    E.g Assume inventory slot 1 holds item "fish". We select by right clicking, with is defined to command "use".
    We now get a draggable image of a fish, complete with the text "use fish with" & because of the animation fiddle as above, iinventory slot 1 appears empty.
    But if we move over apparently empty inventory slot 1 with the dragged fish, we get "use fish with fish", which looks very odd.

    Any ideas welcome.
    Hi, I am setting up my first interface and ran into this same problem, with the action text showing the equivalent of "use fish on fish" or (hoof grease for me) when dragging starts.

    I found a solution that works for me, by storing the value of the "dragged from" slot, and turning on and off the display of the action text when the cursor moves in and out of the corresponding button area.

    So, in the mouse properties, button hold action I have:
    On each item, (e.g. Hoof Grease) the UseInventory command is set up as follows to set the dragged icon.

                                                            

    Then for each inventory slot, (e.g. for Slot 1), the leave / enter is:

                 

                 
    Finally, the HideText script contains:
    game.DrawActionText = 0

    and the ShowText script contains:
    game.DrawActionText = 1


    The result is that when dragging and item starts, the action text is hidden
        

    And when moving outside its slot, it is shown again.
                     
    When returning back to Slot1, it is hidden again.


    Newbie

    25 Posts

  • #11, by sebastianSunday, 07. January 2018, 18:32 6 years ago
    great solution here. Never thought about that.
    Its also possible to use a hook function to rewrite the complete action text when a change gets triggered: "getActionText" . See https://wiki.visionaire-tracker.net/wiki/RegisterHookFunction

    Thread Captain

    2346 Posts