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

Where to download an external api

Started by J15t98J, 23 May 2012 - 05:10 PM
J15t98J #1
Posted 23 May 2012 - 07:10 PM
I want to download and add Lua's string api to the mod. I know how to add the api, but I don't know where to download the api. Anyone know?
Cloudy #2
Posted 23 May 2012 - 07:11 PM
Lua's string API is built in… Just use it like you would normally.
MysticT #3
Posted 23 May 2012 - 07:12 PM
If you mean the default lua string library, it's already included. Otherwise, we need to know what api you want.
J15t98J #4
Posted 23 May 2012 - 07:17 PM
But string.gsub and string.find don't work.
MysticT #5
Posted 23 May 2012 - 07:21 PM
They work for me. Do you get an error?
J15t98J #6
Posted 23 May 2012 - 07:58 PM
startup:11: attempt to index ? (a number value)
MysticT #7
Posted 23 May 2012 - 08:00 PM
Seems an error in your code. I can't tell without the code, but I think the problem is that you defined a variable called string. If that's the case, just rename that variable and it should work. But again, I need to see the code to be sure.
J15t98J #8
Posted 23 May 2012 - 08:00 PM
Don't worry, I've fixed it (I think). On another note, when a message is sent to a turtle, it outputs the sender ID on line 1, the message on line 2 and the distance from the sender on line 3. If I wrote local msg = rednet.receive(), how would I access the message part?
MysticT #9
Posted 23 May 2012 - 08:07 PM
Like you said, rednet.receive() returns three values: the id of the sender, the message and the distance from the sender. You just have to store the values you want in variables, like this:

local id, msg, distance = rednet.receive()
You don't need to store all of them, but if you want one you need the ones before that. So you can't get only the message or the distance, you need to store the previous values, even if you don't need them. You can do something like:

local _, msg = rednet.receive()
if you just want the message. The _ is commonly used to represent an unused variable, you could do

local id, msg = rednet.receive()
and it would be the same.
J15t98J #10
Posted 23 May 2012 - 09:03 PM
Ok, thanks.