Jump to content

Recommended Posts

Hi, I'm trying to make a server mod and still just playing around but I've hit an issue that I don't quite understand. In modmain.lua I want to do some stuff with radians, but I get an error in the server log:

[string "../mods/mymod/modmain.lua"]:186: attempt to perform arithmetic on global 'RADIANS' (a nil value)

I don't understand what else I need to do to be able to use that constant in my mod:

require("constants")

function Test()
  ... do stuff with RADIANS ...
end

Test()

 

2 hours ago, NinjaWafflesOfDooM said:

I don't understand what else I need to do to be able to use that constant in my mod:


require("constants")

function Test()
  ... do stuff with RADIANS ...
end

Test()

 

By the time the mod loads constants.lua is already ran, so you don't need to require it.

There's a namespace thing that if the thing you're trying to access isn't defined in modutil.lua that you should prepend "GLOBAL." to access it.

So your code would look like:

local function Test()
    GLOBAL.print(GLOBAL.RADIANS)
end
Test()

Make sure to keep your functions local for things that are only to be used in your file, speeds up processing time in the LUA runtime.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...