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

function "touch"

Question

hello,

 

actually i use a "touch" function for my programs, and I would want to deactivate the first touch function and activate a second with a click in a precise zone, then deactivate the second and reactivate the first function with a click in another zone.

 

for the click it isn't a problem, but i don't know to activate and deactivate a function in the current program.

 

for close my program, i use this

event.ignore("touch",onTouch)

and it work normally, but in the middle of the program, this code doesn't work.

 

can you help me ?

Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

this is the complet program :

local term = require("term")
local shell = require("shell") 
local component = require("component")
local computer = require("computer")
local math = require("math")
local event = require("event")
local string = require("string")
local unicode = require("unicode")
local serialisation = require("serialization")
local colors = require("colors")
local sides = require("sides")
local os = require("os") 
--local rs = component.redstone
local gpu = component.gpu
component.gpu.setResolution(100,50)

br = component.getPrimary("br_reactor")
nbrrod = br.getNumberOfControlRods()
local i = 1
local rods = {}
local boucle2 = true

local function setColor(bg,fg)
  gpu.setBackground(bg)
  gpu.setForeground(fg)
end

local function loadbar(x,y,width,cur,text,bg)
  local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
  local oldbg = gpu.setBackground(bg)
  local oldfg = gpu.setForeground(0xFFFFFF - bg)
  gpu.set(x,y,unicode.sub(raw,1,cur))
  gpu.setBackground(oldbg)
  gpu.setForeground(oldfg)
  gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
end 

local function loadbarv(x,y,cur,height,col,text)
  local top = i, y
  local left = height
  for i = left, 0, -1 do
    if i <= cur then
      color = col
    else
      color = 0x0
    end
	j = -i + height + y
    gpu.setBackground(color)
    gpu.set(x,j,text)
    gpu.setBackground(0x0)
  end
end

local function hexa(dec)
local B,K,OUT,I,D = 16,"0123456789ABCDEF","",0
  if dec <= 0 then
    OUT = "00"
  elseif dec > 0 and dec < 16 then
    D = dec + 1
    OUT = "0"..string.sub(K,D,D)
  elseif dec > 16 and dec < 256 then
    V1 = math.modf(dec/B)+1
    V2 = dec-V1*16
    OUT = string.sub(K,V1,V1)..string.sub(K,V2,V2)
  elseif dec >= 255 then
    OUT = "FF"
  end
  return OUT
end

local function round(num, dec)
  local mult = 10 ^ (dec or 0)
  return math.floor(num * mult + 0.5) / mult
end

local function rod(x,y,n)
  lvl = br.getControlRodLevel(n-1)
  rouge = math.floor((100-lvl)*255/50)
  vert = math.floor(lvl*255/50)
  color = hexa(rouge)..hexa(vert).."00"
  color2 = tonumber(string.format("%6s",color),16)
  setColor(color2,0x0000FF)
  gpu.set(x,y,"█"..string.format("%3s",lvl).."█")
  setColor(0x0, 0xFFFFFF)
end

local function aff7rod(x,y)
  c = 6.5*y-25
  rod(x,y,c)
  rod(x+6,y,c+1)
  rod(x+12,y,c+2)
  rod(x+18,y,c+3)
  rod(x+24,y,c+4)
  rod(x+30,y,c+5)
  rod(x+36,y,c+6)
end

local function aff6rod(x,y)
  c = 6.5*y-24.5
  rod(x,y,c)
  rod(x+6,y,c+1)
  rod(x+12,y,c+2)
  rod(x+18,y,c+3)
  rod(x+24,y,c+4)
  rod(x+30,y,c+5)
end

local function control()
aff7rod(8,4)
aff6rod(11,5)
aff7rod(8,6)
aff6rod(11,7)
aff7rod(8,8)
aff6rod(11,9)
aff7rod(8,10)
aff6rod(11,11)
aff7rod(8,12)
aff6rod(11,13)
aff7rod(8,14)
aff6rod(11,15)
aff7rod(8,16)
end

local function manualrod(x,y)
  local rod
  local v1
  local v2
  if y == 4 or y == 6 or y == 8 or y == 10 or y == 12 or y == 14 or y == 16 then
    v1 = (x-4)/6
	v2 = 6.5*y-25
  elseif y == 5 or y == 7 or y == 9 or y == 11 or y == 13 or y == 15 then
    v1 = (x-7)/6
	v2 = 6.5*y-24.5
  end
  rod = round(v1,0)+v2-1
  local a = 81
  local b = 1
    gpu.set(a,b,"╦═════════════════╗")
  gpu.set(a,b+1,"║   Profondeur    ║")
  gpu.set(a,b+2,"╠═════════════════╣") 
  gpu.set(a,b+3,"║ Rod n°XX █100█  ║")
  gpu.set(a,b+4,"║                 ║")
  gpu.set(a,b+5,"║  █-10█   █+10█  ║")
  gpu.set(a,b+6,"║                 ║")
  gpu.set(a,b+7,"║  █-1 █   █+1 █  ║")
  gpu.set(a,b+8,"║                 ║")
  gpu.set(a,b+9,"║ ANNULER VALIDER ║")
 gpu.set(a,b+10,"╚═════════════════╣")
  lvl = br.getControlRodLevel(rod-1)
  gpu.set(a+12,b+3,string.format("%3s",lvl))
  gpu.set(a+8,b+3,string.format("%2s",rod))
  print("1")
  local test =0
  while boucle2 == true do
    test = test + 1
    event.listen("touch",onTouch2)
	gpu.set(a,b+11,string.format("%3s",test))

  end
  event.ignore("touch",onTouch2)
  print("a")
  boucle2 = true
  
    gpu.set(a,b,"══════════════════╗")
  gpu.set(a,b+1,"                  ║")
  gpu.set(a,b+2,"                  ║") 
  gpu.set(a,b+3,"                  ║")
  gpu.set(a,b+4,"                  ║")
  gpu.set(a,b+5,"                  ║")
  gpu.set(a,b+6,"                  ║")
  gpu.set(a,b+7,"                  ║")
  gpu.set(a,b+8,"                  ║")
  gpu.set(a,b+9,"                  ║")
 gpu.set(a,b+10,"                  ║")

end

local function onTouch2(_,_,x,y,_,_)
gpu.set(2,22,"x : "..x.." / y : "..y)
  if x > a+11 and x < a+15 then
    if y == b+5 then
	  lvl = lvl + 10
	elseif y == b+7 then
	  lvl = lvl + 1	  
	end
	
  elseif x > a+3 and x < a+7 then
	if y == b+5 then
	  lvl = lvl - 10
	elseif y == b+7 then
	  lvl = lvl - 1	    
	end
	
  elseif y == b+9 and x > a+1 and x < a+9 then
    boucle2 = false
  elseif y == b+9 and x > a+9 and x < a+17 then
    br.setControlRodLevel(rod-1,lvl)
  end
  gpu.set(a+12,b+3,string.format("%3s",lvl))
	
end

term.clear()
 gpu.set(1,1,"╔══════════════════════════════════════════════════════════════════════════════════════════════════╗")
 gpu.set(1,2,"║                                                                                                  ║")
 gpu.set(1,3,"║   ███████████████████████████████████████████████                                                ║")
 gpu.set(1,4,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
 gpu.set(1,5,"║   ██    █   █ █   █ █   █ █   █ █   █ █   █    ██                                                ║")
 gpu.set(1,6,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
 gpu.set(1,7,"║   ██    █   █ █   █ █   █ █   █ █   █ █   █    ██                                                ║")
 gpu.set(1,8,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
 gpu.set(1,9,"║   ██    █   █ █   █ █   █ █   █ █   █ █   █    ██                                                ║")
gpu.set(1,10,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
gpu.set(1,11,"║   ██    █   █ █   █ █   █ █   █ █   █ █   █    ██                                                ║")
gpu.set(1,12,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
gpu.set(1,13,"║   ██    █   █ █   █ █   █ █   █ █   █ █   █    ██                                                ║")
gpu.set(1,14,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
gpu.set(1,15,"║   ██    █   █ █   █ █   █ █   █ █   █ █   █    ██                                                ║")
gpu.set(1,16,"║   ██ █   █ █   █ █   █ █   █ █   █ █   █ █   █ ██                                                ║")
gpu.set(1,17,"║   ███████████████████████████████████████████████                                                ║")
gpu.set(1,18,"║                                                                                                  ║")
gpu.set(1,19,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
gpu.set(1,20,"║                                                                                                  ║")
gpu.set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
gpu.set(1,22,"║                                                                                                  ║")
gpu.set(1,23,"║                                                                             ╠════════════════════╣")
gpu.set(1,24,"║                                                                             ║                    ║")
gpu.set(1,25,"║                                                                             ║ QUANTITE EN PEPITE ║")
gpu.set(1,26,"║                                                                             ║            pépite  ║")
gpu.set(1,27,"║                                                                             ║                    ║")
gpu.set(1,28,"║                                                                             ╠════════════════════╣")
gpu.set(1,29,"║                                                                             ║                    ║")
gpu.set(1,30,"║                                                                             ║                    ║")
gpu.set(1,31,"║                                                                             ║                    ║")
gpu.set(1,32,"║                                                                             ║                    ║")
gpu.set(1,33,"║                                                                             ║                    ║")
gpu.set(1,34,"║                                                                             ║                    ║")
gpu.set(1,35,"║                                                                             ║                    ║")
gpu.set(1,36,"║                                                                             ║                    ║")
gpu.set(1,37,"╠═════════════════════════════════════════════════════════════════════════════╩════════════════════╣")
gpu.set(1,38,"║                                                                                                  ║")
gpu.set(1,39,"║                                                                                                  ║")
gpu.set(1,40,"║                                                                                                  ║")
gpu.set(1,41,"║                                                                                                  ║")
gpu.set(1,42,"║                                                                                                  ║")
gpu.set(1,43,"║                                                                                                  ║")
gpu.set(1,44,"║                                                                                                  ║")
gpu.set(1,45,"║                                                                                                  ║")
gpu.set(1,46,"║                                                                                                  ║")
gpu.set(1,47,"║                                                                                                  ║")
gpu.set(1,48,"║                                                                                                  ║")
gpu.set(1,49,"║                                                                                                  ║")
gpu.set(1,50,"╚══════════════════════════════════════════════════════════════════════════════════════════════════╝")


local function onTouch(event,adress,x,y,clic,pseudo)
  local tclic
  if clic == 0  then
    tclic = "clic gauche"
  elseif clic == 1 then
    tclic = "Clic droit"
  else
    tclic = "Clic inconnu"
  end
  gpu.set(6,20,tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y))
	if x==1 and y==1 then
      computer.pushSignal("quit")
      term.setCursor(1,1)
      return false
    elseif y > 3 and y < 17 then
	  if x > 7 and x < 49 then
	    manualrod(x,y)
	gpu.set(70,15,x.." / "..y)
	  end
	end
end

local function onTimer(_,timer)
  control()
  return true
end

event.listen("touch",onTouch)
local timer = event.timer(0,onTimer,math.huge)
event.pull("quit")
event.cancel(timer)
event.ignore("touch",onTouch)
component.gpu.setResolution(160,50)
term.clear()
Link to post
Share on other sites
  • 0

You have a few problems in your code:

1. it does not call touch2, remove the "local" from function ontouch2 and see for yourself --> you print test on screen during while loop in manualrod()

2. while loop in manualrod(): if you changed 1. and ran the code you will see that you are stuck in that loop and pc does not react anymore, add os.sleep(1) in there

3. function ontouch2 can't read a,b as they are local in function manualrod, remove the local and it will work (just for debugging)

4. your if in ontouch2 is not good, put the line "elseif y == b+9 and x > a+1 and x < a+9 then" first and it will work how you intended that to work.

Link to post
Share on other sites
  • 0
  • Solution

Thank you.

But i had totaly change the structure, delete ontouch2, and add a if in intouch with "boucle2", now, There is a manual control of one rod, a manual control on all rods, and bargraphs, fuel consumation, température, reactivity, and a start/stop button.

I post the modified program this night after the work. And i think change my program for universal reactor (numbers of rod) and create a regulation program for the Steam flow.

Link to post
Share on other sites
  • 0

Sounds very interesting! Quite useful program if it works.

I don't want to persuade you, but maybe you want to have a look at my GUI-API, it could make some things easier for you. You place objects on the screen and just set the function it should call if you click on that object. You wouldn't need to manually check everything. Maybe just give it it a try and have a look at the tech_demo. If you don't like it or don't want to read into it, that's perfectly fine.

 

How will the program regulate the Steam Flow? Pumping water in externally?

Link to post
Share on other sites
  • 0

Ok i will look this.

The Steam is used in turbine, and if i add a turbine, the flow of Steam must be augment, and i don't want to modify the level rod in manual.

For this program, i've be need to use Z transformation and numeric régulation.

But before i finish m'y program.

Link to post
Share on other sites
  • 0

for example a turbine used 2b/t and produce 28 000 RF/t

 

i use ultimate mechanical pipe (Mekanism) to feed it.

a pipe, it's 6.4b/t.

i use 3 turbines by pipe, and actually i use 12 turbines and 4 output and input on my reactor.

but i don't use 100% of my rods. but if i add just a turbine, i need to produce 2b/t, and change the value off my control rod.

and i don't want to change this value in manual.

 

i propose my programm here in French AND English.

good game

Link to post
Share on other sites
  • 0

I understand. I always use tesseracts for the fluids. make it easier and needs less server ressources  tesseracts are "faster" than pipes.

good luck with your program!

do you want a program that checks energy level of enderio capacitors, sends that level to the reactor-pc and let the reactor-pc decide when to start/stop the reactor? Maybe you can copy some of its features to use it with your program, if that suits your intended usage.

My reactors never run all the time, i have a big energy storage and let the reactor start/stop according to energy level.

BTW: NEVER build "batteries" with MFSUs, Thermal Expansion Energy Cells or Mekanism Energy Cubes, last time i did that it caused massive server and client lags. So if you need a bigger energy storage use Enderio Capacitors (if available on your server).

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.