Jump to content




zachary's first program



14 replies to this topic

#1 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 12:03 AM

Hello all I'm completley new to computercraft and I need a little help getting started on my first program.

I want to dial a stargate based on a friendly name, however to do this I have to get the source code of a page on my website to query the database

http://intranet.pdgl...=dial&name=test

This is the url I need to get the source code of with "test" changed to a variable (read() function).

How do I go about getting the source of a webpage by it's URL?

Thanks a lot in advance.

Edited by Bomb Bloke, 01 June 2017 - 03:07 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 June 2017 - 12:13 AM

http://www.computerc...o/wiki/Http.get

#3 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 12:28 AM

Thanks for the quick response, however now I need to know what character to use to append a variable to the end of a string. (+,&,.) (not sure which to use)

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 June 2017 - 12:51 AM

String concatenation is performed using two periods; eg:

local var1, var2 = "hello", 123

print(var1 .. var2 .. 456 .. "world")

Don't stick two dots directly after a number, though (without a space / bracket), or Lua will assume you intended to enter a fraction and complain the number's malformed (throwing a "multiple points" error).

#5 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 01:08 AM

Just have a quick question that I couldn't find an easy answer to.

I want to write a script to password lock doors, however the only thing I don't know how to do that I need to do is manipulate a redstone device connected to the computer.

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 June 2017 - 01:16 AM

Documentation for ComputerCraft-specific commands, such as those in the redstone API, can be found here.

Edited by Bomb Bloke, 01 June 2017 - 01:16 AM.


#7 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 01:19 AM

thanks, I figured it out
https://pastebin.com/ksJ8mLum

#8 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 02:03 AM

Hello! I was just wondering if there is a quick and easy way to trim one character off the left side of a string?

I've tried some premade functions I found on google, but they didn't seem to work with computercraft,

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 01 June 2017 - 02:08 AM

Use string.sub( str, 2 )

#10 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 02:16 AM

I have implemented this into my code and it gives me an error about accessing a nil value.

here is my code, please explain what I'm doing wrong

https://pastebin.com/PVxYYXeL

#11 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 01 June 2017 - 02:54 AM

That shouldn't be a problem.


My first guess is the wrapping of stargate_1 failed, and the issue you have is 'attempt to index ? (a nil value)' on line 13, not line 12. Occasionally line numbers are off by a line or two in lua.

My second guess is the error in question is a Java error, and that the stargate peripheral is improperly programmed to respond to an invalid address when asked to dial. It may require a number, not a string, in which case you should use the tonumber function. I don't know the stargate peripheral well so this is just a guess.



#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 June 2017 - 03:05 AM

Of course, there'd be much less need to "guess" if you'd bothered to provide the actual error, Zachary.

Let's keep all these questions about the one project in the one place - I'll merge them all together.

#13 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 07:41 PM

I've found the error, the peripheral api has changed and now uses a different set of functions to dial.

#14 zachary.litzinger

  • Members
  • 8 posts

Posted 01 June 2017 - 07:51 PM

Here's my new code so far.
https://pastebin.com/9JLjhYn9
Does anyone know the new method for dialing the stargates? I can't seem to figure it out.

Edited by zachary.litzinger, 01 June 2017 - 07:51 PM.


#15 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 01 June 2017 - 08:21 PM

Since you're wrapping a StargateBase I'm going to guess that you're using LanteaCraft. The dialing method has changed considerably and now requires that you break the address down in to individual chevrons, then dial and lock each chevron in order, then make the connection. Here's a really basic example:

for i = 1, #address do --# start a loop equal in length to the number of characters in the address
  sg.selectGlyph(address:sub(i, i)) --# select the glyph associated with the current iteration of the loop
  sg.activateChevron() --# activate the chevron for the selected glyph
end
sg.engageStargate() --# engage the connection






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users