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

Inconsistant results from the same line of code with openPeripheral

Started by sandworm, 12 September 2013 - 05:14 PM
sandworm #1
Posted 12 September 2013 - 07:14 PM
Title:Inconsistant results from the same line of code with openPeripheral

in this code the bold lines work, but the italics does not, they are the exact same other then how the ID is supplied, i also changed the method to call to garbage and it says that it's an invalid method, other wise it shows :

powerTest : 77 : Invalid number of parameters.
Expected 1

77 is the line of the italic callRemote

so i know it is checking, i can't help but wonder if it's not talking about callRemote but i'm just not familer enough with the api to know the issue, i also have a link to the pastebin with the full code, incase the problem exists else where and is effecting it. i also tried just putting in the peripheral name as i did with the other lines, and it shows the same error


function getPowerPercentage()
	cell1 = net.callRemote("redstone_energy_cell_0", "getEnergyStored") --#Works in these four lines
	cell2 = net.callRemote("redstone_energy_cell_1", "getEnergyStored")
	cell3 = net.callRemote("redstone_energy_cell_2", "getEnergyStored") 
	cell4 = net.callRemote("redstone_energy_cell_3", "getEnergyStored")
	amount = cell1 + cell2 + cell3 + cell4
	return (amount / capacity) * 100
end
function setAllTankPercentage()
	setTankPercentage(lavaTank)
	setTankPercentage(oilTank)
	setTankPercentage(fuelTank)
	setTankPercentage(essenceTank)
end
function setTankPercentage(tank)
	local tankCapacity = 0
	local tankAmount = 0
        local values = net.callRemote(tank.id,"getTanks") --#Doesn't work here

	for k, v in pairs(values) do
		for x, y in pairs(v) do
			if x == amount then
				tankAmount = y
			end
			if x == capacity then
				tankCapacity = y
			end
		end
	end

	tank.percent = tankAmount/tankCapacity
end


full code : http://pastebin.com/BMu4V1Kk
Edited by
Bubba #2
Posted 12 September 2013 - 08:36 PM
My first guess would be that tank.id does not contain the actual peripheral name of the tank.

My second guess would be that the tank.id is actually nil. Make sure to check that the variable exists before actually running the method.

if not tank.id then
  print("Invalid tank parameter provided.")
else
  net.callRemote(tank.id,"getTanks")
end
sandworm #3
Posted 12 September 2013 - 09:26 PM
the full code shows where it's set, and i tried just putting the peripheral name right in there, but it throu the same error
Lyqyd #4
Posted 12 September 2013 - 09:30 PM
It isn't the same line of code. Does getTanks require an extra parameter? Can you run that line successfully from the lua prompt?
Bubba #5
Posted 12 September 2013 - 09:30 PM
Does "getTanks" require a parameter to be passed into it?
sandworm #6
Posted 12 September 2013 - 09:39 PM
it would seem to according to this
http://www.openperipheral.info/openperipheral/documentation/railcraft/iron-tank-valve
but it just says side, it's not the side of the computer the valve is on( and i wouldn't know what to put if i was doing it remotly) so i'm not sure what it wants
CoderPuppy #7
Posted 12 September 2013 - 09:42 PM
getTanks requires a side parameter but 'unknown' should work.

Edit: Ninjaed
sandworm #8
Posted 12 September 2013 - 09:44 PM
both with and without quotes didn't work with unknown, without said invalid parameter number 1, and with said attempt to call nil
sandworm #9
Posted 12 September 2013 - 09:54 PM
it seems to work fine with used with a computer butted up against the valve, but use like the code below still doesn't work.


function setTankPercentage(tank)
    local tankCapacity = 0
    local tankAmount = 0
    local tankArg = getTanks("unkown")                      -- This line errors : attempt to call nil with or without quotes
    local values = net.callRemote(tank.id,tankArg)
   
    for k, v in pairs(values) do
	    for x, y in pairs(v) do
		    if x == amount then
			    tankAmount = y
		    end
		    if x == capacity then
			    tankCapacity = y
		    end
	    end
    end
   
    tank.percent = tankAmount/tankCapacity
end
Sora Firestorm #10
Posted 12 September 2013 - 10:24 PM
You need to spell 'unknown' correctly (line 4), but even then I'm guessing 'unknown' is invalid (basing my answer on this which says the argument is a side)
sandworm #11
Posted 12 September 2013 - 11:03 PM
fixed the type, but still doesn't work, that was a fluke typo,

http://pastebin.com/NwUyF33s

that works fine run from a computer up against the vavle, but slimier code doesn't seem to work throu remote calls
sandworm #12
Posted 14 September 2013 - 01:12 AM
well i think i figured a work around, by calling computers that are all hooked up to the valve, so they don't need to go through the callRemote method, i'd rather not as it would add alot of bulk in the base, but if i can't figure it out or don't get any suggestions that work soon i may just decide it's not possible, which i think is ….. i'll call it a bug, but i know it's not the right word, like an exploit but in reverse lol…..
immibis #13
Posted 14 September 2013 - 09:45 PM
Why are you even using callRemote? This works fine:

local tank = peripheral.wrap(tank.id)
local values = tank.getTanks("unknown")
sandworm #14
Posted 14 September 2013 - 10:05 PM
Can't you do net.callRemote(tankid, "getTanks", "unknown") ?

Are you using too old a version of CC to just wrap the remote peripheral and call getTanks on it directly? That would work too…

i got the solution from thief^ shortly after asking about it in the openPeriferals thread (probly a better place for the question) it's the first one, it was stupidly simple, i was just unable to find out about that functionality of callRemote

Why are you even using callRemote? This works fine:

local tank = peripheral.wrap(tank.id)
local values = tank.getTanks("unknown")

yes he sugested that too, but the first was quicker to put in my code, i'm going to put that in comments for a later fix up as in the long run thats a better idea, i need to get into the habit of wraping more