Global script to change cursor and fade effect

  • #1, by PaupasiaThursday, 21. May, 17:09 2 months ago
    Hi everyone, 
    time passes quickly, too much. During this time I focused on graphics and now I can get back to development. I've seen that there have been great improvements for Visionaire and this is great.
    Now I'm a little lost with the new features but I find them very interesting. Thank you @Simon for all this amazing work!
    Before writing I searched in the forum and in the documentation but I'm a noob with Lua and I don't understand how to use it. 

    My problem is the usual old problem. Simulate a 360 view.
    I have an old script, thanks a lot @AFRLme, that places the cursor in the center. Years ago it didn't work but now it works. I don't know why, but it's fine!
    So ... question is ..
    I have this action part on mouse over 

    all of my object scenes are called LEFT, LEFT1, RIGHT,RIGHT1

    and I have this script, never worked and now I don't need the "left click" action


    How can I modify this script to get the "objectname" in the scene (LEFT,LEFT1, RIGHT,TIGHT1) to automatically change the fade effect and check if the condition "slowPC" is true or false when the mouse over the scene object?
    I think now is possible, but how?

    Thanks

    Forum Fan

    165 Posts


  • #2, by afrlmeFriday, 22. May, 15:05 2 months ago
    local obj = game.CurrentObject:getName()

    if Conditions["slowPC"].Value then
    if obj == "LEFT" then
    game.FadeEffect = eFadeIn
    elseif obj == "LEFT1" then
    ...
    elseif obj == "RIGHT" then
    ...
    elseif obj == "RIGHT1" then
    ...
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13


    Effect for fade in/out of a scene.



    '0' (eFadeNo): no effect. display new scene immediately.

    '1' (eFadeIn): fade in. Only fade in new scene. No fade out of current scene.

    '2' (eFadeOut): fade out. Only fade out current scene. No fade in of new scene.

    '3' (eFadeInAndOut): fade in/out. Fade out current scene and fade in new scene.

    '4' (eFadeToNew): fade to new. Use alpha-blending to directly fade from current to new scene.

    '5' (eShiftLeft): shift left. Shift current scene to the left and show new scene.

    '6' (eShiftRight): shift right. Shift current scene to the right and show new scene.

    '7' (eTunnelEffect): tunnel effect. Use a tunnel effect for fade in/out.



    Imperator

    6816 Posts

  • #3, by PaupasiaFriday, 22. May, 15:20 2 months ago
    Thank you so much Lee! You saved me a lot of work 

    Forum Fan

    165 Posts

  • #4, by PaupasiaFriday, 22. May, 16:16 2 months ago
    Well ... this is funny,
    now all the object text inside my main menus have disappeared. Maybe I need a string to exclude interfaces and main menu like 

    if not game.CurrentScene:isEmpty() and not game.CurrentScene.SceneIsMenu then

    But it gives me sintax error if I put this string inside the script.


    Funny thing the eShiftRight command instead of turning to the right turns to the left. 

    In the editor it works but in the script it does the opposite. 

    But wtihout delay, I have to insert the delay time inside the script. 

    Forum Fan

    165 Posts

  • #5, by PaupasiaFriday, 22. May, 16:21 2 months ago
    Damn! Forget about the main menu!

    I had a system crash and it deleted the ttf font ...

    Forum Fan

    165 Posts

  • #6, by afrlmeFriday, 22. May, 16:37 2 months ago
    Hmm it shouldn't cause any issues with anything. maybe it's to do with which fade effect is specified? some of them might not be working correctly?

    It might be a good idea to convert the script into a function so that you only have to use execute a script & call the function in that on cursor enters object area. Or were you wanting to have it running all of the time in a loop?

    You didn't really specify in detail what you were hoping to achieve. Also I forgot to mention how to set cursors with Lua script.

    system.cursor = Cursors["example"]
    1

    Imperator

    6816 Posts

  • #7, by PaupasiaFriday, 22. May, 17:23 2 months ago
    Well the opposite direction is not a problem, I will put them reversed. 

    My goal is to add this effect to all the scenes in the game. I already have about 600 compiled scenes and inserting the actions one by one is a planned suicide.

    With this script I can edit all the scenes in one go and copy only the destination I have in the left click action in the mouse over actions

    But I'm stuck with the delay, all the instructions I've found in the wiki talk about "scenes" and "setdelay" or :to function are called in a different way. 

    Really I 'don't know how to put the delay inside this script

    Edit: the set cursor idea is really good!

    Edit Edit: I want to have it running all the time. Because in all the scenes I have LEFT, RIGHT, GO. To move the NPC character

    Forum Fan

    165 Posts

  • #8, by PaupasiaFriday, 22. May, 17:55 2 months ago
    I deleted the autosave and tried again. 
    Unfortunately it does not read the name of the object scene.  

    The effect is applied to any link, for example GO, NEW GAME, etc. 

    I'm not lucky with my ideas eheh

    Forum Fan

    165 Posts

  • #9, by afrlmeSaturday, 23. May, 03:57 2 months ago
    What's the delay for?

    If you want it to be always running, then  a mouse event listener or mainLoop would ideal.

    Could you please breakdown exactly how it's all supposed to work?

    Anyway, here's something that might do the trick...

    --[[

    Available effects for fading in/out of a scene.

    '0' (eFadeNo): no effect. display new scene immediately.
    '1' (eFadeIn): fade in. Only fade in new scene. No fade out of current scene.
    '2' (eFadeOut): fade out. Only fade out current scene. No fade in of new scene.
    '3' (eFadeInAndOut): fade in/out. Fade out current scene and fade in new scene.
    '4' (eFadeToNew): fade to new. Use alpha-blending to directly fade from current to new scene.
    '5' (eShiftLeft): shift left. Shift current scene to the left and show new scene.
    '6' (eShiftRight): shift right. Shift current scene to the right and show new scene.
    '7' (eTunnelEffect): tunnel effect. Use a tunnel effect for fade in/out.

    ]]

    local t_fade = {

    ["left"] = { effect = eFadeIn, delay = 100, cursor = "arrow_left" },
    ["left1"] = { effect = eShiftLeft, delay = 500, cursor = "arrow_left" },
    etc...

    }


    local current_obj = nil

    function onMouseEvent(eventType, mousePosition)

    if eventType == eEvtMouseMove and not game.CurrentScene.IsMenu then

    if not game.CurrentObject:isEmpty() then -- check if current object exists

    if string.lower(game.CurrentObject:getName()) ~= current_obj then
    current_obj = string.lower(game.CurrentObject:getName()) -- store name of current object in lowercase
    -- + --
    if t_fade[current_obj] ~= nil then
    game.FadeEffect = t_fade[current_obj].effect -- update fade effect
    game.FadeDelay = t_fade[current_obj].delay -- update fade delay
    system.cursor = Cursors[ t_fade[current_obj].cursor ] -- set a new cursor
    end
    end

    elseif game.CurrentObject:isEmpty() and current_obj ~= nil then

    current_obj = nil -- reset current_obj back to nil
    game.FadeEffect = eFadeInAndOut -- specify default fade effect
    game.FadeDelay = 600 -- specify default fade delay
    system.cursor = Cursors["default"] -- specify the default cursor

    end

    end

    end

    registerEventHandler("mouseEvent", "onMouseEvent")
    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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56


    Cursor names are case sensitive. Use lowercase for the object names in the table section because the script is automatically converting object names to lowercase. Anyway with the table you should be able to easily specify fade effects, fade delay, & which cursor to use whenever you mouse over something.

    Imperator

    6816 Posts

  • #10, by PaupasiaSaturday, 23. May, 23:06 2 months ago
    It should simply be an automated scene change without the need to click left or right to change a scene.  Like a "fake" 360 view.

    The delay is necessary for scrolling the scene, without delay the scene would change immediately without scrolling the background, loosing the fake 360 view.

    I tried the script but I think there's a problem with the object names, mine are uppercase ("LEFT" instead of "left").
    I changed "lower" with "upper" in the script (changed also the cursor names)  but it doesn't work. 
    I definitely have to look at it calmly.

    Thank you so much Lee for helping me, sooner or later I'm going to make it work! 

    After all, it only took me 2 years for the other one to make it work. grin

    Forum Fan

    165 Posts

  • #11, by afrlmeSunday, 24. May, 04:25 2 months ago
    The lowercase was done on purpose, so that regardless of what the case the objects used, lower, UPPER, or MiXeD, it would still work because I was converting the name of the current object to lowercase with string.lower() function.

    For the scene change what you could do is create a value inside of the objects on each scene & inside of the string store the name of the scene you want to change to. Make sure that the value is named the same for each of the objects, then you can query the name of that value & change to that scene on mouse over.

    What wasn't working with the script? Did you check the log? Do you have log level set to "info"?

    Quick note: remove the "etc..." line from the table part of the script. also each table entry you create needs to have a comma , after it to separate them - except for the final entry.

    Imperator

    6816 Posts

Write post