Posted 16 March 2016 - 08:52 PM
So ive been working on making a program that just has some basic tools like copy files to a disk, getting a pastebin file and im trying to add a games function so you can launch different games from the program. Im trying to make it so when you click the "Games" button it shows you buttons with different game names, i.e. "Tron" my problem right now is that the function tronGame is never being called in the gameFunc function. This is my first semi major project ive worked on CC and one of few attempts at useing CC. Any help would be much appreciated and if you could give a kinda in depth explanation on how to fix this so I can learn by it that would be great! Also I cant figure out how to run a program from inside a function for example, when I try to do "shell.run(filename)" from inside one of the functions in this program it doesn't do anything and juts goes back to the starting screen.
Here's the Pastebin URL
Heres the code it self:
Here's the Pastebin URL
Heres the code it self:
--JDA Tools GUI By: JdogAwesome
os.unloadAPI("gui")
os.loadAPI("gui")
local disk = "disk2" --Replace "disk2" with whatever your disk is called when you type in "dir"
function waitMouse()
while true do
ev,mb,x,y = os.pullEvent("mouse_click")
if (mb == 1 and gui.detect(x,y, false) ~= nil) then
return gui.detect(x,y, false)
end
end
end
function gamesFunc()
term.setBackgroundColor(colors.black)
term.clear()
--term.setCursorPos(10,10)
tronButton = gui.createButton("Tron", tronGame)
tronButton:draw(18, 3, 3, colors.blue, colors.black)
clicked2 = waitMouse()
if clicked2 == "Tron" then
print("If == tron then tron game statement")
tronGame()
end
sleep(1)
end
function tronGame()
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(10,10)
print("Hello tronGame")
shell.run("Tron")
end
function pastebinGet()
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(10,10)
print("What you want to name the file:")
local filename = gui.newTextBox(15,13,20, colors.red, colors.black)
term.setCursorPos(10,15)
print("Pastebin URL thing, example: KwJ87j7A")
local pastebinUrl = gui.newTextBox(15,16,20, colors.red, colors.black)
shell.run("pastebin get ",pastebinUrl, filename)
sleep(2)
end
function diskCopy()
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(10,10)
print("Name of file to copy to disk: ")
local userinput = gui.newTextBox(15,16,20, colors.white, colors.black)
shell.run("cp",userinput, disk)
sleep(3)
end
function exitProgram()
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
term.setCursorPos(1,1)
term.clear()
error()
end
function main()
term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1,1)
local firstButton = gui.createButton("Pastebin Get ", pastebinGet)
local secondButton = gui.createButton("Disk Copy", diskCopy)
local exitButton = gui.createButton("Exit", exitProgram)
local gamesButton = gui.createButton("Games", gamesFunc)
firstButton:draw(18, 3, 3, colors.red, colors.white)
secondButton:draw(20, 9, 3, colors.orange, colors.white)
exitButton:draw(2, 1, 3, colors.red, colors.black)
gamesButton:draw(20, 15, 3, colors.green, colors.white)
clicked = waitMouse()
if clicked == "Pastebin Get " then
pastebinGet()
elseif clicked == "Disk Copy" then
diskCopy()
elseif clicked == "Exit" then
exitProgram()
elseif clicked == "Games" then
gamesFunc()
--elseif clicked == "Tron" then
--tronGame()
end
end
while true do
main()
end
--Base code credits:
--https://www.youtube.com/watch?v=-oXDm92KZRc
--http://www.computercraft.info/forums2/index.php?/topic/18977-guiapi-simple-powerful-buttonsdialogue-boxes-text-boxes-and-more/
Edited on 16 March 2016 - 10:09 PM