Another question:
What exactly does "and" do when in non if-then statement? Example:[CODE]Msg(tostring(5 and 8)) -- 8
Msg(tostring(8 and 5)) -- 5[/CODE]will always return the second statement. So what does it do exactly? I see it used in allot of scripts but cant understand it exactly.
you need the or
[lua]Msg(tostring(condition and 5 or 8))[/lua]
Like
[lua]local time = (ply:IsAdmin() and 10 or 5)[/lua]
Is the same as
[lua]local time
if (ply:IsAdmin()) then time = 10 else time = 5 end[/lua]
Or for more technical (and confusing) answer: [url]http://en.wikipedia.org/wiki/Short-circuit_evaluation[/url]
[QUOTE=Lexic;23988439]you need the or
Msg(tostring(condition and 5 or 8))Like
local time = (ply:IsAdmin() and 10 or 5)Is the same as
local time
if (ply:IsAdmin()) then time = 10 else time = 5 end[/QUOTE]Hm thats actually really useful. Tried it on one of my scripts and it worked perfectly. Thanks for a good explanation.
[editline]09:37PM[/editline]
Also, another question related to this thread: How to set Networked Variables? Example:[CODE]self:GetOwner():SetNWBool("VwdByCam", true)[/CODE]
Sorry for the bump, but id probably make another thread with the same question as above some time in the future.
[QUOTE=freemmaann;24003126]Sorry for the bump, but id probably make another thread with the same question as above some time in the future.[/QUOTE]
But you've just answered your own question.
[QUOTE=_Kilburn;24005244]But you've just answered your own question.[/QUOTE]
Sry bout that, guess i already knew the answer.
I'll try to express and,or,not as functions in hope to enlighten thee.
[lua]
function and(a,b)
if a then
return b
end
return false
end
function not(a)
if a then
return false
end
return true
end
function or(a,b)
if a then
return a
end
return b
end
[/lua]
:smile:
Sorry, you need to Log In to post a reply to this thread.