233 posts
Location
Cleveland, Ohio
Posted 01 April 2013 - 08:23 AM
in this tutorial, i will show you
- how to use it
- How We use it in computercraft
- why we should use it
1. How to use itThink of the keyboard as a array of numbers. when you press a key, it sends an ID to the computer and the computer turns it into what it is.
If you press the up arrow key, it will send the id 200 to your computer. your computer takes the 208, and says "hey, 208 is the down arrow key!" and act accordingly
2. How we use it in Computercraftcomputercraft uses keyboard ids almost like a computer (shocker). to use it you must do this
1. pull the event
2. wait for the event
3.act how you tell it
a simple door code that will open when you press "spacebar"
while true do --infinite loop
event = {os.pullEvent()} --pulls the all events
if event[1] == "key" then --will wait for you to press do a event. it will then test the event if you press a key. if you press a key,it moves on in the code
if event[2] == 57 then --if the key you pressed is 57, then it continue the code
rs.setOutput("left", true) --opens the door on the left
sleep(2) --waits 2 seconds
rs.setOutput("left", false) -- closes the door
end
end
end -- ends the program
3. why we should use itwhy should we use it? well, it is preference but normally
a program will run smother if you dont have to type your thing, then press enterThose are the basics of key eventsHappy Coding!
318 posts
Location
Somewhere on the planet called earth
Posted 01 April 2013 - 08:29 AM
"If you press the up arrow key, it will send the id 200 to your computer. your computer takes the 208, and says "hey, 208 is the down arrow key!" and act accordingly."
I belive you have a type in there. You start off with key id 200, but end with 208 :P/>
131 posts
Location
I am omnipresent... DUH
Posted 01 April 2013 - 11:14 AM
You should add something on the keys API in this
1214 posts
Location
The Sammich Kingdom
Posted 01 April 2013 - 11:20 AM
How is this useful at all?
233 posts
Location
Cleveland, Ohio
Posted 01 April 2013 - 03:46 PM
How is this useful at all?
for people new to the way computercraft works
7508 posts
Location
Australia
Posted 01 April 2013 - 03:52 PM
You should add something on the keys API in this
Keys API should be mentioned…… but not replace, as the keys api was only added in 1.4 iirc… so most Tekkit players don't have the api :P/>
2217 posts
Location
3232235883
Posted 04 April 2013 - 07:02 AM
most tekkit players wont be able to run alot of programs, because 70% of programs use the function term.isColor
7508 posts
Location
Australia
Posted 04 April 2013 - 05:42 PM
most tekkit players wont be able to run alot of programs, because 70% of programs use the function term.isColor
Most I've seen use the
if term.isColor and term.isColor() then
I myself lately have become lazy and if I'm changing the colour just once or twice just do this
pcall( term.setTextColor, colors.blue )
392 posts
Location
Christchurch, New Zealand
Posted 04 April 2013 - 06:03 PM
I always initialize variables at the top of my program to prevent this
term.isColor = term.isColor or function() return false end
term.setTextColor = term.setTextColor or function() end
.. etc
Fixes all issues
1619 posts
Posted 04 April 2013 - 06:24 PM
I always initialize variables at the top of my program to prevent this
term.isColor = term.isColor or function() return false end
term.setTextColor = term.setTextColor or function() end
.. etc
Fixes all issues
Except for term.setBackgroundColor() :P/>
392 posts
Location
Christchurch, New Zealand
Posted 04 April 2013 - 06:39 PM
That was the etc, smart-arse :P/>
3 posts
Posted 22 April 2013 - 02:10 AM
This looks really usefull to a noob like me and plus it shows all the Keys ID
6 posts
Location
In a Superflat world making turtles play games.
Posted 24 April 2013 - 12:43 PM
I thought you could just use the letters…like using:
local event,param1 = os.pullEvent ("char")
and then use param1 as the variable(or string…..still learning the language) for the key,which can return as whatever button you press.
It uses this on the wiki:
http://computercraft.info/wiki/Os.pullEventUnless that does something different,and i missed it.
1190 posts
Location
RHIT
Posted 24 April 2013 - 12:53 PM
I thought you could just use the letters…like using:
local event,param1 = os.pullEvent ("char")
and then use param1 as the variable(or string…..still learning the language) for the key,which can return as whatever button you press.
It uses this on the wiki:
http://computercraft...ki/Os.pullEventUnless that does something different,and i missed it.
Essentially, two events ("char" and "key") are thrown on key presses so long as the key pressed is an actual character. But if it's a key such as ctrl, there is no char event thrown.