Global script for "mouse enters/leaves area"

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

    Imperator

    6815 Posts


  • #11, by LebosteinTuesday, 17. February 2015, 14:27 5 years ago
    I have some problems with that complex syntax. What is the easiest way to get a specific numeric (or the string) value of the current object? Somithing like that:
    exitmode = game.CurrentObject:getValue("exit")
    1
    2

    Key Killer

    598 Posts

  • #12, by afrlmeTuesday, 17. February 2015, 14:53 5 years ago
    no, you mean using the string.find thing? I would write a fall function which you can reuse as many times as you like...

    the function (definition)
    function strMatch(str)
    if string.find(game.CurrentObject:getName(), str) then
    return true
    end
    end
    1
    2
    3
    4
    5
    6

    to use, create an execute a script action part containing something like...
    if strMatch("exit") then
    -- do something if exit is returned
    break
    elseif strMatch("obj") then
    -- do something if obj is returned
    break
    elseif ...
    -- etc...
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10


    The function I wrote returns the name of the current object the mouse cursor is over & if it finds what you wrote in the function then it will return true, else it will carry on running through the script. You could also consider adding break before each elseif to cancel the rest of the script if it has found a match.

    Imperator

    6815 Posts

  • #13, by LebosteinTuesday, 17. February 2015, 15:36 5 years ago
    Thanks. But I mean to check, if an object has a value, for example with the name "exit"

    Key Killer

    598 Posts

  • #14, by afrlmeTuesday, 17. February 2015, 15:42 5 years ago
    you will need to iterate through its values then with a for loop.

    Imperator

    6815 Posts

  • #15, by LebosteinTuesday, 17. February 2015, 18:33 5 years ago
    There are functions like action parts?
    For example: ChangeCursor(cursorname)

    Key Killer

    598 Posts

  • #16, by afrlmeTuesday, 17. February 2015, 19:05 5 years ago
    There's no table in the data structure for defining the currently active cursor. I will make a note of it in the dev tracker & see if Simon, or David or whoever will be willing to add it.

    All of the Lua functions that are available are listed on the player commands page & the scripting page. Everything else are scripts / functions that myself or others have written. Most things can be accessed & manipulated via the data structure, but not everything is listed in the data structure, like the currently active cursor for example, which is why I ended up having to use called by other actions for setting the cursors instead of pure Lua script.

    Imperator

    6815 Posts

  • #17, by LebosteinTuesday, 17. February 2015, 20:17 5 years ago
    Oh, that is hard to hear. I though I can do the same things with lua as the clicking based action part construction kit inside Visionaire... But for some things I am forced to use lua, for other things I am forced to use the action part editor. That means I have to combine these two methods in most cases confuse

    Key Killer

    598 Posts

  • #18, by afrlmeTuesday, 17. February 2015, 20:31 5 years ago
    Yeah it's how it is I'm afraid. I would just use Lua script (or whatever code) for everything if it was possible, but it's not, so I compromise & use action parts when I have to.

    On the other hand, some things are far faster & simpler with the action parts than they are with scripting, so it's just a case of figuring out the best approach to each event / problem.

    Imperator

    6815 Posts

  • #19, by LebosteinWednesday, 18. February 2015, 10:45 5 years ago
    That is my final script to set the cursor automatically to exit symbols, if you touch scene exit objects:
    function autoCursor()
    exitcode = getObject("Game.GameCurrentCharacter.CharacterValues[exitcode]")
    if game.CurrentObject:getId().tableId == eObjects then
    objectname = game.CurrentObject:getName()
    if not string.find(objectname, "exit") and exitcode.Int ~= 0 then
    startAction("Game.GameCurrentCharacter.CharacterActions[cursor_normal]")
    exitcode.Int = 0
    elseif string.find(objectname, "exit_l") and exitcode.Int ~= 1 then
    startAction("Game.GameCurrentCharacter.CharacterActions[cursor_exit_left]")
    exitcode.Int = 1
    elseif string.find(objectname, "exit_r") and exitcode.Int ~= 2 then
    startAction("Game.GameCurrentCharacter.CharacterActions[cursor_exit_right]")
    exitcode.Int = 2
    elseif string.find(objectname, "exit_u") and exitcode.Int ~= 3 then
    startAction("Game.GameCurrentCharacter.CharacterActions[cursor_exit_up]")
    exitcode.Int = 3
    elseif string.find(objectname, "exit_d") and exitcode.Int ~= 4 then
    startAction("Game.GameCurrentCharacter.CharacterActions[cursor_exit_down]")
    exitcode.Int = 4
    end
    elseif exitcode.Int ~= 0 then
    startAction("Game.GameCurrentCharacter.CharacterActions[cursor_normal]")
    exitcode.Int = 0
    end
    end

    registerEventHandler("mouseEvent", "autoCursor")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28

    I have defined a value "exitcode" that brings two benefits:
    1. The value "exitcode" ensures that the action parts to change the cursor are only called if it is needed (otherwise the action parts are called permanently - that could be a performance problem, I don't know)
    2. My coin interface can only be opened if the value "exitcode" = 0. So the coin interface can not be opened if an exit object is under the cursor.

    Key Killer

    598 Posts

  • #20, by afrlmeWednesday, 18. February 2015, 13:28 5 years ago
    The script works? It could probably have been a lot more compact / global than you have written it, but if it works, then it works. wink

    Imperator

    6815 Posts

Write post