[SOLVED] set cursor in lua is not possible?

  • #1, by PanSMonday, 14. January 2019, 15:47 5 years ago
    its there no way to set the cursor in a lua script?

    i am working on a script set the cursor depending on the direction of an object. so i want to have an arrow showing north if mouse is over an exit area leading north for example. checking the direction isn a problem, but setting a cursor in the same script is apparently not possible right (even according to the wiki)?

    Newbie

    73 Posts


  • #2, by afrlmeMonday, 14. January 2019, 16:27 5 years ago
    Aye, you can set the cursor via Lua script. Has been possible for quite a while now...
    game.Cursor = Cursors["example"]

    Imperator

    7278 Posts

  • #3, by PanSMonday, 14. January 2019, 17:02 5 years ago
    That was what I tried but it didn't work. Nothing happens. No Error Log or something. Doesnt matter with or without the quotation marks.

    Thats the function to test setting cursor. It will be executed when mouse is over the object (scene change):
    function setExitCursor()
      if game.CurrentObject then
        --print(game.CurrentObject.Direction)
        
        game.Cursor = Cursors["cur_exit_n"]
      end
    end
    

    Newbie

    73 Posts

  • #4, by afrlmeMonday, 14. January 2019, 18:29 5 years ago
    Sorry, my bad. It's actually system.cursor, not game.Cursor.

    system.cursor = Cursors["example"]

    Imperator

    7278 Posts

  • #5, by PanSMonday, 14. January 2019, 19:35 5 years ago
    If I'm not doing anything wrong it will not work. :-/

    Newbie

    73 Posts

  • #6, by afrlmeMonday, 14. January 2019, 19:37 5 years ago
    are you actually calling the function? can you share some screenshots of how you have set it up please?

    Imperator

    7278 Posts

  • #7, by PanSMonday, 14. January 2019, 19:54 5 years ago
    The function is called by a mouse over

    Newbie

    73 Posts

  • #8, by PanSMonday, 14. January 2019, 20:11 5 years ago
    wtf. now it works. maybe there was a typo in the lines I havent seen till I rewrote the small script.

    Edit: maybe I wrote system.Cursor instead of system.cursor

    Thx Guys! grin

    Edit2: Thats my working script now:
    local t_arrowdirection = {"cur_exit_e","cur_exit_ne","cur_exit_n","cur_exit_nw","cur_exit_w","cur_exit_sw","cur_exit_s","cur_exit_ne"}
    
    function setExitCursor()
      if game.CurrentObject then  --maybe a check for string "exit_to_"
        --print(game.CurrentObject.Direction) 
        local curDir = math.floor((game.CurrentObject.Direction / 45) + 1 )
        system.cursor = Cursors[t_arrowdirection[curDir]]
      end
    end

    Newbie

    73 Posts

  • #9, by afrlmeTuesday, 15. January 2019, 01:36 5 years ago
    Very good. I would probably use some string.find or string.match thing myself, maybe with a table to iterate through. I would also use the Lua mouse event handler, so I didn't have to create mouse enter/leaves action parts for each exit - though I suppose there's probably not that much work involved in creating some mouse enters/leaves action blocks for a few exits.

    I made the same mistake with system.Cursor too. I replaced game with system, but forgot to lowercase the capital C of cursor. Easy mistake considering almost everything in the data structure uses the camelCase naming convention.

    Imperator

    7278 Posts