This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
n1ghtk1ng's profile picture

[LUA] How to get multiple booleans values to stay on a state file(better explanation inside)

Started by n1ghtk1ng, 05 September 2012 - 11:56 PM
n1ghtk1ng #1
Posted 06 September 2012 - 01:56 AM
I'm trying to setup a computer so that I can enter my commands into it and turn my machines/engines/ etc. to turn on/off. I made the values save into a different file so that when I rebooted I wouldn't have to turn everything on again, but when I turn something on, everything else turns to false, except (of course) what I turned on, then when I turn something else on again, my previous input would turn off and so on. How can I get the boolean values to stay unless I turn that off/ false?

link to code : http://pastebin.com/8HS4skup
Pharap #2
Posted 06 September 2012 - 02:20 AM
it seems you are only showing one of your programs. Do you have a paste of what redset does? I get the feeling it might be the cause of the problem
n1ghtk1ng #3
Posted 06 September 2012 - 02:41 AM
it seems you are only showing one of your programs. Do you have a paste of what redset does? I get the feeling it might be the cause of the problem
to be completely truthful, that is the only part of my code that I dont know what it does ( shell.run("redset", side, "white", file.readLine()) )I
Do you have any Idea how I could improve that part of the code or any other way I could do this? I have looked everywhere and that was the only thing I could find.
Pharap #4
Posted 06 September 2012 - 03:08 AM
it seems you are only showing one of your programs. Do you have a paste of what redset does? I get the feeling it might be the cause of the problem
to be completely truthful, that is the only part of my code that I dont know what it does ( shell.run("redset", side, "white", file.readLine()) )I
Do you have any Idea how I could improve that part of the code or any other way I could do this? I have looked everywhere and that was the only thing I could find.
What you mean is, you are using someone else's code and have no bloody clue what it does, right?
well, redset should be a program in your computer, if it isn't there, you should be getting errors.

Well your major flaw is that when the output is being set, it's being set to a single colour, thus it's only sending that one colour, not all the colours needed. To fix that you'd need a variable storing the current colour output and you'd need to amend it with every switch on/off of a machine. If you have no clue how to do that, I can walk you through it, but solving the problem from what I've just said should be simple enough if you are proficient with the colours api.
n1ghtk1ng #5
Posted 06 September 2012 - 03:36 AM
it seems you are only showing one of your programs. Do you have a paste of what redset does? I get the feeling it might be the cause of the problem
to be completely truthful, that is the only part of my code that I dont know what it does ( shell.run("redset", side, "white", file.readLine()) )I
Do you have any Idea how I could improve that part of the code or any other way I could do this? I have looked everywhere and that was the only thing I could find.
What you mean is, you are using someone else's code and have no bloody clue what it does, right?
well, redset should be a program in your computer, if it isn't there, you should be getting errors.

Well your major flaw is that when the output is being set, it's being set to a single colour, thus it's only sending that one colour, not all the colours needed. To fix that you'd need a variable storing the current colour output and you'd need to amend it with every switch on/off of a machine. If you have no clue how to do that, I can walk you through it, but solving the problem from what I've just said should be simple enough if you are proficient with the colours api.
So basically you're saying that I just need to combine (colors.combine(col1, col2…) and so on? (I.E. The white bundled output, store that as the col1 variable, and the blue bundled output is on, so I would store that as the col2 variable?)

And sorry for being so ignorant, This is my first programming language(at age 13), and I've only being programming ~2 weeks.

Edit: This is my first time using most of these API'S (fs, colors, shell)
Pharap #6
Posted 06 September 2012 - 03:52 AM
it seems you are only showing one of your programs. Do you have a paste of what redset does? I get the feeling it might be the cause of the problem
to be completely truthful, that is the only part of my code that I dont know what it does ( shell.run("redset", side, "white", file.readLine()) )I
Do you have any Idea how I could improve that part of the code or any other way I could do this? I have looked everywhere and that was the only thing I could find.
What you mean is, you are using someone else's code and have no bloody clue what it does, right?
well, redset should be a program in your computer, if it isn't there, you should be getting errors.

Well your major flaw is that when the output is being set, it's being set to a single colour, thus it's only sending that one colour, not all the colours needed. To fix that you'd need a variable storing the current colour output and you'd need to amend it with every switch on/off of a machine. If you have no clue how to do that, I can walk you through it, but solving the problem from what I've just said should be simple enough if you are proficient with the colours api.
So basically you're saying that I just need to combine (colors.combine(col1, col2…) and so on? (I.E. The white bundled output, store that as the col1 variable, and the blue bundled output is on, so I would store that as the col2 variable?)

And sorry for being so ignorant, This is my first programming language(at age 13), and I've only being programming ~2 weeks.

Edit: This is my first time using most of these API'S (fs, colors, shell)

It's ok, just be sure to mention if you've copied someone elses code, otherwise people will assume you've written it and thus know what everything in it does.
And if you don't they will figure out by about the second question when you don't know what one of the lines does. It's easiest to just mention from the start so people know.

Anyway, in regards to fixing your problem:
In CC, colours are stored as numbers, thus they are a fixed value, even combined colours, so you can store the output to a single variable.

Firstly, set that variable at the top, something like
local OP = 0 –0 is no colour output
Then what you want to do is in each section of code changing the bundled output, before changing anything the output, set OP to the value of the current bundled output (so OP = rs.getBundledOutput()) then when you go to set the output, where the output is currently 'colours.white' or 'colours.yellow' or something, set it instead to output OS and the new colour, so for the white output:
rs.setBundledOutput(side, colours.combine(OP, colours.white))
in the case of setting the machine off, use colours.subtract instead, so:
rs.setBundledOutput(side, colours.subtract(OP, colours.white))

I'm sure you can fix it from that, but again, if need be, I can upload a paste of the reworked code.

Also if you don't have a redset program on your computer, you can delete all those lines regarding the running of redset.

I also remember my first few times programming, it's been nearly a year since then, things get a lot easier.
n1ghtk1ng #7
Posted 06 September 2012 - 12:56 PM
http://pastebin.com/XpCMx4Z0
I did what you told me to (well how I interpreted it) But when I enter lets say enginecoolant, nothing happens.)
Also is there any other way I could improve my code?
Thanks :D/>/>