[Solved] Using a Value to show an object and hide the others

  • #1, z bananeisafreeThursday, 24. November 2016, 22:55 hodinky 8 years ago
    Hi again !

    Is there a way to use a value instead of a condition to "show" or "hide" an object ?

    In practice, I would like to have an inventory that looks like a PDA thingy, with every items listed on the side. And when you click on one item, an image(and/or an animation) would appear on the center of the screen with info regarding clicked object.

    I could of course create a condition for every descriptiont, set for every item an action that would change the related description's condition to true and , one by one set the others to false.
    it wil work ...  but will get tidious very quickly, since you need for every item to set manualy the conditions for all the other items to be false.

    The most easy way to deal with it is to use a value to define what image is to be showed, and set an action on every item changing that value to the related image description.

    Thank you in advance !
    Cesar

    Fanoušek fóra

    120 Posts


  • #2, z afrlmeFriday, 25. November 2016, 03:19 hodinky 8 years ago
    No, not currently, but additional methods for being able to hide/deactive interaction of scene objects has been requested multiple times. Hopefully Simon will add something into a future update or fingers crossed the upcoming update. Personally I would like something along the lines of an action box in which we can add multiple instances of query related actions such as conditions, values, language, etc.

    Imperátor

    7285 Posts

  • #3, z bananeisafreeFriday, 25. November 2016, 12:48 hodinky 8 years ago
    Darn, that's a bummer ...

    Ok, So I guess my best chance would be to go the conditions way.
    I'm "working" (by that understand that I'm looking for every script on the wiki and more to try to figure out the part I need for what I want to achieve) on one, and there the idea :

    In VS set an action on every item so that when clicked they set a value (val_itemID) to a number specific to every item (item1 sets the value to 1, item2 to 2 and so on ...).
    Create a condition for every item "description card" (cdt_card1, cdt_car2 etc ...)
    Create an execution script that would 

    1) Store the value of val_itemID on a variable
    2) Compare the value to the number contain in the name of every condition entry.
    3) change the corresponding condition value to TRUE
    4) set the other to false.

    As I said, I'm not script proffessional, right now i'm kindof struggling with the data structure of Visionaire. Is there a way to get the conditions linked only to one of visionaire entry (all the condition that ar storred in an interface for exemple) ? Or do I need to make a table selecting only the conditions that got the common part of the name ?

    ... I don't know if I'm clear :p

    Fanoušek fóra

    120 Posts

  • #4, z afrlmeFriday, 25. November 2016, 13:38 hodinky 8 years ago
    Struggling a bit with the last message you posted...

    You could create a Lua table that contains all of the conditions & when you click / or hover over an item have it iterate through all of the table entries & have it set each one to false except the one you want to display or just use the table to reset them all back to false on mouse out.

    Technically you don't even need to create on mouse enter / out actions for the items either as you can use the Lua mouse event handler function to check if an object under the cursor is an item on mouse move & if so then set the condition linked to the item as true. You could also store the previous item inside of a variable & have it check if the item doesn't equal nil & the object below the cursor is nil or isn't the previous item then set that condition to false. It kind of gets rid of needing to create tons of actions for each object but you will need to create a condition with the same name inside of each items condition tab, something along the lines of "visible" & then link that to the image/animation you want to display - of course you could also use the mouse event to only register clicks instead.

    local prev = nil
    
    function mouseEvt(typ, pos)
     if typ == eEvtMouseLeftButtonUp then
      if game.CurrentObject.ObjectIsItem then
       if prev ~= nil and prev ~= game.CurrentObject then prev.Conditions["visible"].ConditionValue = false end
       if prev ~= game.CurrentObject then game.CurrentObject.Conditions["visible"].ConditionValue = true; prev = game.CurrentObject end
      end
     end
    end
    
    function reset_prev()
     if prev ~= nil then
      prev.Conditions["visible"].ConditionValue = false; prev = nil
     end
    end
    
    registerEventHandler("mouseEvent", "mouseEvt")


    ... I'm not sure if it will work as I wrote it out off the top of my head with a little remembering help from the wiki - bad memory & all that.

    Anyway, what the script is doing there is checking on left click release if an item is underneath the cursor & if the prev variable isn't nil and isn't the current item underneath the cursor then it changes the condition linked to that to false then it checks if the current item isn't what's linked inside of the prev variable & if it isn't then it changes the condtion linked to that to true then sets that item as the prev item.

    So what you need to do is create a condition inside of each item & name it "visible" set it to false by default. Next you will be wanting to create a button for each information thing inside of the interface & link the condition inside of the properties tab for it to determine when it should be visible or hidden. Finally you will be wanting to reset the final stored items condition to false on closing the interface, so you would add an execute a script action part & include reset_prev() inside of it.

    Quick note: I had a thought - my brain still seems to be half asleep even though it's almost dinner time over here. Instead of conditions & a button for each piece of information you could just create one button & add each bit of information inside of it as an animation. So instead of changing a condition you play & stop animations instead. Would be much neater, but I'm not going to write up a function for that just yet... brain's currently not up to it.

    Imperátor

    7285 Posts

  • #5, z bananeisafreeSaturday, 26. November 2016, 13:37 hodinky 8 years ago
    I love how your "half asleep brain" manages to think of solution simpler and more efficient than my coffee infused brain ..

    I will tinker with the mouse event handler, and see what I can achieve that way (again, clumsy brain is clumsy)

    The animation idea is a great one, I thought of something of the sort, but fumbled when trying to achieve it, and then got carried away with my talbes crazyness.

    Thank you for all that insight Lee !
    I'll post what I managed to achieve.

    Cheers

    Fanoušek fóra

    120 Posts

  • #6, z afrlmeSaturday, 26. November 2016, 13:49 hodinky 8 years ago
    I actually created/used an animation method for ALLD or for someone elses project before. I forget which & obviously I'd forgotten all about it when I started replying yesterday.

    It's amazing what you can do with a variable / value & a few if queries & small function or two or three or four - ah, yes... I'm sure you get the general idea.

    https://wiki.visionaire-tracker.net/wiki/StartAnimation
    https://wiki.visionaire-tracker.net/wiki/StopAnimation

    & I believe you can check if an animation is already active with...
    if ActiveAnimation["test"].AnimationActive then
     -- do something
    end

    ... I find it strange that AnimationActive data structure field is inside of the ActiveAnimations table rather than the general Animations table where it makes more sense.

    Imperátor

    7285 Posts

  • #7, z bananeisafreeMonday, 28. November 2016, 14:17 hodinky 8 years ago
    Yeah, The lua scripting is, in itself a strange beast to me (again, more of a writer than coder ...)  ... But the Visionaire DataStructure logic especially is as clear as a wall of brick ...


    So I played around a bit, and, using your insight, found something that, I think, is quite satisfactory.
    It's quite low level so it might seems trivial to you.
    Basicaly on every click on an item

    1) call script : 

    local n=getObject("Values[val_itemId]"):getInt(VValueInt)
    
    
    
    local anim = getObject("Animations[anim_itemInfo"..n.."]")
    
    stopAnimation(anim)

    2) change value val_itemId to the corresponding number (1 for item 1, 2 for item 2 ...)

    3) call script : 

    local n=getObject("Values[val_itemId]"):getInt(VValueInt)
    
    
    
    local anim = getObject("Animations[anim_itemInfo"..n.."]")
    
    startAnimation(anim)


    Does it seems overcomplicated/convoluted to you ?

    Fanoušek fóra

    120 Posts

  • #8, z afrlmeMonday, 28. November 2016, 14:48 hodinky 8 years ago
    Basically the same script, from what I can see, except in one you are stopping the previous animation & in the next starting the new one.

    If it works, it works. Personally I would have used a single function to handle it, but that's just me & as I just said: "if it works, it works!" & in the end that is all that matters. So, well done! wink

    Imperátor

    7285 Posts

  • #9, z bananeisafreeMonday, 28. November 2016, 15:23 hodinky 8 years ago
    Ok , I'm puting a (solved) tag on the title then.


    Again, thank you for your time !

    Fanoušek fóra

    120 Posts

  • #10, z afrlmeMonday, 28. November 2016, 15:50 hodinky 8 years ago
    No problem, no problem at all. smile

    Imperátor

    7285 Posts