Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
squall2044

reactors, stargates, and automation

Question

I'm trying to write a program that checks the power in my Stargate and it's state (connected, idle, etc...) and then turn my reactor on and of accordingly. It works for the power portion but does not seem to care about the of the gate. I also have a config file that is working I'm including it in case anybody notices something wrong with it.

 

here are the codes:

 

config file:

c = require("component")

e = require("event") ---here in case I choose to write other progams

r = c.getPrimary("br_reactor")

s = c.getPrimary("stargate")

t = require("term")  ---here in case I choose to write other programs 

 

now the code itself:

 

dofile("config")

 

if s.energyAvailable() <= 99999 and

 s.stargateState() == idle then

  r.setActive(true)

else if s.energyAvailable() == 1000000 or

 s.stargateState() ~= idle then

  r.setActive(false)

 end

end

 

-----------------------------------------------------------------------------------------------------------------------------------

In the end I will be looping it but that i have no problem with except for programming in a "break" key that I have no idea.

 

For SGCraft methods and events go here: http://www.cosc.canterbury.ac.nz/greg.ewing/minecraft/mods/SGCraft/doc/ComputerCraft.html

 

As for Big Reactors methods and events I'll edit this when their site comes back online

 

 

 

 

Thanks in advance for any help you can give.

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
  • Solution

Without seeing the updated code it's hard to guess. But probably it's just because - according to the documentation - it is should be spelled "Idle". (with a big "I")

One hint for future debugging: Using the function "print" to display important values while running your program helps a lot.

When you do that you have to think about what output you expect and have to compare that to what you got:

dofile("config")

print("energy", s.energyAvailable()) --debug output for energy available
print("state", s.stargateState(), (s.stargateState() == "idle")) --you can also output some of your conditions to see if they are working as expected
if s.energyAvailable() <= 99999 and
 s.stargateState() == "idle" then
  r.setActive(true)
else if s.energyAvailable() == 1000000 or
 s.stargateState() ~= "idle" then
  r.setActive(false)
 end
end

expected output

energy   12345
state    idle      true

real output (at least what I would expect -> never tested):

energy   12345
state    Idle      false   -> "Idle" is not the same as "idle". Therefore the condition fails to work correctly.

I hope that helped. (It makes me think about writing a tutorial for debugging...)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.