[LUA] match pattern issue (aka wait for action to be finished)

  • #1, by sebastianSaturday, 17. September 2016, 18:03 8 years ago
    Hey there again,

    the title says it all... Is this possible? I want to wait for a dynamically called action inside a lua function. So I don't know its length.

    kind regards
    Sebastian

    Thread Captain

    2346 Posts


  • #2, by afrlmeSaturday, 17. September 2016, 21:29 8 years ago
    Creating pauses between lines of code with Lua script is not very easy at all. It requires creating a loop & then setting an initial time & then checking if x time has passed. I guess you could probably also check if an action is inside of the ActiveActions table, but I do not recommend using the Lua repeat or while loop operators as they tend to cause the Visionaire Studio player to crash.

    There's the other problem of Lua reading line by line, so you would need to create an else action part per pause query to include a "return true" or "return false" statement to kill the rest of the actions / lines of code inside of the function.

    Imperator

    7278 Posts

  • #3, by sebastianSaturday, 17. September 2016, 22:12 8 years ago
    basucally i would set a condition to false and check inside a loop if its true. at the end of the action it gets set to true and the loop ends..

    but im not sure if this is the best method...

    I saw in the data structure site that each action contains links to action parts.
    Isnt it possible to check if the chrrent started action is at the last actionpart and then breakout of the loop?

    Thread Captain

    2346 Posts

  • #4, by SimonSSaturday, 17. September 2016, 23:02 8 years ago
    The engine doesn't run any code multithreaded. Every lua script is run synchronously. You can wait all you want the action won't executed. You must leave the lua script.
    Only way is per mainloop handler and checking activeactions or calling something at the end of the action.

    Thread Captain

    1580 Posts

  • #5, by afrlmeSaturday, 17. September 2016, 23:15 8 years ago
    Quick question: why are you wanting to do this with Lua script? It's much easier to handle these sort of things with called by other actions. You could use a combination of both Lua & action blocks.

    Imperator

    7278 Posts

  • #6, by sebastianSaturday, 17. September 2016, 23:20 8 years ago
    so i cant use a ... while(?) loop like

    startAction(Actions["some action name"])
    while Conditions["action_ended"].ConditionValue == false do
          if Conditions["action_ended"].ConditionValue then
                break
          end
    end
    ...some more code which gets execuded when action_ended is TRUE
    



    and inside of the action i started before i set the condition to true at the end...

    @AFRLme: im just doing some theoretical stuff regarding a dialog system which starts a linked action from a lua function and should continue when the called action ended...
    Of course i can do some script stuff at the end of the action anyway, but i would like to do this in the main started function because it would be more easy to manage later

    Thread Captain

    2346 Posts

  • #7, by afrlmeSaturday, 17. September 2016, 23:28 8 years ago
    I really don't recommend using while or repeat x until loop operators. You can try them if you like, but almost every time I've tried using them in a script it ends up crashing the VS player, so I recommend using mainLoop event handlers or called by other action blocks that are looped using the jump to x action parts.

    Good call on reminding me of "break" - not needed to use them in anything in an age & a half! wink

    Imperator

    7278 Posts

  • #8, by sebastianSaturday, 17. September 2016, 23:34 8 years ago
    Can I pm you some of my thoughts about a dialog system and a rough concept about the functions?
    Maybe you have some ideas about improving this...^^

    Thread Captain

    2346 Posts

  • #9, by afrlmeSaturday, 17. September 2016, 23:59 8 years ago
    Me or Simon? If you are wanting editor based improvements then Simon would be the one to contact. If you are talking about a custom dialog system made out of Lua & action parts, then sure pm away (except you won't be able to send me a message as my profile seems to one of many that no longer seems to exist on this forum).

    afrlme (at) outlook (dot) com.

    Imperator

    7278 Posts

  • #10, by sebastianSunday, 18. September 2016, 12:45 8 years ago
    Yes, i meant you, AFRLme ^^ (but if simon likes to throw some thoughts into my idea, too, i would not reject that razz)

    Basically i may have also a solution for my idea with the loop (which isn't needed anymore then)

    I have to write down my concept first, so that its understandable four you ^^
    I'll pm/mail you asap =)

    Thread Captain

    2346 Posts

  • #11, by afrlmeSunday, 18. September 2016, 12:58 8 years ago
    This is where the @ symbol comes into play! wink

    & ok dokie.

    Imperator

    7278 Posts