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

Index error

Started by Kazimir, 15 August 2012 - 01:48 PM
Kazimir #1
Posted 15 August 2012 - 03:48 PM
Tell me how to line 4 should look like?
Tables "tX" and "tY" is the index in table "tHex"
if write
print(tHex[tX[hX]][tY [hY]])
outside the function, it works

but if write like that, then an error index



function symbTable(X,Y,sSymb)
X=tX[hX]
Y=tY[hY]
sSymb = tHex[tX[hX]][tY[hY]]
end
X=3
Y=5
print(symbTable(X,Y,sSymb))
Cranium #2
Posted 15 August 2012 - 03:52 PM
Is tHex a function? If so, shouldn't tX[hX] be in () instead of []? Otherwise, you need to have this line:

sSymb = tHex[tX[hX]][tY[hY]]
look like this:

sSymb = tHex[tX[hX]],tHex[tY[hY]] --added a comma here, so that sSymb is equal to two values
KaoS #3
Posted 15 August 2012 - 03:53 PM
whoa man, what are you making with that, I remember using vars as co-ordinates in DOS and starting to do the same with tables in lua but that looks worrying
Kazimir #4
Posted 15 August 2012 - 04:04 PM
No, tHex a table with the symbols, and the index is composed of tX and tY

that's the entire script:
http://pastebin.com/7x2zYT3a
Kazimir #5
Posted 15 August 2012 - 04:10 PM
I want to be when you call the function from a table function to return the symbol
Cranium #6
Posted 15 August 2012 - 04:16 PM
So how is sSym supposed to look for example?
Kazimir #7
Posted 15 August 2012 - 04:23 PM

tX = {}
tX["h0"]=1
tX["h1"]=2
tX["h2"]=3
tX["h3"]=4
tX["h4"]=5
tX["h5"]=6
tX["h6"]=7
tX["h7"]=8
tX["h8"]=9
tX["h9"]=10
tX["hA"]=11
tX["hB"]=12
tX["hC"]=13
tX["hD"]=14
tX["hE"]=15
tX["hF"]=16
tY = {}
tY["0"]=1
tY["1"]=2
tY["2"]=3
tY["3"]=4
tY["4"]=5
tY["5"]=6
tY["6"]=7
tY["7"]=8
tY["8"]=9
tY["9"]=10
tY["A"]=11
tY["B"]=12
tY["C"]=13
tY["D"]=14
tY["E"]=15
tY["F"]=16
tHex={
--|0|-|1|-|2|-|3|-|4|-|5|-|6|-|7|-|8|-|9|-|a|-|b|-|c|-|d|-|e|-|f|------|
{"~","F","W","&","f","w"," "," "," "," "," "," "," "," "," "," "},--|0|
{"0","G","X","*","g","x"," "," "," "," "," "," "," "," "," "," "},--|1|
{"1","H","Y","(","h","y"," "," "," "," "," "," "," "," "," "," "},--|2|
{"2","I","Z",")","i","z"," "," "," "," "," "," "," "," "," "," "},--|3|
{"3","J",".","-","j"," "," "," "," "," "," "," "," "," "," "," "},--|4|
{"4","K",",","+","k"," "," "," "," "," "," "," "," "," "," "," "},--|5|
{"5","L",";","/","l"," "," "," "," "," "," "," "," "," "," "," "},--|6|
{"6","M",":","*","m"," "," "," "," "," "," "," "," "," "," "," "},--|7|
{"7","N","'","[","n"," "," "," "," "," "," "," "," "," "," "," "},--|8|
{"8","O","!","]","o"," "," "," "," "," "," "," "," "," "," "," "},--|9|
{"9","P","?","|","p"," "," "," "," "," "," "," "," "," "," "," "},--|a|
{"A","R","@","a","r"," "," "," "," "," "," "," "," "," "," "," "},--|b|
{"B","S","#","b","s"," "," "," "," "," "," "," "," "," "," "," "},--|c|
{"C","T","$","c","t"," "," "," "," "," "," "," "," "," "," "," "},--|d|
{"D","U","%","d","u"," "," "," "," "," "," "," "," "," "," "," "},--|e|
{"E","V","^","e","v"," "," "," "," "," "," "," "," "," "," "," "}---|f|
-----------------------------------------------------------------------|
}

function symbTable()
X=tX[hX]
Y=tY[hY]
end
X="h0"                                --horizontal
Y="0"                                  --vertical
print(tHex[tX[X]][tY[Y]])        --symbol that the function should return

Cranium #8
Posted 15 August 2012 - 04:40 PM
in your new code, you are not defining tHex for tY[Y]
Needs to be tHex[tY[Y]]
Kazimir #9
Posted 15 August 2012 - 05:22 PM
in your new code, you are not defining tHex for tY[Y]
Needs to be tHex[tY[Y]]
thanks, something I'm now very unattentive))
Kazimir #10
Posted 15 August 2012 - 05:43 PM
here ready script
I'm going to use it for cipher machine and LED display
http://pastebin.com/qFwZr391