Accessing an item's values

  • #1, by CBCMikeThursday, 05. May 2016, 21:52 4 years ago
    Hi there,

    New to the forums and Visionaire, but not new to programming.

    Here's the context: I have an inventory that contains items that can hold a certain amount of water. These items have a value, called 'volume' that has an initial value of 0.

    When I mouseover the inventory, I want to display that value as part of the action text. I have no problem retrieving the object under the cursor and checking to see whether it is the correct item, it's the next step that has me stuck.

    I can set a global variable for the the volumes, but that's an ugly hack and I'd like to keep values associated with the items themselves.

    How can I access the values of my current object? I think I'm just missing something in the syntax and the docs/tutorials don't seem to touch on this.

    If, for instance, I have the object stored in the variable 'obj', how would I access and get a value named 'volume' ?

    Thanks!



    Newbie

    4 Posts


  • #2, by afrlmeThursday, 05. May 2016, 22:04 4 years ago
    game.CurrentScene.SceneObjects["example"].ObjectValues["volume"].Int
    1
    2


    Tip #1: did you know that you can display the integer or string of a VS value inside of a display text, display narration text or display object text action part?

    There are <v=volume> liters of water available
    1
    2


    Tip #2: it's all about naming convention. Always give everything you create a unique name & then you will be able to access them globally without any conflict issues due to having other visOBJ's (visionaire objects) with the same name.

    Hope this helps & welcome to the Visionaire Studio community mate. Happy developing. wink

    Imperator

    6842 Posts

  • #3, by CBCMikeThursday, 05. May 2016, 22:25 4 years ago
    Thanks for the quick update, but that didn't seem to work. I'm trying to grab a value from an Item that's in an inventory slot... is that considered a SceneObject?

    I pulled some of your code from the wiki to test out what's under the mouse cursor.

    local obj = game:getLink(VGameCurrentObject)
    if obj:getId().tableId == eObjects then
    local isItem = obj:getBool(VObjectIsItem)
    local itemName = obj:getTextStr(VObjectName)
    if isItem then
    if itemName == "Large jug" then
    return 'current item: ' .. itemName .. ' (x/5 pints)'
    elseif itemName == "Small jug" then
    return 'current item: ' .. itemName .. ' (x/3 pints)'
    else
    return 'current item: ' .. itemName
    end
    else
    return 'current object: ' .. itemName
    end
    end
    return '<empty>'
    end

    registerHookFunction("getActionText", "myActionText")

    I'm getting hung up on pulling values from the current 'obj' in the code.

    My goal is to substitute the 'x' in the two jug returns for a value called "volume" in each of the items. The items themselves are called "large_jug" and "small_jug" in the Items tab, with object names "Large jug" and "Small jug".



    Newbie

    4 Posts

  • #4, by afrlmeThursday, 05. May 2016, 23:14 4 years ago
    Would you be willing to share your ved & resources with me so I can take a quick look at what you are doing?

    & no... an inventory item is not considered a scene object as it belongs under interfaces.

    Imperator

    6842 Posts

  • #5, by sebastianFriday, 06. May 2016, 09:48 4 years ago
    This item slots are inside an interface, right? You could do the following:

    Create for each fill state a Button and name it properly (10% filled, 20% filled, etc). These buttons have no polygon. They are just tjere to provide you the names...

    For each inventory slot you now can set
    On mouse leave: set to standard command
    On mouse enter: set command to one of the above mentioned buttons depending on your value.


    Hope this helps

    Ps. I would prefer to rename the item and not the actiontext...but thats up to you smile

    Thread Captain

    2337 Posts

  • #6, by sebastianFriday, 06. May 2016, 10:04 4 years ago
    Hmm as i overread your code above im not quite sure if the methid i mentioned above is right for you. Because items in the inventory are changing its position quickly there has to be a test if the current object under the cursor is an item.
    That could also be done with action parts. Testing if the item is your large jug is - of my knowledge- only possible with lua. So it would make sense to use it right away.
    As you did in your script it checks all relevant parts.
    But in your function you only return the text... You have to setValue it for that items language text. Hope that is the hint you are missing smile

    Thread Captain

    2337 Posts

  • #7, by CBCMikeFriday, 06. May 2016, 16:33 4 years ago
    To ARFLme: I could share my ved, but it's really just a messy playground right now. A character can grab an item, you can bring up an inventory interface at any time, and when you mouse over items in the inventory, I'd like to be able to display the unique properties of the items.

    My real question is one of syntax, I believe. I have an object stored in a variable. That object is an item. That item has an integer value attached to it.

    That value could change, depending on what the user does with the item. I'd like a way to both get and set that value.

    If the answer is: you need to cycle through the items in an interface and compare the name to the current item under the mouse, and then reference what I need through the interface, then, okay. I can try that. But that seems silly when I already have a reference to the object I want.

    Newbie

    4 Posts

  • #8, by afrlmeFriday, 06. May 2016, 19:17 4 years ago
    You can mouse over items, but you will need to use Lua script with the mouseEvent handler/listener as there's currently no on mouse enter/leaves actions for items for some reason.

    Imperator

    6842 Posts

  • #9, by CBCMikeFriday, 06. May 2016, 19:36 4 years ago
    Thanks for the response. I'm doing most of this with Lua script.

    At this point in the script:

    if itemName == "Large jug" then
    return 'current item: ' .. itemName .. ' (x/5 pints)'

    I already have retrieved the object under the cursor, 'obj', and I've tested to see if it's an item (it is), and I've even pulled the item's name from the object:

    local itemName = obj:getTextStr(VObjectName)

    Is there any way, using some similar syntax, to get the object's VALUES?

    If I use:

    local objVals = obj:getLinks(VObjectValues)

    How would I traverse the objVals object to find the value I need?

    I've solved the issue already using global variables, but this is Object-oriented code, and I'd like to be able to keep those variables local to the objects.

    Thanks again for all the help! Just trying to wrap my head around the limitations. smile



    Newbie

    4 Posts

  • #10, by afrlmeFriday, 06. May 2016, 22:29 4 years ago
    To iterate through a list of something you need to use the for loop...

    local val = obj.ObjectValues

    for i = 1, #val do
    if val[i]:getName() == "something" then
    -- do something
    elseif ...
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9


    I think you get the idea. But if it's got a specific name already then just use that. Or give each value the same name. It's ok to use same names for things if you only plan on direct access linking. Bad idea when you plan on accessing things globally though as it can cause conflict issues.

    Imperator

    6842 Posts

Write post