Jump to content




an if statement is a variable


  • You cannot reply to this topic
8 replies to this topic

#1 darkmists

  • Members
  • 6 posts

Posted 06 April 2013 - 06:20 AM

i want to know if it is possible to put an if statement into a variable? if so how?

example of what i want to do

x = if i < 1 then
rs.setOutput("side", true)
end

#2 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 06 April 2013 - 06:22 AM

rs.setOutput("side", i <1)

not sure what you want though

#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 April 2013 - 06:22 AM

No. Unless you're trying to use a function? What is the use case here, what are you actually trying to accomplish?

Edit:

View PostPixelToast, on 06 April 2013 - 06:22 AM, said:

rs.setOutput("side", i <1)

not sure what you want though

This always sets the output, rather than only setting the output if i is less than one.

#4 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 06 April 2013 - 06:29 AM

You can use the ternary operator
local x = z==1 and 'its ture' or 'its false'


#5 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 06 April 2013 - 06:33 AM

View PostLyqyd, on 06 April 2013 - 06:22 AM, said:

This always sets the output, rather than only setting the output if i is less than one.
.-.
rs.setOutput("side", i <1 or rs.getOutput("side"))
that better?

#6 darkmists

  • Members
  • 6 posts

Posted 06 April 2013 - 06:40 AM

nvm i figured it out while thinking of a way to explain. the code i want. very sorry about this. it was my stupid for forgetting how the code works.

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 06 April 2013 - 06:41 AM

rs.setOutput( "side", i < 1 and true or false )


#8 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 06 April 2013 - 07:23 AM

View PostremiX, on 06 April 2013 - 06:41 AM, said:

rs.setOutput( "side", i < 1 and true or false )
"and true"
dafuq?
"or false"
i dont even

seriously these do nothing .-.

#9 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 06 April 2013 - 08:26 AM

Lol ternary operator... What do you mean it doesn't do anything? I thought just plain
rs.setOutput( 'back', i < 1 )
would work but...

View PostLyqyd, on 06 April 2013 - 06:22 AM, said:

View PostPixelToast, on 06 April 2013 - 06:22 AM, said:

rs.setOutput("side", i <1) not sure what you want though
This always sets the output, rather than only setting the output if i is less than one.

EDIT:
Oh misunderstood lol, but setting it to false doesn't matter so rs.setOutput('side', i < 1) is fine really





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users