This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DeclipZ's profile picture

Have a problem (window:57: Expected number)

Started by DeclipZ, 31 March 2015 - 10:48 AM
DeclipZ #1
Posted 31 March 2015 - 12:48 PM
Hi everyone! Sorry for my bad english, it's not my main language. So, I've got a problem, I wanna make a API and program, what use this API, but when I start it, they are going to crash, help me please.
This is API:

This is a program:



MKlegoman357 #2
Posted 31 March 2015 - 04:16 PM
After you load an API you access it through the APIs file name, in your case it's Color. So you'd use Color.CBlack, Color.CGray, etc..
DeclipZ #3
Posted 31 March 2015 - 04:54 PM
After you load an API you access it through the APIs file name, in your case it's Color. So you'd use Color.CBlack, Color.CGray, etc..
It's work! Thank you ;)/>

P.S. I forget about my question.
How can I do autostart program? For example: I powered-on my computer and started program for authorization.
Edited on 31 March 2015 - 03:20 PM
Dragon53535 #4
Posted 31 March 2015 - 05:37 PM
create a file named startup, and then inside that have shell.run("yourfilehere")

Or just rename your file to startup, either way
Edited on 31 March 2015 - 03:37 PM
DeclipZ #5
Posted 31 March 2015 - 05:55 PM
create a file named startup, and then inside that have shell.run("yourfilehere")

Or just rename your file to startup, either way
Ok, it's clear, thank you. And I have another problem :D/>
If a press CTRL+T program will be closed, how can I denied it?
Konlab #6
Posted 31 March 2015 - 06:49 PM
#1
use shell.run instead of os.loadAPI if you want to use them as you used in the posted pictures (CBlack and not Color.CBlack)
KingofGamesYami #7
Posted 31 March 2015 - 06:59 PM
Put this at the top of your script:

os.pullEvent = os.pullEventRaw

It'll prevent control+T, but will not prevent control+R or control+S.
MKlegoman357 #8
Posted 31 March 2015 - 07:41 PM
While KingofGamesYami's solution works, it will disable CTRL-T in all programs. You should save the original 'os.pullEvent' and restore it whenever your program exits:


--# save the original os.pullEvent
local old_os_pullEvent = os.pullEvent

--# override it to disable termination
os.pullEvent = os.pullEventRaw

--# your main program's code goes here
...

--# put this wherever the program exits to allow termination in other programs
os.pullEvent = old_os_pullEvent
DeclipZ #9
Posted 31 March 2015 - 08:41 PM
Thank you for your helping! If you so kindness can you help me again? :)/>
I have a code:

local function gui()
  for i=1,4 do
    if i == Selector then
	  term.setTextColor(Color.Red)
	  write(">")
    end
  term.setTextColor(Color.White)
  print(Menu[i])
  end
end
gui()

while true do
  local scancode = os.pullEvent("key")
  if scancode == 200 then
    Selector = Selector-1
    if Selector<1 then Selector = 1 end
    gui()
  elseif scancode == 208 then
    Selector = Selector+1
    if Selector>4 then Selector=4 end
    gui()
  elseif scancode == 28 and Selector == 4 then
    break
  end
end

When I press Arrow Up or Down nothing is go on. What is wrong?
Edited on 31 March 2015 - 06:42 PM
Bomb Bloke #10
Posted 31 March 2015 - 09:19 PM
os.pullEvent() returns an event type followed by its parameters. You want something like:

local event, scancode = os.pullEvent("key")

Don't forget the keys API! This allows you to make your code much more readable, eg:

if scancode == keys.up then
MKlegoman357 #11
Posted 31 March 2015 - 09:20 PM
That's because os.pullEvent always returns the event as its first parameter. The second parameter would be the key code. You can also use the keys table to lookup keys


local event, key = os.pullEvent("key")

if key == keys.up then --# up arrow button was pressed
  ...
elseif key == keys.down then --# down arrow button was pressed
  ...
end