Set Slow Motion with a Variable?

Discussion in 'Programming' started by Occam's Razer, Nov 22, 2016.

  1. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Hi, community!

    For the projects (scenarios, specifically) that demand it, I've been using this snippet of code for slow motion:

    Code:
    helper.queueLuaCommandByName('scenario_player0', 'bullettime.set(1.8)')
    However, a recent test I've done has hit a snag. I can't seem to set the slow motion with a variable:

    Code:
    helper.queueLuaCommandByName('scenario_player0', 'bullettime.set(sloMo)')
    A quick look inside bullettime.lua indicates that the set() function specifically weeds out any inputs except raw numbers. But surely my variable, effectively being a number, ought to suffice, right?
     
  2. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    The issue here is, that you are not sending the value of your variable over.
    Your variable only exists in the scope it is defined in and in this case it's at maximum GE lua.
    The bullettime code is executed in vehicle lua though, so there is absolutely no chance this could work as is.

    The fix however is easy, you just need to make it send the actual value instead of trying to use a reference.
    Code:
    helper.queueLuaCommandByName('scenario_player0', 'bullettime.set('..tostring(sloMo)..')')
    Is what you are actually looking for ;)
     
  3. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Thanks, works like a charm. I think I tried using 'tonumber' at one point, so I was kinda close.
     
  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