Jump to content

Recommended Posts

Posted

I am trying to use the computer access port from the Big Reactors mod to be able to access my reactor through a computer, but something doesn't seem to be working. I want to use the .getEnergyProducedLastTick function(?) and print it as a string, but when it is printed, it is printed as a nil value, meaning that it either crashes the program, or when I use the tostring() function(?) it shows me a weird set of numbers and letters. What am I doing wrong? Here are the two programs I am using. One of them is for a computer connected to a monitor, the other is for the computer connected to the reactor.

monitor computer:

mon = peripheral.wrap("top")
mon.clear()
connect = peripheral.wrap("back")
connect.open(25565)
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if message == "connected" then  
  mon.clear()
  mon.setTextScale(1.4)
  mon.setCursorPos(10,2)
  mon.write("CONNECTED TO REACTOR!")
  connect.transmit(25565,25565, "iw")
  os.sleep(2)
  mon.clear()
end
repeat
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
connect.transmit(25565, 25565, "it")
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(1,1)
mon.write("The Current Amount of")
mon.setCursorPos(1,2)
mon.write("Fuel is:", message)
print(message)
until message == 0
if message == 0 then
  mon.clear()
  mon.setCursorPos(1,1)
  mon.write("OUT OF FUEL!!!!")
end

and the reactor computer,

connect = peripheral.wrap("right")
connect.open(25565)
reactor = peripheral.wrap("front")
if reactor.getConnected() == true then 
  connect.transmit(25565,25565,"connected") 
  sleep(1)
end
repeat
  fAmount = reactor.getFuelAmount
  Amount = tostring(fAmount)
  connect.transmit(25565,25565, Amount)
  sleep(1)
until fAmount == 0

in this exact example I am actually using the get fuel amount function(?). Oh, and by the way, each (?) after the word function is me asking if that is the right word to use for that line of code.

Posted

I have no idea about the workings of Computercraft, but it should be noted that we are right on the edge of the CC1.5>CC1.6 migration right now. In 1.2.9e (recommended), you should be able to do everything the old CC1.5 way. In the 1.2.10 beta, we currently seem to have a mismatch with the BigReactors version, which only supports CC1.6. And there is still only CC1.5 in there. So make sure you don't use the beta if you want BigReactors to work with ComputerCraft.

 

Tekkit devs have >acknowledged that the CC1.6 update is up in the near future (barring any problems that might still arise). Probably another beta release soon.

Posted (edited)

As a principle when you call a function that doesn't need a parameter you should add () afterwards.

For instance :

fAmount = reactor.getFuelAmount
should be :

fAmount = reactor.getFuelAmount()
An example of code that was working before the changes as an example :

        local t = "Big Reactor Status: "..active..
                          --"~/Active: "..tostring(reactor.getActive())..
                          "~/Temperature: Fuel="..reactor.getFuelTemperature().." Casing="..reactor.getCasingTemperature()..
                          "~/Fuel: "..reactor.getFuelAmount().." / Waste: "..reactor.getWasteAmount()..
                          "~/ControlRods: "..reactor.getNumberOfControlRods()..
                          "~/Fuel Efficiency: "..math.floor(temp/100)..
                          "~/Energy: "..string.format("%f", reactor.getEnergyProducedLastTick()).."/Ticks"..
                          "~/Stored: "..reactor.getEnergyStored()
But as stated by Curunir you should wait before invest to much time doing a nice program that the next beta became recommended including the new version of ComputerCraft changes... Edited by M1r077
Posted

I have not tried communicating between CC computers yet, so not sure if that is all correct. I do monitor and control steam flow to a turbine with a CC PC on the turbine computer port and monitor a reactor with same computer using wired modem on reactor computer port. Output is to an advanced monitor adjacent to the computer.

 

Doesn't your reactor script give you an error about line 9 which seems to be missing () or may explain why it is nil? In other words it should be:

fAmount = reactor.getFuelAmount()

Posted

No, I do not have any errors there, but that may just be my problem. I was using this web page for all my reactor controls, and it doesn't have the () after each function... For Curunir and M1r077, I am currently using the recommended version of tekkit, although with just a couple mods added in, which I think would be a great addition to the pack. (Minus tinker's construct, since this is a tech pack.) These mods should not in any way change how CC works with Big Reactors.

Posted

Thanks so much guys. Another question; I tried to make the code easier to handle, in ways like making certain parts of the code functions so I could use them more without taking the time to rewrite them over and over again. But now,I'm getting the same error again. I made sure that my methods like reactor.getFuelAmount had () at the end, but I am still getting a nil concatenating error. Am I making the functions incorrectly? Any help would be appreciated.

Here are the two scripts (again)

monitor computer,

function getMessage() 
  local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
end

function getRF() 
  getMessage()
  connect.transmit(25565, 25565, "gI")
  mon.setCursorPos(5, 1)
  mon.write("The current amount of RF")
  mon.setCursorPos(6, 1)
  mon.write("produced is:".. message)
end

function getFuel() 
  getMessage()
  connect.transmit(25565, 25565, "iG")
  mon.setTextScale(1)
  mon.setCursorPos(1, 1)
  mon.write("The Current Amount of")
  mon.setCursorPos(1, 2)
  mon.write("Fuel is:".. message)
end

mon = peripheral.wrap("top")
mon.clear()
connect = peripheral.wrap("back")
connect.open(25565)
getMessage()
if message == "connected" then  
  mon.clear()
  mon.setTextScale(1.4)
  mon.setCursorPos(10,2)
  mon.write("CONNECTED TO REACTOR!")
  connect.transmit(25565,25565, "iw")
  os.sleep(2)
  mon.clear()
end
i = 5
repeat
  mon.clear()
  mon.setCursorPos(1, 1)
  getFuel()
  getRF()  
  sleep(1)
until i == 6
if message == 0 then
  mon.clear()
  mon.setCursorPos(1,1)
  mon.write("OUT OF FUEL!!!!")
end

and the reactor computer,

function getRF()
  rF = reactor.getEnergyProducedLastTick()
  connect.transmit(25565, 25565, rF)
end

function getFuel()
  fAmount = reactor.getFuelAmount()
  connect.transmit(25565, 25565, fAmount)
end  

connect = peripheral.wrap("right")
connect.open(25565)
reactor = peripheral.wrap("front")
if reactor.getConnected() == true then 
  connect.transmit(25565,25565,"connected") 
  sleep(1)
end
i = 5
repeat
  getRF()
  getFuel()
  sleep(1)
until i == 0
Posted

I am not really a programmer. But how local is "local"? Is it possible that the local variables within a function are not available outside the function, so you may need to "return" the message, or use a variable local to the script instead of just local to the function. It has been awhile since I did Perl and Python scripting and I am new to lua.

Posted

The word "local" in front of each variable indicates that the variable is specific to that script.  It is just the standard method of creating variables in Lua.

 

Also, could you give us the exact error report that the computer gives you?  Also, does the program run but then crash at a certain point or refuse to run at all?

Posted

It runs until it hits that point. It says:  fuel:22: attempt to concatenate string and nil. The problem was fixed, and then showed up again when I tried making functions out of the code.

Posted

I know that that is supposed to help me in some way, but since there is no context to what you are saying, I have no idea what that link is supposed to do for me. Sorry, but can you please elaborate a bit for me?

Posted (edited)

fuel:22: attempt to concatenate string and nil

As you were not telling us witch script was making this error I looked at both on line 22 ... on is "end" and the other "sleep(1)"

So I assumed that the issue was here, and I was too fast to answer because in fact the link I gave you will not help you at all sorry , my mistake ... 

 

I think the issue stand in the way you concatenate on line 21 though ... but I'm not an expert in lua and I don't really have time for now sorry ....

Furthermore I don't think this is the place to ask as this isn't related directly to tekkit even though you use it in tekkit ^^

 

But for computer craft related question I advice you to maybe Ask A Pro

Edited by M1r077
Posted

The issue is with line 21 of the first script.  The function tries concatenate a string and the variable 'message'.  Since the error says that you're trying to concatenate string and nil, the problem is with this variable.  The variable is created on line 2, in another function.  Herein lies your problem:  Functions can't access each others' variables.  This is a concept called encapsulation (if I remember correctly) and it allows similar functions to share variable names without interfering with each other.  Change the getMessage() function to return the message variable, and use the function as a variable whenever you call it.  This should solve your problem.

Posted (edited)

M1r077, I did try asking basically the same thing in computercraft forums, but since this problem also has to do with reactors, I decided that it might be better to ask this question on a forum with a more general knowledge base. For strictly computercraft questions, I am asking on the computercraft forums, but unfortunately this can be a problem with bigreactors, and the people at CCForums (what I've decided to call it now) might not know that, but the people here might. That might have been a run-on sentence... Thanks for your help though on those sleep() functions. I figured out already that it had to be os.sleep(), it just wasn't giving me any errors on that.

 

Doomzzday01, I'll try that. So I'll have to add a return part to getMessage(), then use it as a variable like message = getMessage()?

 

EDIT: I just added the line

return message

to the function getMessage(), then I used getMessage() to fill a variable like RF for getting RF production, and it worked. Thanks, Doomzzday!

Edited by Dmac9244
Posted

So now I want the Fuel amount to update quickly, but the RF production amount to update not so quickly, like every five seconds or so. Currently, I have under one loop, the functions getRF() and getFuel(). Can I do this?

Posted

It looks like your main loop runs once every second (if that is how long the sleep(1) function runs, I can't remember for sure.  I think so.).  With a few if-then statements, you should be able to get the functions to call at only certain values of i.

repeat
  if i=5 then do function1() end
  function2()
until i==0

You could try it, at least.  You might also try looking into the parallel API on the CC wiki.

Posted (edited)

So... therefore I would just use if statements to change the value of i, then whenever i becomes 9, do function2()? That would work, I think. It would still  do what I want it to do, which is good. Thank you.

 

EDIT: Thank you so much. It worked.

Edited by Dmac9244
Posted

Anytime.  Also, you might try cutting out the second computer and putting in a wired modem instead.  Connect a wired modem on the reactor computer port to a wired (not wireless) modem on the monitor computer, and use the reactor as a peripheral.  Saves you from having to run two computers or deal with wireless communication.

Posted

Anytime.  Also, you might try cutting out the second computer and putting in a wired modem instead.  Connect a wired modem on the reactor computer port to a wired (not wireless) modem on the monitor computer, and use the reactor as a peripheral.  Saves you from having to run two computers or deal with wireless communication.

 

That is what I do with CC computer directly on turbine port (advanced monitor adjacent) to control steam flow to crank a turbine full bore until up to speed (1800 rpm) then control steam flow based on energy cell level on turbine power ports to just produce required power. I use wired modems to reactor computer port to monitor fuel and case temperature (reactor is actually controlled by rednet PRC), to each of 4 energy cells to monitor total stored energy, and redstone output to control tesseract for laser drill once there is enough stored energy to sustain that as turbine winds up. So the turbine winds up to over 20K RF/t until a certain amount of energy storage (50%), kicks on the tesseract, then modulates steam for 20K RF/t (just under that when all cells fully charged or turbine energy buffer begins to fill).

 

I don't think there is any way to use "wireless" modem directly on reactor computer port because there would be no way to set a channel.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...