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

  • #1, by andiliddellSunday, 09. February 2014, 12:59 11 years ago
    Here's a tricky one to explain...

    Im using a Monkey Island 3 style verb coin UI, with three simple buttons TALK, LOOK and ACTION.

    I wanted to avoid having a USE and PICKUP button so have created a generic ACTION button.

    Is there any way for me to customise the onscreen text for specific in game objects?

    For example:

    If I use my ACTION button on a door handle i'd like the onscreen text to say "open door"
    If i use the same ACTION button on a coin i'd need it to say "pickup coin"
    or using the same ACTION button on a big red button it should say "press big red button"

    Is there a way to specifiy per open what its onscreen text will say for each of my interface actions?
    Or can i do a replace hook in LUA?

    Any help would be great! smile

    Forum Fan

    178 Posts


  • #2, by afrlmeSunday, 09. February 2014, 13:43 11 years ago
    hmm... although technically "objectname" & "charactername" are not scriptable, according to the data structure - reason being that the new names won't get saved into the save file - you can still edit them with Lua temporarily.
    -- here's a quick global function example for renaming objects...
    -- to use: add inside of an execute a script action part: renameObj("the objects name", "the command name you want to add")
    
    function renameObj(obj, cmd)
     getObject("Game.GameCurrentScene.SceneObjects[" .. obj .. "]"):setValue(VObjectName, cmd .. " " .. obj)
    end
    

    not tested... but maybe you could create a value in the editor which can be set to x value on mouse over an object which can then be checked with Lua when you select one of the coin sections & then in turn be used to return the correct action prefix from a table you defined in a script. this is just an idea mind.

    & for mouse out or execute command: use another function which resets the name back to default.

    edit: I have an idea for a global function but I'm a bit busy at the minute... will get back to you later on.

    Imperator

    7278 Posts

  • #3, by afrlmeSunday, 09. February 2014, 15:10 11 years ago
    ok, had enough tidying up of the house for now...

    here is a global function for renaming the button name. add the script as a definition script. change the getObject names (inside of the [...]) to whatever you need them to be & also change the string values inside of the table to whatever you need them to be.

    you need to create a single value in the editor & rename it to whatever you changed "cmd_state" to in the script. the interaction button name should be whatever name you changed "use" to in the script.

    how it will work - in theory, as I've not tested it yet - will be by you adding a mouse enter action part for each interactable scene object in which you will set the "cmd_state" value (integer; from 1 to whatever) to reflect which string you need from the table in the script. then when you open the coin interface you should add a mouse over action which contains an execute a script action part:
    renameBtn()
    

    the definition script looks like this:
    -- * local variables * --
    local val
    local btn = getObject("Buttons[use]") -- store interface button
    
    -- * tables * --
    tCmd = {"Pick up ", "Use ", "Push ", "Pull "}
    
    -- * function used to rename objects * --
    function renameBtn()
     val = getObject("Values[cmd_state]"):getInt(VValueInt) -- store number value of value
     btn:setValue(VButtonName, tCmd[val] ) -- ammend required action name to the "use" button
    end
    

    finally you should consider on mouse out of the interaction button action area or on execution of interaction command that the btn name should be reset back to nil.
    -- edit use to whatever you called the interface button...
    getObject("Buttons[use]"):setValue(VButtonName, "")
    

    Imperator

    7278 Posts

  • #4, by andiliddellSunday, 09. February 2014, 15:25 11 years ago
    Ah, this sounds promising, Ive got some sunday afternoon issues to contend with too, so wont be able to test it till later. razz

    Thanks so much for the input, much appreciated.

    PS Just to be clear: this will be altering the action text which appears at the top of my screen automatically because the button name will be changed on mouse over before it is used in the display?

    Forum Fan

    178 Posts

  • #5, by afrlmeSunday, 09. February 2014, 16:06 11 years ago
    yeah...
    on mouse over an object you edit the value which will determine which action name will be selected from the tCmd table & then on mouse over the use button action area you will execute the function which will automatically set the action name based on the current value. you also want to set the command too to make it display the action text.

    not sure about before, but should be instantaneous. I would recommend leaving the use button name empty by default & to clear it again afterwards but it shouldn't matter either way really if you execute the function before setting the command.

    by the way... how does your coin interface work? can it be accessed anywhere on the scene or only when an object &/or character is below the mouse cursor?

    Imperator

    7278 Posts

  • #6, by andiliddellSunday, 09. February 2014, 20:10 11 years ago
    I used the coin interface example from the websites tutorial section, which can appear anywhere in the scene.

    I've been trying the scripts suggested but koep getting errors:

    19:07:36: Warning: Invalid table name (plural):
    19:07:36: Error: Path must start with a valid table-name.

    This seems to be with the :
    local btn = getObject("Buttons[Action_Coin]")

    My Action_Coin button is part of an interface called coin_disc1 which is my main interface, does this have to feature anywhere?

    Forum Fan

    178 Posts

  • #7, by afrlmeSunday, 09. February 2014, 20:27 11 years ago
    hmm... try:
    local btn = getObject("Interfaces[coin_disc1].InterfaceButtons[Action_Coin]")
    

    I've not actually tried manipulating the interface buttons with Lua before, so it is all guesswork, on my part.

    the names that go in the square brackets are case sensitive; they have to match the name you give them in the editor.

    Imperator

    7278 Posts

  • #8, by andiliddellSunday, 09. February 2014, 20:38 11 years ago
    looks like we're both on the same track, unfortunately i still get:

    19:35:45: Warning: Invalid table name (plural):
    19:35:45: Error: Path must start with a valid table-name.

    Ive tried all of these using teh data structure link you sent me yesterday
    getObject("Interfaces[coin_disc1]") --Seems fine
    getObject("Button[Action_Coin]") --invalid table name
    getObject("InterfaceButtons[Action_Coin]") --invalid table name
    getObject("Interfaces[coin_disc1].InterfaceButtons[Action_Coin]") --invalid
    


    Nothing seems to be able to get those objects successfully?

    Forum Fan

    178 Posts

  • #9, by andiliddellSunday, 09. February 2014, 20:44 11 years ago
    Hmmm just tried this:

    local btn = getObject("Interfaces[coin_disc1].InterfaceButtons.Button[Action_Coin]")
    


    And got :
    Error: Field is missing "index". You must give an object-name or a number in square-brackets.

    The dataStructre suggests i need to go through interfaceButtons to get to a button? is there another array f button types on interfaceButtons, or should i be able to get button objects of that button parent?

    Forum Fan

    178 Posts

  • #10, by andiliddellSunday, 09. February 2014, 20:56 11 years ago
    Ive simplified the code to try and root out the issue now im runnign this to just quickly change the text to "wibble" the object..
    local val
    local btn = getObject("Interfaces[coin_disc1].InterfaceButtons[Action_Coin]")
    
    function newName()
     btn:setValue(ButtonName, "wibble" )
    end
    



    Ive got rid of the invalid table issue and now got this:
    19:54:14: Error: Failed to run string in Lua: [string "..."]:7: call to setValue on object A (e,19) failed, first argument is not a number.

    Forum Fan

    178 Posts

  • #11, 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