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

Config Problem

Started by Kadecamz, 12 September 2012 - 07:00 PM
Kadecamz #1
Posted 12 September 2012 - 09:00 PM

term.clear()
while true do
if key == "x" then
print("hi")

I am trying to find out how to do something if the user presses a certain key, can someone please tell me how?


The above is solved, but now my question is how do I raise my rednet range in the config above the default, because when I try it always resets. :)/>/>

CC: 1.4.1
Forge: 3.4.9.171
MysticT #2
Posted 12 September 2012 - 09:06 PM
To get key presses you need to wait for a "key" event, using os.pullEvent.
Example:

while true do
  local evt, key = os.pullEvent() -- wait for an event
  if evt == "key" then -- check if the event is a key press
    print("Key pressed: ", key) -- print the pressed key
  end
end

If you only want key events you can use:

while true do
  local evt, key = os.pullEvent("key") -- wait for a key press event
  print("Key pressed: ", key) -- print the pressed key
end
Kadecamz #3
Posted 12 September 2012 - 09:29 PM
But how do you make it only work for a certain key?
Lettuce #4
Posted 12 September 2012 - 09:29 PM
In this case, MysticT has given you the better, if a bit more complicated, choice. But when I see an opportunity to give someone a quick pro-tip, I do. If you want something a bit more complex than "press x to do y" I prefer io.read(). Type your input, press enter. For instance, to set x (a number) as a user's input I do:

x = io.read()
x = tonumber(x)

That can be shortened to one line, but it is easier to read for a beginner as two lines. Or if you want it to take a command:

x = io.read()
if x = "dosomething" then
--stuff
end

There. I think that covers both ways to take a user's input. Again, for your sample program, MysticT's is the better choice.
Kadecamz #5
Posted 12 September 2012 - 09:31 PM
I know exactly how to do that.
But for key PRESSING, not entering a code.
Kilobyte #6
Posted 12 September 2012 - 09:35 PM

while true do
  e, key = os.pullEvent("key")
  if key == <keyid> then
	-- do stuff here
  end
end
Lettuce #7
Posted 12 September 2012 - 09:36 PM
Very well. To answer your question that you posted 3 seconds before I gave you a tip, you just use:

param1 = os.pullEvent("char") --or "key"
if param1 == "x" then
--do stuff
end

Sorry for giving you that tip, didn't mean to make you mad, it's just the alternative, and is one of my favorite API's.
Cranium #8
Posted 12 September 2012 - 09:36 PM
But how do you make it only work for a certain key?
You can get a list of keys here. All you would need to do is this:

local event, p1 = os.pullEvent("key")
if p1 == #ofkeyhere then
--do stuff here
elseif p1 == #ofotherkeythen
--do other stuff here
end
Just a quick tip, if you have the os.pullEvent in there, it waits indefinitely for an event to occur. This is ideal for menu systems and navigation.
Kadecamz #9
Posted 12 September 2012 - 09:37 PM
Its ok.
Kadecamz #10
Posted 12 September 2012 - 09:38 PM
Alright, and not to spam AAP
How do I raise my rednet range above 64 in the config?
If I raise it over 64 the config file always resets.
MysticT #11
Posted 12 September 2012 - 10:07 PM
Alright, and not to spam AAP
How do I raise my rednet range above 64 in the config?
If I raise it over 64 the config file always resets.
What version of CC and forge are you using?
Kadecamz #12
Posted 12 September 2012 - 10:19 PM
CC is 1.4.1
v3.4.9.171
Kadecamz #13
Posted 13 September 2012 - 12:22 AM
Bump.
Cranium #14
Posted 13 September 2012 - 12:34 AM
Please don't bump your own thread. This is not neccessary, and will not get your question answered any faster. Almost everyone here who answers questions does so at their own time(which is not usually in the same time zone), and generally they read all unanswered posts here. The rest of the pros will get to your question in time. Please be patient, and don't spam posts.
Lettuce #15
Posted 13 September 2012 - 03:18 AM
To start: What are you doing? To configure modem range, you go to (relative path) .minecraft/config/mod_ComputerCraft.cfg Then you go into it, I believe you might have to set it to open cfg files with notepad, since it may not recognize the extension. Then you scroll down to modem_range=64 and change it to the setting you want. Then hit File>Save. Tell us exactly what you did, in detail, and if we see a flaw in the way you handled it, we'll try to help you.

Also, about the timezone thing, I'm in Ohio, it's 10pm EST. Cranium up there is a few hours behind me, methinks, and you are probably somewhere completely different, we are all around the world. Trust me, we all love to help people on these forums, and will whenever we can. Some of us get on here just to help people on Ask a Pro. It will get answered eventually, if I haven't answered it already. Also, Cranium, you forgot to change your name in your signature, which I doubt you noticed.
Cranium #16
Posted 13 September 2012 - 03:59 AM
Lol, yeah. Fixed.
Kadecamz #17
Posted 13 September 2012 - 04:01 AM
@Lettuce
I'm in ohio too.
And I did EXACTLY that dude. -.-
I set it to 9999999999999999999999999999999999999, and saved.
But it just reset.
Lettuce #18
Posted 13 September 2012 - 04:39 AM
Honestly, I never changed my modem range, I never saw a reason to. There might be a maximum you are exceeding, and it resets. Try something more reasonable, like 5,000 and see how that goes. 5,000 should be sufficient, no?
Kadecamz #19
Posted 13 September 2012 - 05:05 AM
I tried 900 and it STILL reset.
Kadecamz #20
Posted 13 September 2012 - 05:07 AM
2012-09-13 00:06:41 [WARNING] Configuration for mod_ComputerCraft.enableAPI_http found value 0 outside acceptable range 4.9E-324,1.7976931348623157E308

I get that in my multimc console.
Lettuce #21
Posted 13 September 2012 - 05:41 AM
Well, apparently you have the http API enabled, and you set it to two or something. Make sure it's 1 or 0. That may well be your problem. ALSO: This may be your problem: there is no space before/after '=' on either.