6 posts
Posted 24 March 2012 - 09:55 PM
Hey there,
I've just found out about the GPS feature which is very cool, but I can only find mathematical/complex commands for vectors (such as multiplying). I'm looking to seperate only the Y value, but I can't figure out how to do that (y = VectorA.y? y = VectorA[y]? ). Help?
(p.s. If im at the subject, can you add a page with all Computercrafts basic commads (Loops, If, arrays etc.) for us programmers who dont know Lua so we can learn faster?)
454 posts
Location
London
Posted 24 March 2012 - 10:20 PM
There is plenty of information to get you started in the tutorial section, and in links in the stickies.
If you'd have tried this, then you would find that
local y = vec.y
will give you the y value.
6 posts
Posted 25 March 2012 - 01:05 PM
My test program is:
rednet.open("right")
vec = vector.new(0, 0, 0)
vec = gps.locate(5, true)
y = vec.y
print("H")
print(y)
But it returns:
Finding position...
10.440307 meters from 821,5,881
12 meters from 831,5,872
9.219544 meters from 837,5,891
Position is 831,5,884
vector:7: attempt to index ? (a number value)
454 posts
Location
London
Posted 25 March 2012 - 01:07 PM
My test program is:
rednet.open("right")
vec = vector.new(0, 0, 0)
vec = gps.locate(5, true)
y = vec.y
print("H")
print(y)
But it returns:
Finding position...
10.440307 meters from 821,5,881
12 meters from 831,5,872
9.219544 meters from 837,5,891
Position is 831,5,884
vector:7: attempt to index ? (a number value)
You are overwriting vec when you do vec = gps.locate(5, true), with a number.
6 posts
Posted 25 March 2012 - 01:10 PM
Doesn't gps.locate return a vector?
715 posts
Posted 25 March 2012 - 01:24 PM
Doesn't gps.locate return a vector?
No, it returns 3 number values.
You have to use:
local x, y, z = gps.locate(5, true)
The way you used it just grabbed the first returned value of
locate(), the x coordinate.
And since
x is just a number, so will your
vec be. That's why there isn't any
vec.y
6 posts
Posted 25 March 2012 - 01:42 PM
Ok, now it works thank you very much