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

[Lua][Question] Can i set a variable using a variable?

Started by rickydaan, 16 March 2012 - 03:10 PM
rickydaan #1
Posted 16 March 2012 - 04:10 PM
Like
function(printold, printnew)
print = printtext[printold]

text = print .. _text


If u see what i mean
Sebra #2
Posted 17 March 2012 - 05:42 AM
Can you see it yourself?
rickydaan #3
Posted 17 March 2012 - 09:26 AM
What u mean, i just want a system so i can move pieces without i need tons of functions. It edits the table;

function movePiece(newx, newy, oldshortcut, newshortcut)
unitSelected = t[oldshortcut]

unitSelected .. _x = newx
unitSelected .. _y = newy

if t[newshortcut] ~= "Nothing" then
term.setCursorPos(19,15)
print("You hit a piece from " .. turn .. "'s team!")
end
t[oldshortcut] = "Nothing"
t[newshortcut] = unitSelected
end
Sebra #4
Posted 17 March 2012 - 03:04 PM
If your units are tables…

function movePiece(newx, newy, oldshortcut, newshortcut)
  unitSelected = t[oldshortcut]

  unitSelected.x = newx
  unitSelected.y = newy

  if not t[newshortcut]==nil then
	term.setCursorPos(19,15)
    print("You hit a piece from " .. turn .. "'s team!")
  end
  t[oldshortcut] = nil
  t[newshortcut] = unitSelected
end