math.random returns the same numbers

  • #40, by sebastianThursday, 17. November 2016, 15:20 8 years ago
    when you make it local inside a function, its only available inside the function

    Thread Captain

    2346 Posts


  • #41, by afrlmeThursday, 17. November 2016, 15:58 8 years ago
    As Sebastian says, you need to declare it as local inside of a function if you want it to only be accessible from inside of the function & sorry, I didn't realize what you was talking about. I was referring to these myself...
    function name(var1, var2)
    
      var1 = Objects[var1]
    
      var2 = Scenes[var2]
    
    end
    
    
    
    name("rock", "beach")

    The input variables of your function become local automatically. Manually declared variables will either need to be set local by you or left as global.

    Imperator

    7278 Posts

  • #42, by ke4Thursday, 17. November 2016, 17:06 8 years ago
    Oh interesting, didn't know that. Anyway what i meant exactly is if it's not declared as local, is it as global for the whole engine or is as local for the current script. That it would be accessible outside of the function but only in the same script

    Key Killer

    810 Posts

  • #43, by afrlmeThursday, 17. November 2016, 18:17 8 years ago
    local is local inside of whatever you declare a variable.

    If you declare a variable inside of the main script then any function or loop block inside of the same script can access it. If you declare a local variable inside of a function or loop block then it will only be accessible from inside of that function or loop block.

    Imperator

    7278 Posts

  • #44, by ke4Thursday, 17. November 2016, 20:01 8 years ago
    Thanks for explaining razz

    Key Killer

    810 Posts

  • #45, by afrlmeThursday, 17. November 2016, 20:09 8 years ago
    Thanks for explaining razz

    No problem at all mate. smile

    Imperator

    7278 Posts