How can I disable functions of a definition script in MenuScenes? [SOLVED via Discord]

  • #1, by retinaMonday, 14. September 2020, 16:22 3 years ago
    SOLUTION:
    It must be "If not game.CurrentScene.IsMenu" added to function b). The Code below is already adapted.

    PROBLEM:
    I want to disable functions of a definition script in MenuScenes. How can I do that?
    I already tried to include an "If not Scenes.IsMenu…" and "If Scenes.IsMenu == false…" to the functions. But then the script would not work in normal Scenes either. Since I am not a programmer, maybe I didn't code it correctly. So I ask for your help.

    Alternative Question: How can I end an execution scripts later on in the game e.g. in a MenuScene?
    As I use MenuScenes at the beginning of the game, I also tried to call the script as an execution script in the first Scene. But I don't know how to end/stop this execution script when I have a MenuScene later in the game.

    Details about the script:

    I use a definition Script with EventHandlers for "textStarted" and "textStopped" which includes following functions:
    function a) for displaying speechbubbles when characters are speaking
    and
    function b) for hiding the cursor & allowing to skip text while text is displayed (this includes object text, narration text and character text).

    In regular Scenes this script works fine and is exactly what I want.
    But I don't want this script, especially function b) to be enabled in MenuScenes with displayed object or narration text.

    Happy for any help!

    Here comes the script without the "If not Scenes.IsMenu…"-Experiment.
    -- * event handlers * --
    registerEventHandler("textStarted", "onTextStarted")
    registerEventHandler("textStopped", "onTextStopped")
    
    -- * lokal: handle cutscene * --
    local handle_cutscene_txt = false
    
    
    -- * function for text started * --
    function onTextStarted(text)
      -- * function part for speechbubbles * --
      local currentCharacter = game.CurrentCharacter
      local owner = text:getLink(VTextOwner)
      if owner:getId().tableId == eCharacters then
        local isLeft = owner:getName() == currentCharacter:getName()
        showTextBalloon(isLeft)
      end
      -- * function part for Hide Cursor while Display Text * --
      if not game.CurrentScene.IsMenu and
        not not game.HideCursor and
        game.CutsceneAction:isEmpty() and
        not handle_cutscene_txt then
          game.HideCursor = true
          handle_cutscene_txt = true
      end
      -- + --   
      setDelay(250, function()
            game.AlwaysAllowSkipText = true
      end)
    end
    
    -- * function for text finished * --
    function onTextStopped(text)
      -- * function part for speechbubbles * --
      local currentCharacter = game.CurrentCharacter
      local owner = text:getLink(VTextOwner)
      if owner:getId().tableId == eCharacters then
        local isLeft = owner:getName() == currentCharacter:getName()
        hideTextBalloon(isLeft)
      end
      -- * function part for Hide Cursor while Display Text * --
      if handle_cutscene_txt then
          game.HideCursor = false
          handle_cutscene_txt = false
      end
      -- + --
      game.AlwaysAllowSkipText = false
    end
    
    
    
    function getBaloon(isLeft)
      if isLeft then
    -- when Hero(currentCharacter) talks --- show no speechbubble ------
        return getObject("")
      end
    --- when other characters talk ---- show speechbubble ---LuaPath --Interfaces.Sprechblase---
      return getObject("Interfaces[Sprechblase]") 
    end
    
    
    function showTextBalloon(isLeft)
      local baloon = getBaloon(isLeft)
      baloon.InterfaceVisible = true
      baloon.InterfaceVisibility = 100
    end
    
    function hideTextBalloon(isLeft)
      local baloon = getBaloon(isLeft)
      baloon.InterfaceVisible = false
      baloon.InterfaceVisibility = 0
    end
    
    --[[https://www.visionaire-studio.net/forum/thread/dialog-interface-mit-abbild-der-personen-add-character-images-to-dialogs/#49215]]--
    --https://www.visionaire-studio.net/forum/thread/skip-protection-of-displayed-text/#52563--
    

    Newbie

    4 Posts