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

[LUA] [SOLVED] GPS Help

Started by rbasset, 13 June 2012 - 04:55 AM
rbasset #1
Posted 13 June 2012 - 06:55 AM
Im new to ComputerCraft and so far i absolutely LOVE it, now i have some programming background but nothing in LUA , now heres my problem, I have a computer that I run
gps host <x> <y> <z>
But everytime I quit and go to play again i have to go to the computer and type the code al over again, I have 3 seperate computers about 45 blocks apart in a triangular positioning, thats alot of blocks to travel just to type that in lol, so i suppose on to my question -

How would I get the GPS HOST <x><y><z> to load when the "startup" file loads?

ive tried

– startup
gps host <x><y><z>
–end of startup file on computer


the error that i get when it loads is nil - trying to place string as int or something like that.

please help!
PixelToast #2
Posted 13 June 2012 - 07:08 AM
if your trying to run a shell program from lua, use shell.run("gps","host",x,y,z) in the startup file
rbasset #3
Posted 13 June 2012 - 08:00 AM
thats working but i need to have it auto populate the x,y and z but when i replace x.y.z with -176 +247 63 i get the error

>startup
bios:206: [string "startup"]:1: unexpected symbol
>

the startup code is

shell.run("gps","host",-176,+247,63)

now if i leave it as

shell.run("gps","host",x,y,z)
then it works BUT it says to add the x,y,z in manually which is what im trying not to do. i want it all automatic. :(/>/>

thanks in advance!
fsz1987 #4
Posted 13 June 2012 - 09:04 AM
well,this is how i get my gps servers works automaticlly

Step 1 ,find the coordinate of the server.

Step 2 ,set the server label use the label command. for example,for a server at 0,0,0 run command: label set 0 0 0

Step 3 ,i've already written a short startup code for general use,just copy and save it to your server's root directory with name "startup"

term.clear()
term.setCursorPos( 1, 1 )
pos = os.getComputerLabel();
x,y,z = string.match (pos,"(%d+)%s(%d+)%s(%d+)")
shell.run ("gps","host",x,y,z);

then reboot you server,now it will host gps service automaticlly,even you quit and play again :(/>/>
rbasset #5
Posted 13 June 2012 - 09:50 AM
http://flic.kr/p/ce6pNA


thats what im getting now
Cloudy #6
Posted 13 June 2012 - 10:06 AM
To be honest, what I would do is this:

local x = 123 --no need to put + if positive value!
local y = 456
local z = -789

shell.run("gps", "host", x, y, z)
rbasset #7
Posted 13 June 2012 - 10:08 AM
i will try that when i log back in, i will let you know thank you!
rbasset #8
Posted 13 June 2012 - 10:11 AM
Cloudy Thanks A lot this works like a Charm!!!!!


thank you to everyone else too for the ideas!