Jump to content

Recommended Posts

Posted

Hey,

I'm pretty new to ComputerCraft, just started playing around with it today. I've made a couple simple programs such as a password protected door, and a computer that controls lights, however what I have been trying for the past hour or so is a computer to control all the machines in my factory. It's pretty much done - I just can't figure out how to "add up" the bundled cable values, for example, I have 3 output cables: white, red, and orange. I can turn white on, but when I turn red on, white turns off, because the value changes to 16385 instead of 16386 for both white and red.

I know what I have to do, make it so that if white cable is on, it adds one to the red cable when I turn it on, and if white and red are on, it adds 16386 to the orange cable, so all 3 turn on. Only thing is I have no idea how to do this in Lua. I think it might involve using variables, although I am still not sure.

If you could help it would be much appreciated, so close to finishing this and now I'm stumped right at the end :(

Code: http://pastebin.com/iAwFCbyJ

The "state" variable is when I tried to use variables to add them but I could not get it to work.

Posted

Declare state as 0 (All off) then have a function that takes the variables state, cable and set

State is the state variable

Cable is the cable you want to change

Set is it's new state, IE On/Off

First the function parses state, so it finds out what is on and off already

Then it finds out what cable needs to change and what to

Makes that change over

And returns state

That is how I would handle it

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...