os.pullEvent("monitor_touch")
3 participants
Page 1 sur 1
os.pullEvent("monitor_touch")
Bonjour,
je ne fait pas partit du serveur computercraft.fr mais j'ai quand meme besoin de votre aide
j'utilise big reactors et j'éssait de créer un programme de gestion de mon réacteur...
probleme : voici mon code
au if os.pullEvent("monitor_touch") then
je ne peut pas récupérer les coordonnées du monitor_touch...
si qqun peut m'aider sa serais vraiment cool
je ne fait pas partit du serveur computercraft.fr mais j'ai quand meme besoin de votre aide
j'utilise big reactors et j'éssait de créer un programme de gestion de mon réacteur...
probleme : voici mon code
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
while true do
if os.pullEvent("monitor_touch") then
m.write("yo")
end
end
au if os.pullEvent("monitor_touch") then
je ne peut pas récupérer les coordonnées du monitor_touch...
si qqun peut m'aider sa serais vraiment cool
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
Essaye plutôt :
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
while true do
-- Je mets les coordonées dans clickX et clickY
event, monitorName, clickX, clickY = os.pullEvent("monitor_touch")
m.write("yo")
end
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Re: os.pullEvent("monitor_touch")
c'est ce que j'ai essayé juste avant...
mais le problème est que la suite du programmes ne s'execute pas car il att un pullEvent...
car il y'a d'autres fonctions qui doivent êtres mises dans le programme
mais le problème est que la suite du programmes ne s'execute pas car il att un pullEvent...
car il y'a d'autres fonctions qui doivent êtres mises dans le programme
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
Fait des fonctions et utilise l'API parallel :
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
function clickHandler()
while true do
-- Je mets les coordonées dans clickX et clickY
event, monitorName, clickX, clickY = os.pullEvent("monitor_touch")
m.write("yo")
end
end
function autreChose()
while true do
--Je fais autre chose en même temps
end
end
parallel.waitForAny(clickHandler, autreChose)
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Re: os.pullEvent("monitor_touch")
arc13 a écrit:Fait des fonctions et utilise l'API parallel :
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
function clickHandler()
while true do
-- Je mets les coordonées dans clickX et clickY
event, monitorName, clickX, clickY = os.pullEvent("monitor_touch")
m.write("yo")
end
end
function autreChose()
while true do
--Je fais autre chose en même temps
end
end
parallel.waitForAny(clickHandler, autreChose)
merci je n'ai jamais utiliser cette api...
je vais check le wiki tu connais un bon tutoriel
sinon merci
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
Tu peut aller voir la vidéo de cedmeu à ce sujet :
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Re: os.pullEvent("monitor_touch")
merci beacoup j'ai refait mon code et... il y'a encore un problème voici le code:
au run (monitor right mono) ce programme affiche le hud correctement mais apprer quelques secondes, celui ci m'affiche un message d'erreur...
http://puu.sh/qCida/64dca7b1c3.png
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
function mo_touch()
while true do
event, side, xpos, ypos = os.pullEvent("monitor_touch")
if xpos == 3 or xpos == 4 and ypos == 2 then
r.setActive(true)
elseif xpos == 45 or xpos == 46 and ypos == 2 then
r.setActive(false)
end
end
end
function test_r()
while true do
if r.getActive() then
m.setBackgroundColor(colors.green)
m.setCursorPos(4,4)
m.write("On")
elseif r.getActive() == false then
m.setBackgroundColor(colors.red)
m.setCursorPos(4,4)
m.write("off")
end
end
end
function hud()
paintutils.drawImage(image, 1, 1)
end
while true do
parallel.waitForAny(hud(),test_r(),mo_touch())
os.sleep(0.5)
end
au run (monitor right mono) ce programme affiche le hud correctement mais apprer quelques secondes, celui ci m'affiche un message d'erreur...
http://puu.sh/qCida/64dca7b1c3.png
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
Je pense que mettre un sleep réglerait le problème :
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
function mo_touch()
while true do
event, side, xpos, ypos = os.pullEvent("monitor_touch")
if xpos == 3 or xpos == 4 and ypos == 2 then
r.setActive(true)
elseif xpos == 45 or xpos == 46 and ypos == 2 then
r.setActive(false)
end
end
end
function test_r()
while true do
if r.getActive() then
m.setBackgroundColor(colors.green)
m.setCursorPos(4,4)
m.write("On")
elseif r.getActive() == false then
m.setBackgroundColor(colors.red)
m.setCursorPos(4,4)
m.write("off")
end
-- Ici, pour que le programme souffle un peu
os.sleep(0.1)
end
end
function hud()
paintutils.drawImage(image, 1, 1)
end
while true do
parallel.waitForAny(hud(),test_r(),mo_touch())
os.sleep(0.5)
end
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Re: os.pullEvent("monitor_touch")
c'est cool sa ne crash plus mais maintenant je n'arrive pas a presser sur les boutons.. :'(
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
Tu pourrais essayer ça, je pense que ça devrait marcher :
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
function mo_touch()
while true do
event, side, xpos, ypos = os.pullEvent("monitor_touch")
if xpos == 3 or xpos == 4 and ypos == 2 then
r.setActive(true)
elseif xpos == 45 or xpos == 46 and ypos == 2 then
r.setActive(false)
end
end
end
function test_r()
while true do
if r.getActive() then
m.setBackgroundColor(colors.green)
m.setCursorPos(4,4)
m.write("On")
elseif r.getActive() == false then
m.setBackgroundColor(colors.red)
m.setCursorPos(4,4)
m.write("off")
end
os.sleep(0.1)
end
end
function hud()
paintutils.drawImage(image, 1, 1)
end
hud()
parallel.waitForAny(test_r, mo_touch)
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Re: os.pullEvent("monitor_touch")
super cool mais il n'y a plus de m.clear() ce qui donne sa (dernier problème je crois )
:
http://puu.sh/qCjbh/ae5706e764.png
:
http://puu.sh/qCjbh/ae5706e764.png
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
Ouais c'est normal, tant que tu écris pas sur un caractère il reste, dans ton cas un simple paintutils.drawPixel fera l'affaire :
- Code:
m = peripheral.wrap("right")
r = peripheral.wrap("back")
image = paintutils.loadImage("hud")
m.setBackgroundColor(colors.black)
m.clear()
paintutils.drawImage(image,1,1)
function mo_touch()
while true do
event, side, xpos, ypos = os.pullEvent("monitor_touch")
if xpos == 3 or xpos == 4 and ypos == 2 then
r.setActive(true)
elseif xpos == 45 or xpos == 46 and ypos == 2 then
r.setActive(false)
end
end
end
function test_r()
while true do
if r.getActive() then
m.setBackgroundColor(colors.green)
m.setCursorPos(4,4)
m.write("On")
paintutils.drawPixel(6, 4, colors.black)
elseif r.getActive() == false then
m.setBackgroundColor(colors.red)
m.setCursorPos(4,4)
m.write("off")
end
os.sleep(0.1)
end
end
function hud()
paintutils.drawImage(image, 1, 1)
end
hud()
parallel.waitForAny(test_r, mo_touch)
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Kuruyia- Messages : 83
Date d'inscription : 10/04/2016
Age : 23
Localisation : Glitch City
Re: os.pullEvent("monitor_touch")
Un petit partage du programme terminé serait sympa pour la communauté de ComputerCraft
Re: os.pullEvent("monitor_touch")
cedmeu a écrit:Un petit partage du programme terminé serait sympa pour la communauté de ComputerCraft
oui effectivement je le poste dés que possible
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Re: os.pullEvent("monitor_touch")
http://pastebin.com/cPzn7vS0
Tonitch8- Messages : 2
Date d'inscription : 30/03/2016
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum