17 posts
Location
South Africa
Posted 14 January 2013 - 01:25 PM
This is a game i've been working on. Its Similar to a claw machine :P/> [link]
http://images.monste...ine-700x700.jpg[/link]
Anyway what it does is move to where the user says, checks if the block below is obsidian (can change), and if it is, it returns and prints true (a prize will be implemented later)
The problem is that i get no errors but it doesnt return to its original position.
Please help
Code:
Spoiler
local xPos = 1
local zPos = 1
local yPos = 1
local q = xPos - 1
local w = zPos - 1
local e = yPos - 1
print("How far forward?")
local x = tonumber( read() )
term.clear()
term.setCursorPos(1,1)
print("How far left?")
local z = tonumber( read() )
term.clear()
term.setCursorPos(1,1)
print("How far down?")
local y = tonumber( read() )
term.clear()
function xMove()
for i = 1,(x) do
xPos = xPos + 1
turtle.forward()
end
end
function zMove()
turtle.turnLeft()
for i = 1,(z) do
zPos = zPos + 1
turtle.forward()
end
turtle.turnRight()
end
function yMove()
for i = 1,(y) do
yPos = yPos + 1
turtle.down()
end
end
print("Moving...")
xMove()
zMove()
yMove()
function goBack()
for i = 1,(q) do
turtle.back()
end
turtle.turnLeft()
for i = 1,(w) do
turtle.back()
end
turtle.turnRight()
for i = 1,(e) do
turtle.up()
end
end
if turtle.compareDown(1) true then
print("Well done!")
else
print("Try again...")
end
goBack()
Setup:
http://www.flickr.co.../in/photostreamhttp://www.flickr.co.../in/photostreamhttp://www.flickr.co.../in/photostreamSimplified - its a turtle in a glass room C:
139 posts
Location
USA
Posted 14 January 2013 - 01:28 PM
Does it return to somewhere near the original positions? And if you tell it to go to a different place than the obsidean, does it return to that same, wrong position?
17 posts
Location
South Africa
Posted 14 January 2013 - 01:36 PM
Does it return to somewhere near the original positions? And if you tell it to go to a different place than the obsidean, does it return to that same, wrong position?
It returns to the position it was in when you started the programs, or well at least it should. thats the problem
7508 posts
Location
Australia
Posted 14 January 2013 - 01:42 PM
Firstly, for next time this post is in the wrong section, for assistance with problems you should post in the "ask a pro" section…
So I'm assuming the problem comes about when its unloaded mid process?
139 posts
Location
USA
Posted 14 January 2013 - 02:00 PM
Does it return to somewhere near the original positions? And if you tell it to go to a different place than the obsidean, does it return to that same, wrong position?
It returns to the position it was in when you started the programs, or well at least it should. thats the problem
So does it just sit above the obsidean and never actually runs the goback function? Or does it run the goback function but returns to a position that is 1 x coord too far? If it does go somewhere, but the wrong place, just tinker with the values in the goback function.
8543 posts
Posted 14 January 2013 - 05:34 PM
Moved to Ask a Pro.
17 posts
Location
South Africa
Posted 14 January 2013 - 10:30 PM
Moved to Ask a Pro.
thanks
2005 posts
Posted 15 January 2013 - 06:53 AM
It looks like if the y entered is too large, the turtle will stall against the block it encounters, racking up the counter regardless. This would lead to the go back function failing…if it did anything anyway. Which it doesn't, because q,w, and e are all initialized to 0 (1-1) and you never change that.
Try a function structured like:
function yMove()
for i = 1,(y) do
if turtle.down() then yPos = i else break end
end
end
This way the move will only increment yPos for as long as the move succeeds. Then change your goBack() function so that it uses those modified position values for loop limits rather than having them all set to zero.
Edited on 15 January 2013 - 05:58 AM