is it possible throughout and entitys script to allow a character such as X represent a number and have a peice of code change that X to a number depending on certain conditions
Yup, these are called variables.
[lua]x = 6
if x >3 then
x = x + 3
print(x) --Prints 9[/lua]
To do it in an entity, and specific to that entity declare the variable as such :
ENT.x = 6
self.x = 6
Or inside a SWEP :
SWEP.x = 6
self.x = 6
Oh and if you want a variable to be accessible from only a part of the script, put local in front of it.
local function foo() --This function is local to this script
local x = 6 – And this variable is local to this function
foo() --Calling the function to set x
print(x) – prints nothing, x doesn’t exist.
can u tell me the code i would need to use I am using this in a way so that if a certain amount of power is given it will change
Go to http://www.lua.org, get the binaries for windows (http://luaforwindows.luaforge.net/), read and understand Programming in Lua (http://www.lua.org/pil/index.html) and/or other (good) tutorials and write a lot of programs (like print hello world, guess my number, tic tac toe with “ai” that never loses etc.) to fully understand what you have learned. Use the lua interpreter from the binaries that you have downloaded to execute them and refer to the lua documentation if you need more detailed info on whatever you want to know (http://www.lua.org/docs.html). When you fully understand the language and it’s capabilities, return to gmod. Study the code of other users addons, sweps, stools and gamemodes. Play around with them, add stuff that could be useful and use the forum/wiki to learn about the parts you don’t fully understand.
Once you have done this, it’s time to return to what you are doing now.
If you’re new to programing, this will be very hard and time consuming, but sadly it’s the only good way to get something done that’s not full of bugs. Seriously, learning Lua when you’'ve never programmed before is hard enough, but getting started with gmod/lua at the same time is next to impossible (that’s the impression I have), so take your time and concentrate solely on lua before moving on.
Lua is pre-compiled so technically it isn’t interpreted.
Yes, it is jit compiled into bytecode (but not in a previous step. like java). I chose the term interpreter, because I simply don’t know a better fitting term. If you could enlighten me here, please do.