Jump to content




Bundled cable troubles.

computer

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

#1 plazter

  • Members
  • 134 posts

Posted 23 August 2016 - 02:14 PM

Hello again pros!

- I am trying to make a simple code for a few spawners, and want to use bundled cables, but i've hit a brick wall... im not sure what im doing wrong.. the code works more or less,
but its not saving the colors thats allready active in the table i want to use for it..

(Sorry for the bad describtion)

http://pastebin.com/0ynx1UvH

Spoiler

Hope you can help me!!

Regards Plazter

#2 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 23 August 2016 - 02:25 PM

getBundledOutput doesn't work like you think it does. It gives back a 16bit number in which each of the individual bits corresponds to a different wire being on or off, 1 or 0.

There is a method called colors.test() in which it tests if a number, usually 16 bit color code, contains another number, 16 bit color code.

if(colors.test(rs.getBundledOutput("right"),colors.green)) then
--#If the input from the right has the color green on.
end
You can use this to setup an if-else statement in which it tests for colors that are on/off.
Or you could of course use this to test for if the color is in the output and then save it.

Another way to do so, would be to grab the Output number and work in order backwards and modulus each number, starting at bit 16, and down to bit 1, if the modulus is 0, then the output contains that color. If it contains that number, subtract it from the total.

Edited by Dragon53535, 23 August 2016 - 02:36 PM.


#3 plazter

  • Members
  • 134 posts

Posted 23 August 2016 - 02:36 PM

Spoiler

uhm.. so 1 to 16 .. it returns with the correct number (heximal) from the cc wiki :s..
but how would i get it to add the colors aswell tho? thats kinda the problem currently :P

#4 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 23 August 2016 - 02:38 PM

Adding the colors to the output is easy as it's just a number and each power of 2 is literally a single binary digit. Add or subtract the number.

#5 plazter

  • Members
  • 134 posts

Posted 23 August 2016 - 02:41 PM

well its easy to hard code yes, but theres more colors to come since i got a lot of spawners on the server im playing on :), kinda why i want it to automatic remember the colors thats on and unless i click the right button it goes off ofc.. (not sure that made sense :B)

#6 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 23 August 2016 - 02:44 PM

So you want persistent storage of the number?

File Tutorial

If I misinterpreted that and you mean you don't know how to set new colors in with the old. Just set the output with the old or new color subtracted or added in.

local num = rs.getBundledOutput("right")
num = num - 256
rs.setBundledOutput("right",num)


#7 plazter

  • Members
  • 134 posts

Posted 23 August 2016 - 02:47 PM

View PostDragon53535, on 23 August 2016 - 02:44 PM, said:

So you want persistent storage of the number?

File Tutorial

If I misinterpreted that and you mean you don't know how to set new colors in with the old. Just set the output with the old or new color subtracted or added in.

local num = rs.getBundledOutput("right")
num = num - 256
rs.setBundledOutput("right",num)

not persistant (i think) but just keep the ones thats on at the moment (currently got 8 spawners connected to a bundled cable with levers.. really ugly :P)
but as u can i see i tried to make the current "signal" to be saved in the table on.

Quote

-snip-
num = num - 256

Whats the 256 for? O_o

#8 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 23 August 2016 - 03:48 PM

The second part should be what you want then. The 256 is just one of the bits, in this case LightGray is the color.

You could of course use colors.add and colors.subtract, but I like dealing with the numbers myself

Edited by Dragon53535, 23 August 2016 - 03:49 PM.


#9 plazter

  • Members
  • 134 posts

Posted 23 August 2016 - 04:11 PM

Ah ok, ill look at it once im a little more fresh :P drove tired in it xD

#10 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 August 2016 - 06:52 PM

It's better to use colors.add and colors.subtract, as these will ensure that the value remains unchanged if the color was already present or already absent.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users