function save(var,text)
var = text
end
But, it will save the text to "var" and not the variable that the user provided.Also, need a good tutorial on using _G
- What is it?
- how to use it
- when to use it
- why to use it
function save(var,text)
var = text
end
But, it will save the text to "var" and not the variable that the user provided.
function func (_table)
print (_table)
end
and I do the following:
local myTable = { 1, 2, 3, 4, 5 }
print (myTable)
func (myTable)
I'll get the SAME value printed out which is simply the address of the table. Therefore, if you want to copy tables, you'll have to do it using what's called recursion or just going through the table and copying the non-table values if the table is simple enough (not really any tables within the table).
var = text
without a function or, superfluously:
local var = nil
function save (text)
var = text
end
or even
local var = nil
function save (text)
return text
end
var = save ("Test.")
All of the which are unnecessary except for the first example without any functions.
-- term.write ("Test.")
_G["term"]["write"] ("Test.")
_G["index"] = ...
-- or even (if you know exactly what you want the index to be)
_G.totallyAwesomeTable = {}
local var = text
But I thought that there was a way to take whatever is in the variable "text", and save it as whatever text in the variable "var".Sorry to piggyback on this topic but its kinda relevant - so i could per example overwrite all turtle movement functions with my own to add positioning code and store current turtle position inside _G table? would that even be good idea?
local x, y
function replacement.up() ... end
function replacement.down() ... end
function replacement.forward() ... end
...
Sorry to piggyback on this topic but its kinda relevant - so i could per example overwrite all turtle movement functions with my own to add positioning code and store current turtle position inside _G table? would that even be good idea?
It's not necessarily a good idea to store the position in _G. You shouldn't really put anything in _G unless you want everything else to be able to access it, and you don't mind the possibility of name collisions. A better way is to just have local variables accessible to your custom turtle functions.local x, y function replacement.up() ... end function replacement.down() ... end function replacement.forward() ... end ...
function save(text)
return text
end
a = save("Hello world")
--# a is now "Hello world"
@OP if you want to do a save function you can do something likefunction save(text) return text end a = save("Hello world") --# a is now "Hello world"