Greeting,
First of all please forgive my English because I use a translator
And thank you for any help and code optimization
I'm currently playing on the Modpack Project Ozone 3 and unlike 2, the modpack uses Opencomputers instead of Computercraft.
The problem that I currently encounter after countless error display and almost three sleepless nights (I specify that I am not a programmer, any time I tinker a little).
On Project Ozone 2 I used a Direwolf20 program code to manage my Big Reactor with computercraft, naturally I wanted to do the same by posting the code as it was on Opencomputer.
Following the first error encountered, I did some research and I came across some topics of this forum:
- a topic explaining basically the difference between the two mods (in particular on "os.load ()" and "require ()") - link : opencomputers-for-computercraft-users
- a topic about Direwolf20 Computercraft API button code conversion to Opencomputers
After an incalculable error display number (again) I came to understand that instead of "API.button.XXXXXX" it was enough just to replace "button.XXXX" with "API.XXXX"
also little question on the topic of each function code begins with "API.nameFunction" while on my own I just replaced the variable "button.XXXX" with "API.XXXX" and it finally seems to work when removes some line of the code.
function autoMenu()
API.clearTable()
API.setTable("Automatic", autoMode,"",3,13,6,6)
API.setTable("Manual", manualMode,"",15,25,6,6)if steamReactor then
API.setTable("Reactor", reactorMenu,"",5,18,19,19)
API.setTable("Turbine", turbineMenu,"",22,35,19,19)end
API.screen()
checkMode()
menuMode()end
Currently I have the following error that appears /home/br_Reactor.lua:220: bad argument # 1 (string exected, got number):
[C]: in function 'error'
machine: 69: in function 'checkArg'
/home/br_Reactor.lua:220: in function 'comma_value'
/home/br_Reactor.lua:241: in function 'displayEn'
/home/br_Reactor.lua:429: in function 'findOutFuelRods'
/home/br_reactor.lua:617: in main chunk
(... tail calls ...)
[C]: in function 'xpcall'
machine: 791: in function'xpcall '
/lib/process.lua:63: in function </lib/process.lua:59>
And when I delete lines "trm.write(comma_value(XXXXXXXXXX).. "XXXXXXX")" the code seems to work but with some bug like:
- The display is done in two colors (gray and white)
- The program displays a turbine error in the absence of it, on computeurcraft I just use the reactor or combi reactor / turbine it works
- The buttons are not touch
- the control of the rods does not seem to control the rods
can you help me please and if so how to otpimize the code
buttonAPI.lua
local API ={}local button ={}local component = require("component")-- On appelle l'API "component"local term = require("term")-- On appelle l'API "term"local colors = require("colors")-- On appelle l'API "colors"local mon = component.gpu
local trm = term
function API.clear()
mon.setBackground(colors.black,true)
mon.fill(1,1, w, h," ")endfunction API.clearTable()
button ={}
term.clear()endfunction API.setButton(name, buttonOn)
print(name)
print(button[name]["active"])
button[name]["active"]= buttonOn
API.screen()endfunction API.setTable(name, func, param, xmin, xmax, ymin, ymax)
button[name]={}
button[name]["func"]= func
button[name]["active"]=false
button[name]["param"]= param
button[name]["xmin"]= xmin
button[name]["ymin"]= ymin
button[name]["xmax"]= xmax
button[name]["ymax"]= ymax
end-- function API.fill(text, color, bData)-- mon.setBackground(color, true)-- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)-- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1-- for j = bData["ymin"], bData["ymax"] do-- trm.setCursor(bData["xmin"], j)-- if j == yspot then-- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do-- if k == xspot then-- trm.write(text)-- else-- trm.write(" ")-- end-- end-- else-- for i = bData["xmin"], bData["xmax"] do-- trm.write(" ")-- end-- end-- end-- mon.setBackground(colors.black)-- endfunction API.fill(text, color, bData)-- ## this part works just finelocal yspot = math.floor((bData["ymin"]+ bData["ymax"])/2)local xspot = math.floor((bData["xmax"]+ bData["xmin"]- string.len(text))/2)+1-- ## save any previous color used before, not just blacklocal oldColor = mon.setBackground(color,true)-- ## gpu.fill(x,y,width,height,char) char here = " " for a blank space of color
mon.fill(bData["xmin"], bData["ymin"],(bData["xmax"]-bData["xmin"]+1),(bData["ymax"]-bData["ymin"]+1)," ")-- ## write your text here from the gpu.set function instead of io.
mon.set(xspot, yspot, text)-- ## reset the old color
mon.setBackground(oldColor)endfunction API.screen()local currColor
for name,data in pairs(button)dolocal on = data["active"]if on ==truethen
currColor = colors.lime
else
currColor = colors.red
end
API.fill(name, currColor, data)endendfunction API.toggleButton(name)
button[name]["active"]=not button[name]["active"]
API.screen()endfunction API.flash(name)
API.toggleButton(name)
API.screen()
os.sleep(0.15)
API.toggleButton(name)
API.screen()endfunction API.checkxy(x, y)for name, data in pairs(button)doif y>=data["ymin"]and y <= data["ymax"]thenif x>=data["xmin"]and x<= data["xmax"]thenif data["param"]==""then
data["func"]()else
data["func"](data["param"])endreturntrue--data["active"] = not data["active"]--print(name)endendendreturnfalseendfunction API.heading(text)
w, h = mon.getResolution()
trm.setCursor((w-string.len(text))/2+1,1)
trm.write(text)endfunction API.label(w, h, text)
trm.setCursor(w, h)
trm.write(text)endreturn API
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.
Greeting,
First of all please forgive my English because I use a translator
And thank you for any help and code optimization
I'm currently playing on the Modpack Project Ozone 3 and unlike 2, the modpack uses Opencomputers instead of Computercraft.
The problem that I currently encounter after countless error display and almost three sleepless nights (I specify that I am not a programmer, any time I tinker a little).
On Project Ozone 2 I used a Direwolf20 program code to manage my Big Reactor with computercraft, naturally I wanted to do the same by posting the code as it was on Opencomputer.
Following the first error encountered, I did some research and I came across some topics of this forum:
- a topic explaining basically the difference between the two mods (in particular on "os.load ()" and "require ()") - link : opencomputers-for-computercraft-users
- a topic about Direwolf20 Computercraft API button code conversion to Opencomputers
After an incalculable error display number (again) I came to understand that instead of "API.button.XXXXXX" it was enough just to replace "button.XXXX" with "API.XXXX"
Exemple code topic :
Exemple my code :
API.button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
also little question on the topic of each function code begins with "API.nameFunction" while on my own I just replaced the variable "button.XXXX" with "API.XXXX" and it finally seems to work when removes some line of the code.
Exemple code topic :
Exemple original code program :
Currently I have the following error that appears
/home/br_Reactor.lua:220: bad argument # 1 (string exected, got number):
[C]: in function 'error'
machine: 69: in function 'checkArg'
/home/br_Reactor.lua:220: in function 'comma_value'
/home/br_Reactor.lua:241: in function 'displayEn'
/home/br_Reactor.lua:429: in function 'findOutFuelRods'
/home/br_reactor.lua:617: in main chunk
(... tail calls ...)
[C]: in function 'xpcall'
machine: 791: in function'xpcall '
/lib/process.lua:63: in function </lib/process.lua:59>
And when I delete lines "trm.write(comma_value(XXXXXXXXXX).. "XXXXXXX")" the code seems to work but with some bug like:
- The display is done in two colors (gray and white)
- The program displays a turbine error in the absence of it, on computeurcraft I just use the reactor or combi reactor / turbine it works
- The buttons are not touch
- the control of the rods does not seem to control the rods
can you help me please and if so how to otpimize the code
buttonAPI.lua
br_Reactor.lua
Link to post
Share on other sites