lua forward/backward selection

Discussion in 'Get Help/Troubleshooting' started by daspex, Jun 13, 2018.

  1. Hi,
    I wonder how to code a forward/backward selection in lua.I tried to realise it via counter with
    -1 and +1 but even if the code should make the counter count -1 it seems to be that it also counts
    +1.What is wrong with my code?Maybe it's latency time depended?
     

    Attached Files:

  2. I move incrementing to the function and I guess it works
    Code (Lua):

    local The_Thread_Handle = INVALID_THREAD_HANDLE
    show_location(true)
    local MSG_NN = 1
    function set_msg_index_plus(increment)
    if increment == true then
     if MSG_NN == 13 then
     MSG_NN = 1
     else
     MSG_NN = MSG_NN + 1
     end
    else
     if MSG_NN == 1 then
     MSG_NN = 13
     else
      MSG_NN = MSG_NN - 1
     end
    end
    end
    function function_with_the_code()
    if player_action_is_pressed("CBA_GAC_WEAPON_SELECT_4") then
     if MSG_NN == 1 then
     mission_help_table("MSG_1", LOCAL_PLAYER)
     elseif MSG_NN == 2 then
     mission_help_table("MSG_2", LOCAL_PLAYER)
     elseif MSG_NN == 3 then
     mission_help_table("MSG_3", LOCAL_PLAYER)
     elseif MSG_NN == 4 then
     mission_help_table("MSG_4", LOCAL_PLAYER)
     elseif MSG_NN == 5 then
     mission_help_table("MSG_5", LOCAL_PLAYER)
     elseif MSG_NN == 6 then
     mission_help_table("MSG_6", LOCAL_PLAYER)
     elseif MSG_NN == 7 then
     mission_help_table("MSG_7", LOCAL_PLAYER)
     elseif MSG_NN == 8 then
     mission_help_table("MSG_8", LOCAL_PLAYER)
     elseif MSG_NN == 9 then
     mission_help_table("MSG_9", LOCAL_PLAYER)
     elseif MSG_NN == 10 then
     mission_help_table("MSG_10", LOCAL_PLAYER)
     elseif MSG_NN == 11 then
     mission_help_table("MSG_11", LOCAL_PLAYER)
     elseif MSG_NN == 12 then
     mission_help_table("MSG_12", LOCAL_PLAYER)
     elseif MSG_NN == 13 then
     mission_help_table("MSG_13", LOCAL_PLAYER)
     end
     set_msg_index_plus(true)
    end
     
    if player_action_is_pressed("CBA_GAC_WEAPON_SELECT_5") then
    mission_help_table("Working",LOCAL_PLAYER)
    if MSG_NN == 1 then
    mission_help_table("MSG_1", LOCAL_PLAYER)
    elseif MSG_NN == 2 then
    mission_help_table("MSG_2", LOCAL_PLAYER)
    elseif MSG_NN == 3 then
    mission_help_table("MSG_3", LOCAL_PLAYER)
    elseif MSG_NN == 4 then
    mission_help_table("MSG_4", LOCAL_PLAYER)
    elseif MSG_NN == 5 then
    mission_help_table("MSG_5", LOCAL_PLAYER)
    elseif MSG_NN == 6 then
    mission_help_table("MSG_6", LOCAL_PLAYER)
    elseif MSG_NN == 7 then
    mission_help_table("MSG_7", LOCAL_PLAYER)
    elseif MSG_NN == 8 then
    mission_help_table("MSG_8", LOCAL_PLAYER)
    elseif MSG_NN == 9 then
    mission_help_table("MSG_9", LOCAL_PLAYER)
    elseif MSG_NN == 10 then
    mission_help_table("MSG_10", LOCAL_PLAYER)
    elseif MSG_NN == 11 then
    mission_help_table("MSG_11", LOCAL_PLAYER)
    elseif MSG_NN == 12 then
    mission_help_table("MSG_12", LOCAL_PLAYER)
    elseif MSG_NN == 13 then
    mission_help_table("MSG_13", LOCAL_PLAYER)
    end
    set_msg_index_plus(false)
    end
    end
    function gameplay_the_scroler_init()
     The_Thread_Handle = thread_new("tp_thread_manager")
    end
    function tp_thread_manager()
     while true do
    function_with_the_code()
    delay(0.2)
    end
    end
     
     
    daspex likes this.
  3. Ah,I see.Thats cool.(Like always)Will try that this night.Thank you very much. :)
    Yeah man,that works!So after reading the code serveral times I understand what it does.
    Piece by piece I understand more about the lua scripting.The most difficult thing to me is
    thinking function style like and not line directed.But it is usable anyway. :)
     
    Last edited: Jun 14, 2018
  4. Hm,after testing more intensive i see that if pushing the "4" button it counts +1 but if
    the "5" button is pushed it counts first +1 and after that if pushed again it counts -1.
    Sometimes it is the same in the + direction.Also the "Working" message is not displayed.
     
  5. I have replaced calls for the function and I guess it will work better, also debug "Working" doesn't work because new messages override it
    Code (Lua):

    local The_Thread_Handle = INVALID_THREAD_HANDLE
    show_location(true)
    local MSG_NN = 0
    function set_msg_index_plus(increment)
    if increment == true then
     if MSG_NN == 13 then
     MSG_NN = 1
     else
     MSG_NN = MSG_NN + 1
     end
    else
     if MSG_NN == 1 then
     MSG_NN = 13
     else
      MSG_NN = MSG_NN - 1
     end
    end
    end
    function function_with_the_code()
    if player_action_is_pressed("CBA_GAC_WEAPON_SELECT_4") then
     set_msg_index_plus(true)
     if MSG_NN == 1 then
     mission_help_table("MSG_1", LOCAL_PLAYER)
     elseif MSG_NN == 2 then
     mission_help_table("MSG_2", LOCAL_PLAYER)
     elseif MSG_NN == 3 then
     mission_help_table("MSG_3", LOCAL_PLAYER)
     elseif MSG_NN == 4 then
     mission_help_table("MSG_4", LOCAL_PLAYER)
     elseif MSG_NN == 5 then
     mission_help_table("MSG_5", LOCAL_PLAYER)
     elseif MSG_NN == 6 then
     mission_help_table("MSG_6", LOCAL_PLAYER)
     elseif MSG_NN == 7 then
     mission_help_table("MSG_7", LOCAL_PLAYER)
     elseif MSG_NN == 8 then
     mission_help_table("MSG_8", LOCAL_PLAYER)
     elseif MSG_NN == 9 then
     mission_help_table("MSG_9", LOCAL_PLAYER)
     elseif MSG_NN == 10 then
     mission_help_table("MSG_10", LOCAL_PLAYER)
     elseif MSG_NN == 11 then
     mission_help_table("MSG_11", LOCAL_PLAYER)
     elseif MSG_NN == 12 then
     mission_help_table("MSG_12", LOCAL_PLAYER)
     elseif MSG_NN == 13 then
     mission_help_table("MSG_13", LOCAL_PLAYER)
     end
     
    end
     
    if player_action_is_pressed("CBA_GAC_WEAPON_SELECT_5") then
    set_msg_index_plus(false)
    if MSG_NN == 1 then
    mission_help_table("MSG_1", LOCAL_PLAYER)
    elseif MSG_NN == 2 then
    mission_help_table("MSG_2", LOCAL_PLAYER)
    elseif MSG_NN == 3 then
    mission_help_table("MSG_3", LOCAL_PLAYER)
    elseif MSG_NN == 4 then
    mission_help_table("MSG_4", LOCAL_PLAYER)
    elseif MSG_NN == 5 then
    mission_help_table("MSG_5", LOCAL_PLAYER)
    elseif MSG_NN == 6 then
    mission_help_table("MSG_6", LOCAL_PLAYER)
    elseif MSG_NN == 7 then
    mission_help_table("MSG_7", LOCAL_PLAYER)
    elseif MSG_NN == 8 then
    mission_help_table("MSG_8", LOCAL_PLAYER)
    elseif MSG_NN == 9 then
    mission_help_table("MSG_9", LOCAL_PLAYER)
    elseif MSG_NN == 10 then
    mission_help_table("MSG_10", LOCAL_PLAYER)
    elseif MSG_NN == 11 then
    mission_help_table("MSG_11", LOCAL_PLAYER)
    elseif MSG_NN == 12 then
    mission_help_table("MSG_12", LOCAL_PLAYER)
    elseif MSG_NN == 13 then
    mission_help_table("MSG_13", LOCAL_PLAYER)
    end
    end
    end
    function gameplay_the_scroler_init()
     The_Thread_Handle = thread_new("tp_thread_manager")
    end
    function tp_thread_manager()
     while true do
    function_with_the_code()
    delay(0.2)
    end
    end
    [/lua]
     
  6. Yeah,it works better with msg_nn = 0 if thats what you meant with replace function calls
    I tested this already last night.:)Btw.Is this the only way to make a forward/backward selection?And again thank's a lot for your help.
     
  7. No, you can also use tables, I had an idea to create a dynamic list with them but sorting in lua quite messy.
     
  8. Ah,does that depends on the limited lua interpreter we have?
    Off Topic Rus:KSA 5:0 :) Congratulation! Thats cool. :)
     
    Last edited: Jun 14, 2018
  9. Hm,I read something about tables and higher-order-functions like sort but thats too
    high for me at least at this point of understanding.I think your solution fits better than
    the table stuff but thanks for information.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice