Jump to content




Where to download an external api


  • You cannot reply to this topic
9 replies to this topic

#1 J15t98J

  • Members
  • 30 posts
  • LocationPlanet Earth, the Universe

Posted 23 May 2012 - 06: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?

#2 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 23 May 2012 - 06:11 PM

Lua's string API is built in... Just use it like you would normally.

#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 23 May 2012 - 06:12 PM

If you mean the default lua string library, it's already included. Otherwise, we need to know what api you want.

#4 J15t98J

  • Members
  • 30 posts
  • LocationPlanet Earth, the Universe

Posted 23 May 2012 - 06:17 PM

But string.gsub and string.find don't work.

#5 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 23 May 2012 - 06:21 PM

They work for me. Do you get an error?

#6 J15t98J

  • Members
  • 30 posts
  • LocationPlanet Earth, the Universe

Posted 23 May 2012 - 06:58 PM

startup:11: attempt to index ? (a number value)

#7 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 23 May 2012 - 07: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.

#8 J15t98J

  • Members
  • 30 posts
  • LocationPlanet Earth, the Universe

Posted 23 May 2012 - 07: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?

#9 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 23 May 2012 - 07: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.

#10 J15t98J

  • Members
  • 30 posts
  • LocationPlanet Earth, the Universe

Posted 23 May 2012 - 08:03 PM

Ok, thanks.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users