Communicate from vlua to gelua

Discussion in 'Utilities and programming' started by snoutie, Feb 4, 2025.

  1. snoutie

    snoutie
    Expand Collapse

    Joined:
    Dec 3, 2021
    Messages:
    38
    We have the option to communicate from gelua to vlua using mailboxes, but I was not able to figure this out the other way around.

    Maybe I am stuck somewhere else.

    Here is some context of what I want to achieve:

    On the event onInventoryPreRemoveVehicleObject I want to store the current beamstate of the vehicle using beamstate.save()

    However veh:queueLuaCommand() seems to put that command at the end of the execution stack which will then cause the vehicle being removed BEFORE this command could be issued.

    Is there a way to call this function without using
    queueLuaCommand() by direcly accessing vlua? Basically I want to communicate that beamstate.save() is done and then continue with the processing inside gelua.

    Even more context: source
     
  2. TommoT

    TommoT
    Expand Collapse

    Joined:
    Mar 5, 2017
    Messages:
    48
  3. snoutie

    snoutie
    Expand Collapse

    Joined:
    Dec 3, 2021
    Messages:
    38
    Unfortunately that is "asynchronous" or queued, rather. I mean it's the same method just the other way around.
    If you have your code like this:
    print("A")
    obj:queueGameEngineLua('print("B")')
    print("C")

    The output will be
    A
    C
    B
    which is not ideal for my case.

    I am hooking into an event where I want to save the vehicle state.
    After the event callback is finished the vehicle will be removed.
    Meaning if I use the method above, the vehicle saving will be queued, then the vehicle gets removed and after that it will be saved (which obviousely fails)

    Maybe I misunderstood your answer.
     
  4. TommoT

    TommoT
    Expand Collapse

    Joined:
    Mar 5, 2017
    Messages:
    48
    Oh okay, so i misunderstood your question. Sorry, i don't know how to help,but usually some people on the Modding for Dummies discord know a bit better, so i recommend you ask there maybe
    --- Post updated ---
    And have you tried making it wait for your command to finish before unloading somehow? That would fix the async issue i would guess
     
  5. snoutie

    snoutie
    Expand Collapse

    Joined:
    Dec 3, 2021
    Messages:
    38
    Yes, usually I would implement something along the lines of:
    Code:
    M.isCompleted = false
    local function checkIsCompleted()
      while not M.isCompleted do --busy wait
    
      end
    end
    
    local function run()
       object:queueLuaCommand("myModule.isCompleted = true")
       checkIsCompleted()
    end
    
    But this will never terminate. I would need a proper method of communicating between veh and ge

    Unfortunately I don't use discord anymore, so I have to stick to the forums
     
  6. TommoT

    TommoT
    Expand Collapse

    Joined:
    Mar 5, 2017
    Messages:
    48
    t
    I do think it is probably possible by using coroutines, with beam's job system and some callback. Im sorry that i dont have an exact solution, but its probably worth looking into that. If that doesn't work, it is probably not possible, at least not by hooking onInventoryPreRemoveVehicleObject
     
  7. snoutie

    snoutie
    Expand Collapse

    Joined:
    Dec 3, 2021
    Messages:
    38
    I managed to work around this issue by overwriting the function that removes the vehicles with my own function. I then call the original function afterwards.

    For reference: source code

    Thanks for your help!
     
    • Like Like x 1
  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