LUA Modding ~ How to Create a Random Number Generator?

Discussion in 'Programming' started by KennyWah, Jan 25, 2023.

  1. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
    So when taking a LUA file and making modifications to it inside your mod.. how can you tell if it is loading or loaded when you make changes to said LUA file?

    I am kind of a noob when it comes to LUA modding
    -
    Okeh so I've figure the above out.



    --- Post updated ---
    Now how would I go about writing an equation which takes two values, determines which is lesser then the other and assigns that as the value to move forward with?

    Nvm.. I've managed to do this as well.
     
    #1 KennyWah, Jan 25, 2023
    Last edited: Jan 25, 2023
  2. Leo Zieger

    Leo Zieger
    Expand Collapse

    Joined:
    Jan 12, 2023
    Messages:
    823
    I don´t know in which programming language but standard will be something like that:

    IF item1<item2
    THEN valuetouse = item1
    ELSE valuetouse = item2
    END IF
     
  3. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
    all I needed was something like this - (I got it working after figuring out the correct math I needed to use for LUA to do this for me)

    Code:
    assignedValue = math.min(value1,value2)
     
  4. Instant Winrar

    Instant Winrar
    Expand Collapse

    Joined:
    Jun 12, 2015
    Messages:
    711
    Lua is a proper noun, not an acronym btw
     
    • Like Like x 1
  5. Leo Zieger

    Leo Zieger
    Expand Collapse

    Joined:
    Jan 12, 2023
    Messages:
    823
    That´s more elegant! :oops:
     
    • Like Like x 1
  6. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
    Thank you Dr.English
     
    • Agree Agree x 1
  7. JlnPrssnr

    JlnPrssnr
    Expand Collapse

    Joined:
    Jun 15, 2016
    Messages:
    432
    akshually it's Portuguese
     
    • Like Like x 1
  8. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
    How do I create and assign a value to a random number generator?

    I've tried using these functions in places and I just cannot get a RNG to actually work and function as intended.

    Code:
    -
           random()
    -
           math.random()
    -
        math.randomseed( os.time() )
           math.random()
    
    -
        math.randomseed( os.time() )
        local number = math.random()
     
  9. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,341
    math.random(max value you want)
     
  10. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
    yeah, it doesn't work, it just takes that value and uses that 100% of the time.

    So if I write

    math.random(32) it'll just always output as 32.
     
  11. AlexKidd71

    AlexKidd71
    Expand Collapse

    Joined:
    Mar 16, 2022
    Messages:
    492
  12. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
  13. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,657
    Alright, what I actually need to do is write a loop that assigns a variable to an output value from a looping Random Number Generator.
     
  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