• Simple Lua question
    6 replies, posted
Hello, My question is how can I do an "antidote" for something like: -- This is one Weapon [lua] /* Here's a Timer, that never stops giving damage to the player, lets say that it gives 3 damage each second. */ if ent:antidote(true) then timer.Destroy(timer_name) end function Damage(stuff) antidote(false) .. end [/lua] --This is other Weapon (Antidote) [lua] ... ent:antidote(true) ... [/lua] The game says "antidote" is a nil value on the First Weapon Im ready to get rated dumb... I just want to learn Thanks. [highlight](User was banned for this post ("utt" - garry))[/highlight]
Post the whole code and whole error. "is a nil value" is mostly caused when you call serverside functions clientside and in reverse.
[QUOTE=Netheous;40183647]Post the whole code and whole error. "is a nil value" is mostly caused when you call serverside functions clientside and in reverse.[/QUOTE] Actually my real doubt is, how can I do something like, if "a = true" then timer stop Like make a random variable like a, b, or wasd...
[QUOTE=Ion123;40183690]Actually my real doubt is, how can I do something like, if "a = true" then timer stop[/QUOTE] You could use a loop rather than a timer, for something to loop until something is achieved, such as... [CODE] local i = 1 while a[i] do print(a[i]) i = i + 1 end [/CODE] Also, = sets a value of a variable from right to left, == returns a boolean, so that'd be what you want to use in a if statement for your logic.
[QUOTE=Bearklaw_;40183732]You could use a loop rather than a timer, for something to loop until something is achieved, such as... [CODE] local i = 1 while a[i] do print(a[i]) i = i + 1 end [/CODE] Also, = sets a value of a variable from right to left, == returns a boolean, so that'd be what you want to use in a if statement for your logic.[/QUOTE] A loop would cause the game to freeze until the condition is reached.
Ok I'll try to explain myself in other way... [lua] function DamageTimer(ent, timer_name) if IsValid(ent) then ent:TakeDamage(3) elseif ent:antidote(true) then timer.Destroy(timer_name) end end function DamageTarget(path) local ent = path.Entity local tn = Format("info", ent:EntIndex(), math.ceil(CurTime())) timer.Create(tn, 2, 20, function() DamageTimer(ent, tn) end) end -- This is not the all code but I think You get the idea [/lua] And I want ONE weapon to make "ent:antidote(true)"
[QUOTE=Ion123;40183606]The game says "antidote" is a nil value on the First Weapon[/QUOTE] Well first of all ent:antidote() isn't even a valid code. So of coarse it's going to return nil, unless you have a function somewhere else called ENT:antidote(bool). You might want something more like ent.antidote = your bool. This will allow the variable antidote to be specific to the entity, which is what I think you're trying to do. So it should look something more like this: [lua] --Put this somewhere where you want to have the antidote activated ent.antidote = true function DamageTimer(ent, timer_name) if IsValid(ent) then if ent.antitdote then timer.Destroy(timer_name) else ent:TakeDamage(3) end end end [/lua]
Sorry, you need to Log In to post a reply to this thread.