ZagKalidor, on 24 April 2019 - 02:41 PM, said:
Hey guys,
how do I manage this loadstring() thing to get a true bolean value for, maybe modem methods, like example:
block=peripheral.wrap("left")
a = "isWireless()"
answer = loadstring ("block." .. a)
print (answer)
instead of
>>function 725678bla...
Thanks in advance
Zag
loadstring returns a callable function, so you need to do this:
block=peripheral.wrap("left")
a = "isWireless()"
answer = loadstring ("block." .. a)()
print (answer)
Although this does seem like an instance of the XY-Problem and what you really want to do is index a table using a variable, you can do the following to achieve that:
block=peripheral.wrap("left")
a = "isWireless" --'Notice how I'm not including brackets
answer = block[a]() -- This is the same as block.isWireless()
print(answer)
Also for this specific case you can also just use peripheral.call:
answer = peripheral.call("left", "isWireless")
print(answer)
Edited by Luca_S, 24 April 2019 - 03:24 PM.