Jump to content

AmbiguousMonk

Member
  • Posts

    6
  • Joined

  • Last visited

Reputation Activity

  1. Like
    AmbiguousMonk reacted to Fenris_Wolf in Are Persistent Variables Possible?   
    Technically, thats not a global. Its a local variable, with the scope of the file is written in, and can only be accessed from that file. A global variable is defined in lua without the 'local' keyword, and accessed from any file. Not trying to be picky but it helps to clarify when explaining.
    Global variables should be avoided, Local variables with a file scope (like the previous example) are much more preferred.
  2. Like
    AmbiguousMonk reacted to nater in Are Persistent Variables Possible?   
    If you want this variable to persist throughout your script, and be usable in other functions in this same file, you simply need to declare it as a global variable.
    Here is a basic example:
    local testVar = 0 local function Global()     testVar = testVar + 1     print(testVar) end  
    However, if you would like this variable to persist when quitting the game, you can save it as ModData and it will be saved to the specific character that executed the script.
    Here is a basic example of this:
    --Saving getSpecificPlayer(0):getModData()["Test"] = ZombRand(100) --set "Test" to a random value between 0-99 --Loading if (getSpecificPlayer(0) ~= nil) then --if player not nil   print("*****test value:*****")   print(getSpecificPlayer(0):getModData()["Test"]) --print the value end  
  3. Like
    AmbiguousMonk reacted to Fenris_Wolf in Looping over getBodyParts()   
    ah sorry I see what I did there... my previous post was early my time and I may not have had enough coffee.
     
    The problem is getPlayer():getBodyDamage() is returning a java array. Doing:
    if parts[i] then parts[i]:RestoreToFullHealth() end Is trying to treat that java array as a lua table, which it's not. It should be used like:
    if parts:get(i) then parts:get(i):RestoreToFullHealth() end  
  4. Like
    AmbiguousMonk reacted to Fenris_Wolf in Reference List of Lua Events   
    Just a thought, It would be useful have listed on each event's page if the event is triggered client side, server side, or both. Some are obvious of course (such as mouse movements etc), but no so much with others.
×
×
  • Create New...