Jump to content




colors.combine and colors.subtract not doing their jobs?

lua

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

#1 Tassyr

  • Members
  • 80 posts

Posted 08 April 2013 - 08:49 AM

So I'm trying to set up a system where by detault the computer keeps output steady on six redstone colors (Green, Red, Gray, White, Blue and Black.) and one that keeps off (Cyan.) Each of the six "on" colors can be toggled off for 10 seconds, then will reactivate. THAT part I have working just fine.

The one that doesn't work fine is the seventh option- the plan is to leave the Six "on" colors on and just activate the Cyan one. However every time it activates, the Cyan is the ONLY one active- the others deactivate. I'm going in circles. Anyone got an idea what I did wrong?

Spoiler


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 08 April 2013 - 08:51 AM

fix the code spoiler please.

EDIT: nvm, you just did it.

Edited by theoriginalbit, 08 April 2013 - 08:52 AM.


#3 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 08 April 2013 - 08:51 AM

The BB interpreter messed it up. Pastebin please.

EDIT: Yay ninja'd...

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 08 April 2013 - 08:55 AM

one of your problems is colors.combine and colors.subtract aren't magic, they don't look for what the bundled output is already, they combine the colours that you supply, you are only supplying one colour. make it something like
c = colors.combine(colors.cyan, rs.getBundledInput("right"))
rs.setBundledOutput("right",c)

EDIT: Also use elseif's for your checking of what the user entered.

Edited by theoriginalbit, 08 April 2013 - 08:57 AM.


#5 Tassyr

  • Members
  • 80 posts

Posted 08 April 2013 - 09:19 AM

oh for the love of... I'm an idiot. I forgot I meant to put

c = colors.combine(c, colors.cyan)

But your code works better. x.x

Also is there some colossal problem with using if instead of elseif?

#6 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 08 April 2013 - 09:22 AM

View PostTassyr, on 08 April 2013 - 09:19 AM, said:

Also is there some colossal problem with using if instead of elseif?
yes, it makes code look ugly and inneficent

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 08 April 2013 - 03:10 PM

View PostPixelToast, on 08 April 2013 - 09:22 AM, said:

View PostTassyr, on 08 April 2013 - 09:19 AM, said:

Also is there some colossal problem with using if instead of elseif?
yes, it makes code look ugly and inneficent
Not only that, but it does use extra CPU cycles to evaluate each conditional, as opposed to just 'skipping' them all.

#8 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 09 April 2013 - 02:13 AM

if anyone cares about a couple more CPU cycles from simple if statements they sould just go write in lua bytecode to achieve maximum efficiency

#9 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 09 April 2013 - 03:08 AM

View PostPixelToast, on 09 April 2013 - 02:13 AM, said:

if anyone cares about a couple more CPU cycles from simple if statements they sould just go write in lua bytecode to achieve maximum efficiency

But using elseif instead of another if is a quick win of efficency
writing bytecode is more efficient but not worth the work it takes :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users