Set pause [Lua]

  • #1, by ke4Saturday, 17. January 2015, 19:31 6 years ago
    Hi,

    please how can i set pause in Lua? ( the same like in the miscellaneous actions )
    Thanks.

    Key Killer

    810 Posts


  • #2, by afrlmeSaturday, 17. January 2015, 20:21 6 years ago
    Do you to trigger the action part pause or to pause between the execution of lines of code in Lua?

    The first is not possible because pause action needs to be directly linked to a block of actions. It is not a global pause. The latter is only possible, to an extent, if you write your own pause function in combination with a loop.

    Please see here, for my loop handler script. There's is only an example script available as I've not gotten round to writing up the documentation of how to use it, yet. Sorry.

    P.S: the function is pretty complicated, which is why I included it under the advanced script section.

    Imperator

    6846 Posts

  • #3, by ke4Monday, 19. January 2015, 13:58 6 years ago
    I solved it via execution scripts into visionaire if queries as you suggested.

    I would have one more question, is there way how to make an if condiction with value like this?
    i have value and i need to execute an action if the value is equal between 1 and 10 ( from 1 to 10 )
    another action for 10 - 20 and so on.
    Or i have to set if condition for every number separately?

    Key Killer

    810 Posts

  • #4, by afrlmeMonday, 19. January 2015, 14:20 6 years ago
    it's much easier to do those sort of if queries in Lua than it is in the editor. In the editor you need to create 2 if queries which both require an end if action part to close them...

    if x more than equal 1
    if x less than equal 10
    action parts
    end if
    end if

    ...to me that is messy, because I don't like the tree structure of if queries in the editor as they can get really long & messy & there is no way of adding and / or operators into the queries.

    In Lua I can do...
    if Values["value_name"].Int >= 1 and Values["value_name"].Int <= 10 then
    -- add code or call an action with startAction() function here
    elseif Values["value_name"].Int >= 11 and Values["value_name"].Int <= 20 then
    -- more actions
    -- etc...
    end
    1
    2
    3
    4
    5
    6
    7

    Imperator

    6846 Posts

  • #5, by ke4Monday, 19. January 2015, 14:26 6 years ago
    The thing is that i need this for 300 per 10 - that's 30 if queries and that would be super messy.
    I was hoping that maybe there is some operator for this.

    the best way in this case will be Lua,
    thank you.

    Key Killer

    810 Posts

  • #6, by afrlmeMonday, 19. January 2015, 14:52 6 years ago
    Hmm you might actually be able to iterate with a for loop, instead of writing out each query I mean. I don't know if it would actually work mind as I've not tried sorting that out before.


    What exactly are you trying to do?

    Imperator

    6846 Posts

  • #7, by ke4Monday, 19. January 2015, 15:08 6 years ago
    I believe it won't be so annoying to write them all out through Lua.

    I have the Balance game - The full animation of the box with pointer has 300 frames where frame 1 and 300 are the edges.
    The whole thing is a loop.

    execute script (First/Last frame of animation through variable value)
    add + 1 to the variable value
    pause for[value]

    and i want to make this: The closer the pointer is to the edge - the faster the pointer is
    - basicaly just setting shorter pause value for the main loop.

    i'm first checking if the current value of the First/Last frame variable is less or more than 150 ( middle )
    - according to this i'm adding + 1 OR - 1 to this variable

    this would be just another check and setting the pause value.

    Key Killer

    810 Posts

  • #8, by afrlmeMonday, 19. January 2015, 16:02 6 years ago
    Sounds like more work than just simply updating the position of a single frame.

    If you use a single frame. You only need to define the min & max value then you will only need a few if queries. If you create a value & link it to a pause value then you can also control the speed of the pause value by editing the values number.

    So with this in mind... say, at a range of 100 to 150 & 150 to 200 you want it to update via the normal speed & then increase the speed as you go past those numbers. It's easy enough by defining ranges with a combination of and / or queries.

    1. I would first have an action to initialize the position & value on scene/puzzle/mini-game start. So for this you could do a set random value with min = 140, max = 160. This will push the starting position over to one side thus allowing you to easily determine if it should be incrementing or decrementing.

    2. After setting up the initial value, you would follow this through by using the ActiveAnimations["anim_name"].Position = {x = x, y = y} value determined by the value of value mentioned above for setting up the position instantly.

    3. You then create some new actions for controlling the increment with some if queries & a jump to x action part to create a loop. The value ranges defined in the if queries will determine the speed that you set in another value (as I mentioned further up this post) which will control the speed of the increment or decrement.

    4. The keyboard controls will work however you decide to implement them with the default looping key action or with the key (released) action.

    I guess I've been a bit vague here, but you did say you wanted to learn/figure out how to sort it out more or less yourself. smile

    Imperator

    6846 Posts

  • #9, by ke4Monday, 19. January 2015, 17:36 6 years ago
    Ok so this is i guess the simplest way, don't know how to make the speed update system more simpler.
    4 action
    Until left or right key is hold then LEFT or RIGHT is true


    1action
    start_balance_miniGame

    local RandomFrame = math.random(140,160)
    Values["balance_pause"].int = 20
    Values["balance_frame"].int = RandomFrame
    local frame = getObject("Values[balance_frame]"):getInt(VValueInt)
    startAnimation("Animations[anim_name]")
    ActiveAnimations[anim_name].Position = {x = frame, y = frame};
    startAction("Actions[Balance_loop]")

    ---------------------------------------------------------------------------------------------------

    2action
    Balance_loop

    1. execute script
    local frame = getObject("Values[balance_frame]"):getInt(VValueInt)
    ActiveAnimations[anim_name].Position = {x = frame, y = frame};

    2. call script "Balance_update"
    3. Pause for balance_pause Value
    4. Jump to action part #1

    -----------------------------------------------------------------------------------------------------
    3action ( I missed the ENDS )
    Balance_update
    local frame = getObject("Values[balance_frame]"):getInt(VValueInt)


    if frame = 300 THEN
    startAction("Actions[Game_over]")

    else

    if LEFT OR RIGHT THEN

    if LEFT
    Values["balance_frame"].int = Values["balance_frame"].int - 1
    else
    Values["balance_frame"].int = Values["balance_frame"].int + 1


    else

    if frame >= 150 THEN
    Values["balance_frame"].int = Values["balance_frame"].int + 1
    else
    Values["balance_frame"].int = Values["balance_frame"].int - 1

    Call script balance_update_pause


    -----------------------------------------------------------------------------------------------------
    4action
    balance_update_pause
    local frame = getObject("Values[balance_frame]"):getInt(VValueInt)


    if frame >= 1 AND frame <= 10 THEN
    --- value PAUSE set 10ms

    elseif frame >= 11 AND frame <= 20 THEN
    --- value PAUSE set 11ms

    elseif frame >= 21 AND frame <= 30 THEN
    --- value PAUSE set 12ms

    elseif frame >= 31 AND frame <= 40 THEN
    --- value PAUSE set 13ms


    ......

    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75

    Key Killer

    810 Posts

  • #10, by afrlmeMonday, 19. January 2015, 19:46 6 years ago
    Please note that: Lua operators & functions are case sensitive. Most of them are in lower case, such as: and, or, else, end, if etc.

    For a successful query you need 2 equal signs == or one of the other operators. A single = is the method used to write/set a variable.

    Also you do not need to create variables for everything. For example: why do...
    local RandomFrame = math.random(140,160)
    Values["balance_frame"].int = RandomFrame
    1
    2
    3

    when you can simply do...
    Values["balance_frame"].int = math.random(140, 160)
    1
    2


    Your script to me is overly-complicated. Technically you could do this with a single animation & no scripting at all. There's actually a set animation position action part already so all you would need to do is query current position then increment/decrement the value & offset the animation by 1 or -1 & then afterwards you add another if query to see if value equals the min or max value & if it does then game over else if value equals whatever then do something else.

    I would make the ranges for setting the pause/speed a lot larger instead of every 10 frames/pixels. It will decrease the amount of if queries by a lot, even if you increased to a range of 20, but I would recommend doing ranges of 50 instead except maybe towards to min or max values.

    Imperator

    6846 Posts

Write post