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

General Program Troubleshooting and questions

Started by hunter239833, 26 March 2014 - 12:33 AM
hunter239833 #1
Posted 26 March 2014 - 01:33 AM
hi! im working on a project that is on a scale that ive never attempted before, and while it may not seem like very much to some of you, it is to me, so i would appreciate if i could post my questions and troubles in one big post so i dont spam "ask a pro" with small posts. my project is to hook up just about everything in my base to an openp terminal bridge so i can access everything in my base from anywhere in the world. you may have seen my post on here a while ago about a open blocks radio controller, and the success of that has inspired me, so here is my first question; would it be smarter in the long run to have my systems connected to the bridge through a wired modem network and just have them sort out the events they dont need? or would it perhaps be smarter to have a computer with a wireless modem that routes all the commands to different computers also on wireless modems?
theoriginalbit #2
Posted 26 March 2014 - 01:47 AM
definitely wired networks, its definitely more efficient in terms of server resources, its much more scalable, and its easier to implement :)/>
hunter239833 #3
Posted 26 March 2014 - 01:49 AM
thanks, thats what i thought, and if i need to later on, i can always stick a computer with a wireless modem on the bridge later on if i need far away computers to be accessible too
theoriginalbit #4
Posted 26 March 2014 - 01:52 AM
yeah, I'd be more inclined to add it to the original computer, but yeah.
hunter239833 #5
Posted 26 March 2014 - 02:38 AM
is it possible to have a range of numbers instead of an exact number when comparing? something like

if var == 1-10 then
  print("Hello World")
end
instead of

if var == 1,2,3,4,5,6,7,8,9,10 then
  print("hello World")
end
Edited on 26 March 2014 - 01:40 AM
Lyqyd #6
Posted 26 March 2014 - 02:43 AM
You can use inequalities:


if var >= 1 and var <= 10 then
hunter239833 #7
Posted 26 March 2014 - 02:45 AM
thanks, would this also include decimals?
theoriginalbit #8
Posted 26 March 2014 - 02:50 AM
of course


if var >= 3.1 and var <= 3.15 then
  print"it might be pi!"
end
hunter239833 #9
Posted 26 March 2014 - 04:12 AM
ok, im having some more trouble with tables, for some reason this works perfectly:

scan = peripheral.wrap("top")
bridge = peripheral.wrap("down")
m = peripheral.wrap("left")
local arg = {...}
if not arg[1] then
  for data, info in pairs(scan.getPlayerData("hunter239833")) do
	print(data)
	print(info)
	os.pullEvent()
  end
end
playerData = scan.getPlayerData("hunter239833")
if arg[1] and not arg[2] then
  for data, info in pairs(playerData[arg[1]]) do
	print(data)
	print(info)
	os.pullEvent()
  end
end
playerData2 = playerData[arg[1]]
if arg[2] then
  for data, info in pairs(playerData2[arg[2]]) do
	print(data)
	print(info)
	os.pullEvent()
  end
end

but this just returns" attempted to index nil" at line 5

scan = peripheral.wrap("top")
bridge = peripheral.wrap("bottom")
playerData = scan.getPlayerData("hunter239833")
playerData2 = playerData[armor]
boots = playerData2[boots]
here is a list of everything in "armor" that i got from using the first program i showed https://www.dropbox....26_00.10.09.png
sorry for dropbox link, it was the only thing i could think of that i could use quickly
edit: broken link
Edited on 26 March 2014 - 03:13 AM
theoriginalbit #10
Posted 26 March 2014 - 04:14 AM
ok, im having some more trouble with tables, for some reason this works perfectly:

playerData2 = playerData[armor]
boots = playerData2[boots]
this is because its looking for the value of the armor variable, which doesn't exist, you meant to use either of these

playerData2 = playerData["armor"]
boots = playerData2["boots"]
or


playerData2 = playerData.armor
boots = playerData2.boots
hunter239833 #11
Posted 26 March 2014 - 04:25 AM
ok, im having some more trouble with tables, for some reason this works perfectly:

playerData2 = playerData[armor]
boots = playerData2[boots]
this is because its looking for the value of the armor variable, which doesn't exist, you meant to use either of these

playerData2 = playerData["armor"]
boots = playerData2["boots"]
or


playerData2 = playerData.armor
boots = playerData2.boots
this worked, though it confuses me, i wan under the impression that you pulled something out of a table by using something like table[key]
theoriginalbit #12
Posted 26 March 2014 - 04:37 AM
this worked, though it confuses me, i wan under the impression that you pulled something out of a table by using something like table[key]
yes you do, however that syntax would require a variable named `key`


local foo = { bar = 1 }

--# this only works with strings that have no spaces, you cannot do numbers
print( foo.bar )

--# this works with any data type, you can do foo[1], or foo[true], or foo[{}], etc. strings with spaces must be this way (or the way below) foo["hello world"]
print( foo["bar"] )

--# functionally this is the same as above, except the key is in a variable
local key = "bar"
print( foo[key] )
hunter239833 #13
Posted 26 March 2014 - 04:47 AM
ok, im going to bed now, so im just going to leave this here and check tis tomorrow after school.
i undrstand now,
this is going to be a part of the network im making, but for now its just a proof of concept
it checks if im looking at the the computer (everytime i run the player info checker im looking at the computer obviously so i just used it)

scan = peripheral.wrap("top")
bridge = peripheral.wrap("bottom")
while true do
  playerData = scan.getPlayerData("hunter239833")
  lookingAt = playerData.lookingAt
  looking = playerData.isLookingAtBlock
   if lookingAt.y == -1 and lookingAt.z == 0 and lookingAt.x == 0 then
	 bridge.clear()
	bridge.addText(6, 6, "this is a computer")
  else
	bridge.clear()
	bridge.addText(6, 6, "this is not a computer")
  end
end
and it works, but if i am not looking at a block the x,y, and z values become null and i get a crash, so i change it to this:

scan = peripheral.wrap("top")
bridge = peripheral.wrap("bottom")
while true do
  playerData = scan.getPlayerData("hunter239833")
  lookingAt = playerData.lookingAt
  looking = playerData.isLookingAtBlock
   if lookingAt.y and lookingAt.y == -1 and lookingAt.z == 0 and lookingAt.x == 0 then
	 bridge.clear()
	bridge.addText(6, 6, "this is a computer")
  else
	bridge.clear()
	bridge.addText(6, 6, "this is not a computer")
  end
end

but it immediately skips to else no matter what im looking at. theoretically it should work, if there are coords for a block im looking at, and they match the computers coords, then print the message, but alas no

edit: i can also use isLookingAtBlock, which returns a true or false depending if im looking at a block, but it has the same end effect, locking into else. i will post it for reference anyway:

scan = peripheral.wrap("top")
bridge = peripheral.wrap("bottom")
while true do
  playerData = scan.getPlayerData("hunter239833")
  lookingAt = playerData.lookingAt
  looking = playerData.isLookingAtBlock
   if playerData.isLookingAtBlock and lookingAt.y == -1 and lookingAt.z == 0 and lookingAt.x == 0 then
	 bridge.clear()
	bridge.addText(6, 6, "this is a computer")
  else
	bridge.clear()
	bridge.addText(6, 6, "this is not a computer")
  end
end


nevermind, forgot one simple cap, works now
Edited on 26 March 2014 - 05:58 PM