Custom command property names for same interface action button (use door handle, pickup coin, press button)

  • #10, by AlexSunday, 09. February 2014, 21:41 11 years ago
    I haven't read the whole thread, but maybe this helps:
    http://wiki.visionaire-tracker.net/wiki/RegisterHookFunction

    couldn't you use the getActionText hook function? e.g. create a value for each object with the same value name. in the hook function you read the actual value of the current object and set the appropriate command name.

    Great Poster

    378 Posts


  • #11, by andiliddellSunday, 09. February 2014, 21:59 11 years ago
    that sounds feasible, with my limited knowledge of these things smile

    Where could i find the syntax and structure of the getActionText function. I'm very new to this and cant seem to find that in the wiki?

    I understand how to make a hook function, but dont know the syntax of how that hook function will receive the incoming action text, and how i need to amend and pass on the action text to the screen?

    Any help would be very gratefully received, its proving a real sticking point for me.

    Forum Fan

    178 Posts

  • #12, by andiliddellSunday, 09. February 2014, 22:46 11 years ago
    Looking back at the original method it looks like all properties of button cannot be scripted. or the properties are private and not accesible.

    This simple code shows that the ButtonName (which is meant to hold the command text) is listed as Nil, when in actual fact i have entered it as "take/use" in the editor.
    
    local btn = getObject("Interfaces[coin_disc1].InterfaceButtons[Action_Coin]")
    
    --Called on mouse over the interface button
    function newName()
      local btnName = btn.ButtonName
      print("name is", btnName)
    end
    
    


    Result= 21:41:53: name is nil

    It seems the same for all other properties listed on the button datastructure

    Can anyone confirm this, and if so is there any chance these properties could be made editable in a future release?

    Forum Fan

    178 Posts

  • #13, by afrlmeSunday, 09. February 2014, 23:27 11 years ago
    I figured it out... after a load of hassle mind you! razz

    I wasn't thinking correctly & forgot that it is the language texts that you need to edit & not the button/object/character name as they are the object name & not the displayed names.

    will post something in a bit, after I've polished up the code. it's really messy at the minute as I've commented out & changed various bits all over the place.

    Imperator

    7285 Posts

  • #14, by andiliddellSunday, 09. February 2014, 23:59 11 years ago
    Excellent, I can't wait, I've been struggling for hours, and decided to move on for now. Chuffed you can help! smile
    Learnt alot about LUA in my struggles tho, so every cloud and all that razz

    Is there a good tutorial in how to drag and drop items from inventory onto scene objects too in a similar fashion where the context is object specific?

    For example:

    use KEY on DOOR or alternatives like give CARROT to DONKEY

    Sorry to add YET ANOTHER question just as your solving this one. I've been seeing the amount of support you give on these forums and its bloody impressive. Keep up the great work!

    Forum Fan

    178 Posts

  • #15, by afrlmeMonday, 10. February 2014, 01:49 11 years ago
    sorry I've not replied in a wee while; having issues with electric. shitty storm raging on outside.

    It's good that you are willing to get down & dirty with the Lua side of things. a lot of people aren't really willing to give it a try, as you can achieve most things via the action parts alone.

    In regards to support: I'm the English support for the community & wiki, which is why I reply to most threads. I mostly manage to provide help but sometimes it eludes me as I'm more of a visual person; meaning I prefer to check out the problem myself in the .ved file or via screenshots etc.

    -- * --

    hmm you mean to literally left click, hold & drag an item over another item, character or object? in vs there is a built in option for drag & drop but it doesn't work in the way you would think. confused me at first as it works by left clicking on an item which it then automatically sets the currently held item as the item you clicked on & sets the mouse cursor as the item image & then will remain as current item/cursor until you left click on a character, item, scene object, empty space or cancel it with right click etc. strange system.

    you can also manually set currently held items & commands with action parts & define what can be used on each object, character etc via "executed" actions.

    -- * --

    Ok, so, here's the script, all in working order; I tested it multiple ways by setting up some debug options so I could quickly change the game language & the integer value of "cmd_state".

    To use it you want to set the active command to your interaction one on mouse over the interaction action area & then execute a script containing: renameBtn()... You need to set the value of cmd_state on mouse over each object, character etc...
    --[[
    Global action rename function (v1)
    Written by AFRLme
    -- * --
    alternatingfrequencies@hotmail.com | skype @ AFRLme
    --]]
    
    -- * local variables * --
    local texts, btn, val, t  -- empty variables
    
    -- * tables * --
    t = {}
    t["de"] = {"Benutzen", "Nehmen", "Drucken", "Ziehen"}
    t["en"] = {"Use", "Pick up", "Push", "Pull"}
    t["es"] = {"Usar", "Cojer", "Empujar", "Tirar"}
    t["fr"] = {"Usage", "Prendre", "Appuyer", "Arracher"}
    
    -- * function * --
    function renameBtn()
     val = getObject("Values[cmd_state]"):getInt(VValueInt) -- get current value
     btn = game:getLink(VGameActiveCommand):getLink(VButtonName) -- store current command
     texts = btn:getLinks(VTextAll) -- get all texts related to the button
     -- * --
     for i = 1, table.maxn(texts) do
    
      if texts[i]:getLink(VTextLanguageLanguage):getName() == "English" then
       texts[i]:setValue(VTextLanguageText, t["en"][val])
      elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "French" then
       texts[i]:setValue(VTextLanguageText, t["fr"][val])
      elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "German" then
       texts[i]:setValue(VTextLanguageText, t["de"][val])
      elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "Spanish" then
       texts[i]:setValue(VTextLanguageText, t["es"][val])
      end
     end
    end
    

    I've not sorted out the resetBtn() function yet. too late now & I'm not in the mood to code anything else.

    Imperator

    7285 Posts

  • #16, by andiliddellMonday, 10. February 2014, 15:49 11 years ago
    Thanks so much for this, I wont get a chance to implement it till this evening,(im at work at the moment) but looking forward to getting it done.

    I'm guessing the reset should be simpler, to just put the language text back to blank ready for the next interaction

    --------------------
    On the drag and drop question:
    I was actually referring to the built in drag and drop "click to lock object to mouse" interface. I don't mind it really it would just be great if when you hovered the "held" item over a scene object the actions text told you what the resulting action would be i.e.

    "give carrot to donkey"
    or
    "use carrot with blender"

    It's a shame specific scene objects don't have an "action text" field for certain inventory item interactions

    If "object_carrot" is held over "blender" then show action text "blend Carrot"

    It would give scope for unique and interesting interaction text, with a more human feel.

    Now I'm just rambling... i should get back to work. razz

    Thanks again Ill let you know how i get on this evening

    Forum Fan

    178 Posts

  • #17, by andiliddellTuesday, 11. February 2014, 00:21 11 years ago
    Excellent it works a charm!! thanks so much.

    However, there's some brackets missing before all of your else if commands, to close the setvalue()

    ... all hail the message log smile

    errors:
    23:11:33: Error: Failed to run string in Lua: [string "--[[..."]:28: ')' expected (to close '(' at line 27) near 'elseif'
    23:11:33: Error: Failed to run string in Lua: [string "--[[..."]:28: ')' expected (to close '(' at line 27) near 'elseif'

    ---------
    On the topic of the standard drag method (where an item locks to the cursor once you click it in the inventory) should the Action text show things like "use key on door" as you mouse over scene objects or isn't that supported by default?

    Forum Fan

    178 Posts

  • #18, by andiliddellTuesday, 11. February 2014, 00:29 11 years ago
    I've corrected the bracket typo, and added a clearBtn function and an empty string at position Zero in each language table. I'm guessing it works, there's no errors, but it updates so quick on mouse enter ITs hard to tell.

    Ive just added a call to clearBtn on the mouse leave action of my interface button.

    --[[
    Global action rename function (v1)
    Written by AFRLme
    -- * --
    alternatingfrequencies@hotmail.com | skype @ AFRLme
    --]]
    
    -- * local variables * --
    local texts, btn, val, t, zero  -- empty variables
    
    -- * tables * --
    t = {}
    t["de"] = {"", "Benutzen", "Nehmen", "Drucken", "Ziehen"}
    t["en"] = {"", "Use", "Pick up", "Push", "Pull"}
    t["es"] = {"", "Usar", "Cojer", "Empujar", "Tirar"}
    t["fr"] = {"", "Usage", "Prendre", "Appuyer", "Arracher"}
    
    -- * function * --
    function renameBtn()
     val = getObject("Values[cmd_state]"):getInt(VValueInt) -- get current value
     btn = game:getLink(VGameActiveCommand):getLink(VButtonName) -- store current command
     texts = btn:getLinks(VTextAll) -- get all texts related to the button
     -- * --
     for i = 1, table.maxn(texts) do
    
    if texts[i]:getLink(VTextLanguageLanguage):getName() == "English" then
       texts[i]:setValue(VTextLanguageText, t["en"][val])
    elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "French" then
       texts[i]:setValue(VTextLanguageText, t["fr"][val])
    elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "German" then
       texts[i]:setValue(VTextLanguageText, t["de"][val])
    elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "Spanish" then
       texts[i]:setValue(VTextLanguageText, t["es"][val])
      end
     end
    end
    
    -- * function * --
    function clearBtn()
     val = 0 -- Uses String from position zero of each language table which is set to an empty string
     btn = game:getLink(VGameActiveCommand):getLink(VButtonName) -- store current command
     texts = btn:getLinks(VTextAll) -- get all texts related to the button
     -- * --
     for i = 1, table.maxn(texts) do
    
    if texts[i]:getLink(VTextLanguageLanguage):getName() == "English" then
       texts[i]:setValue(VTextLanguageText, t["en"][val])
    elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "French" then
       texts[i]:setValue(VTextLanguageText, t["fr"][val])
    elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "German" then
       texts[i]:setValue(VTextLanguageText, t["de"][val])
    elseif texts[i]:getLink(VTextLanguageLanguage):getName() == "Spanish" then
       texts[i]:setValue(VTextLanguageText, t["es"][val])
      end
     end
    end
    


    Forum Fan

    178 Posts

  • #19, by afrlmeTuesday, 11. February 2014, 00:38 11 years ago
    hmm they are in the script... it's some bug with the code blocks that removes ) when placed directly after ]... I think it started doing it after I asked Thomas & Calli to prevent emoticons in the code blocks. I'll send Calli a message the morrow & see if he can find out what's up with it.

    dragged objects are just the item set as the cursor I think? not sure if it shows an action text for it? you could I suppose use the manual method (more work for you; yay! razz) & set command + item & then change cursor to reflect the item. this of course would be mean that you would need to add a cursor for each item with the item images to the cursor section. but that could actually be quite fun as you can assign inactive & active state animations for them. blah blah blah... more theoretical gibberish from me.

    P.S: here's the pastebin link for the script: http://pastebin.com/QwawbtVt - copied straight out of vs.

    Imperator

    7285 Posts

  • #20, by andiliddellTuesday, 11. February 2014, 01:22 11 years ago
    Thanks again AFRLme.

    Im now trying to code the manual action text for the dragged item razz

    I've dived into the data structure wiki and think i can build my own custom action text (for dragging an item over a scene object) from the current GameUsedItem, plus some of the renamebut function above, to get the cmd_state and finally the scene Object Name as you mouse over it.

    Ive fallen at the first hurdle as i can't seem to get the string name of the GameUsedItem mentioned in the datastructure under the game table

    local activeObj
    
    function dragItem()
       activeObj= game:getLink("VGameUsedItem"):getName() -- get current gameusedItem name
       print("active dragged object:", activeObj)
    end
    
    


    I'm unsure of whether i should be using game:getLink or game:getObject and what the differences between :getStr(VValueString) and :getName() are?

    Forum Fan

    178 Posts