Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Global script for "mouse enters/leaves area"

  • #1, by Lebostein 11 years ago Zitieren
    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.
  • #2, by SimonS 11 years ago Zitieren
    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")
    
  • #3, by Lebostein 11 years ago Zitieren
    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?
  • #4, by afrlme 11 years ago Zitieren
    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.
  • #5, by Lebostein 11 years ago Zitieren
    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
    ...
  • #6, by afrlme 11 years ago Zitieren
    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.
  • #7, by Alex 11 years ago Zitieren
    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.
  • #8, by Lebostein 11 years ago Zitieren
    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)....
  • #9, by afrlme 11 years ago Zitieren
    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.
  • #10, by Lebostein 11 years ago Zitieren
    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
  • #11, by afrlme 11 years ago Zitieren
    ah ok, sorry. I misunderstood what you was asking. grin