Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Lua, a variable is unexpectedly nil
    text
    copied!<p>I have programmed a 'punishbox' (to punish a player for rulebreaking) for my Crysis Wars server mod but for some reason I keep getting this error:</p> <blockquote> <p>[Warning] [Lua Error] scripts/functions.lua:340: attempt to perform arithmetic on global 'tme' (a nil value)</p> </blockquote> <p>But the thing is, <code>tme</code> is actually a number value between 0 and 15. The below code basically sets up the 'punishbox' and checks if it's still valid for the player or not. As you can see, <code>tme</code> is actually a value (if it was not, the code would not run at all). Am I doing something wrong here?</p> <p>As this is a specific situation, I can't find that much on the internet. <code>tme</code> is referenced from <code>time</code>, which is forwarded to the function by a chat command and is definitely a number.</p> <p>Also, is there any simpler way of doing this?</p> <p>Code:</p> <pre><code>function XPunishPlayer(Name, time, reason) if (time &gt; 5) then System.LogAlways("[SYSTEM] Punished by administrator: "..Name:GetName()..""); end if (not Msg) then local tme = math.floor(time*60); Msg = true; XMessageChatToPlayer(Name, "[!punish] You were punished for "..time.." minutes: "..reason..""); g_gameRules.game:RenamePlayer(Name.id, "[PUNISH]"..Name:GetName()..""); XMessageChatToPlayer(Name, "[!punish] You can use !pm to dispute this punishment."); g_gameRules:KillPlayer(Name); end Script.SetTimer( 1000,function() local tme = tme+1; XPunishPlayer(Name, time, reason); Name.actor:SetNanoSuitEnergy(0); local punish = math.floor(timeleft-1); g_gameRules.onClient:ClStepWorking(g_gameRules.game:GetChannelId(Name.id), tme); if (tme == math.floor(time*60)) then g_gameRules.onClient:ClStepWorking(g_gameRules.game:GetChannelId(Name.id), false); XMessageChatToPlayer(Name, "[!punish] Released from the punishbox."); XMessageInfoToAll("Unpunished "..Name:GetName()..", was punished for "..time.." minutes: "..reason.." (Server Administration)"); return; end end); end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload