And in a non if-then statement?

Another question:
What exactly does “and” do when in non if-then statement? Example:


Msg(tostring(5 and 8)) -- 8
Msg(tostring(8 and 5)) -- 5

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: http://en.wikipedia.org/wiki/Short-circuit_evaluation

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:


self:GetOwner():SetNWBool("VwdByCam", true)

Sorry for the bump, but id probably make another thread with the same question as above some time in the future.

But you’ve just answered your own question.

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: