Global script for "mouse enters/leaves area"

  • #1, by LebosteinTuesday, 17. February 2015, 11:15 10 years ago
    Is it possible to define a global script that would be called, if the mouse enters any action area (button, object, character)? There are some additional/optional global scripts for pressing and releasing mouse buttons only.

    I search a solution to change the mouse cursor automatically, if I focus an exit object. All my exit objects in scenes contains the phrase "exit" in the object name, for example "exit_to_left" or "exit_to_street". I would check that the entered object under the mouse cursor is a scene object and that the object name contains "exit" before I modify the cursor image. At the moment I know the solution to add these scripts to every exit object manually. But this is not the sense of scripting I think.

    Key Killer

    621 Posts


  • #2, by SimonSTuesday, 17. February 2015, 11:24 10 years ago
    You can use lua. Just wrote this down without testing, so maybe some errors inside. If the current object changes an action gets called.
    cur_obj = emptyObject
    function currentobjChange()
      if cur_obj.getId().id ~= game.CurrentObject.getId().id or 
         cur_obj.getId().tableId ~= game.CurrentObject.getId().tableId then
         cur_obj = game.CurrentObject
         startAction("ObjectHasChanged")
      end
    end
    registerEventHandler("mainLoop", "currentobjChange")
    

    Thread Captain

    1581 Posts

  • #3, by LebosteinTuesday, 17. February 2015, 12:19 10 years ago
    Could this work? Or is this not a good idea to do this inside the main loop?
    function currentobjChange()
      if game.CurrentObject:getId().tableId == eObjects and string.sub(game.CurrentObject:getName(), 1, 4) == "exit" then
        startAction("Characters[main].CharacterActions[cursorToExit]")
      elseif game.CurrentObject:getId().tableId == eCharacters then
        startAction("Characters[main].CharacterActions[cursorToMouth]")
      else
        startAction("Characters[main].CharacterActions[cursorToNormal]")
      end
    end
    
    registerEventHandler("mainLoop", "currentobjChange")
    

    PS: How I change the cursor with lua?

    Key Killer

    621 Posts

  • #4, by afrlmeTuesday, 17. February 2015, 12:44 10 years ago
    Interesting. You are wanting it to automatically change the cursor on mouse over based on a prefix setting. That's a nice idea.

    Quick note: You should include another query to check if you are currently holding an item, otherwise it will change the cursor, but you will still be holding said item, which might confuse the player as they will probably think the item has been dropped but will find out otherwise when they try to click on something.

    Here's the function I use for setting cursors in the current project I'm working on...
    function setCursor(n)
     if game.UsedItem:isEmpty() then
      startAction("Actions[set_cursor_" .. n .. "]")
     end
    end
    

    to set a cursor I create an execute an action part inside of each objects on mouse enter action containing something like...
    setCursor("use")
    

    ...if item is not held then it will trigger a called by other action I created called "set_cursor_use", which contains a set cursor action part. I use the same method for resetting the cursor via the on mouse leave action with...
    setCursor("default")
    


    You method does sound more interesting to me though. I would recommend adding it to the mouseEvent handler function instead of mainLoop handler as it should only need to be checked on mouse cursor move instead of each system loop.

    Imperator

    7278 Posts

  • #5, by LebosteinTuesday, 17. February 2015, 13:05 10 years ago
    The disadvantage of the Visionaire data structure is, there is no place for self defined object parameters. The only way to add self defined preferences to objects is the name of the object. I want to use the object name to store other preferences like dynamic action names. An object name that ends with with changes the action name to "use" automatically (and [p] for "pick up" and so on):
    obj_lever_
    obj_stone_[p]
    exit_to_street
    ...

    Key Killer

    621 Posts

  • #6, by afrlmeTuesday, 17. February 2015, 13:16 10 years ago
    I wrote a script for dynamic action names ages ago, which be found here. Maybe you can use that or adapt it to suit your needs.

    P.S: you can use Lua to check if something exists inside of a string, check out the recommended example on this stack overflow page I found via google.

    Imperator

    7278 Posts

  • #7, by AlexTuesday, 17. February 2015, 13:40 10 years ago
    The disadvantage of the Visionaire data structure is, there is no place for self defined object parameters.

    you can create object values where you store your object parameters.

    Great Poster

    378 Posts

  • #8, by LebosteinTuesday, 17. February 2015, 13:55 10 years ago
    This could work also. Is it possible to check if an object has the value "exit" for example? An object with the value "exit" could mark an exit object (exit = 1 means exit to the left and exit = 2 means exit to the right)....

    Key Killer

    621 Posts

  • #9, by afrlmeTuesday, 17. February 2015, 14:02 10 years ago
    Sure I don't see why not. I don't recommend writing it that way though. Use an underscore instead, like so: exit_1, exit_2, or maybe use compass directions instead: exit_w, exit_nw, exit_n, etc.

    Imperator

    7278 Posts

  • #10, by LebosteinTuesday, 17. February 2015, 14:07 10 years ago
    I don't recommend writing it that way though.

    I mean the numeric value ( wink ) of the value with the name "exit" is set to 1 for left, 2 for right and so on. If the value with the name "exit" not exist, there is no exit at this object

    Key Killer

    621 Posts

  • #11, by afrlmeTuesday, 17. February 2015, 14:20 10 years ago
    ah ok, sorry. I misunderstood what you was asking. grin

    Imperator

    7278 Posts