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

zachary's first program

Started by zachary.litzinger, 31 May 2017 - 11:03 PM
zachary.litzinger #1
Posted 01 June 2017 - 01: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.pdglobal.net/?sid=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 on 01 June 2017 - 02:07 AM
Bomb Bloke #2
Posted 01 June 2017 - 01:13 AM
http://www.computercraft.info/wiki/Http.get
zachary.litzinger #3
Posted 01 June 2017 - 01: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)
Bomb Bloke #4
Posted 01 June 2017 - 01: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).
zachary.litzinger #5
Posted 01 June 2017 - 02: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.
Bomb Bloke #6
Posted 01 June 2017 - 02:16 AM
Documentation for ComputerCraft-specific commands, such as those in the redstone API, can be found here.
Edited on 01 June 2017 - 12:16 AM
zachary.litzinger #7
Posted 01 June 2017 - 02:19 AM
thanks, I figured it out
https://pastebin.com/ksJ8mLum
zachary.litzinger #8
Posted 01 June 2017 - 03: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,
KingofGamesYami #9
Posted 01 June 2017 - 03:08 AM
Use string.sub( str, 2 )
zachary.litzinger #10
Posted 01 June 2017 - 03: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
KingofGamesYami #11
Posted 01 June 2017 - 03: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.
Bomb Bloke #12
Posted 01 June 2017 - 04: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.
zachary.litzinger #13
Posted 01 June 2017 - 08:41 PM
I've found the error, the peripheral api has changed and now uses a different set of functions to dial.
zachary.litzinger #14
Posted 01 June 2017 - 08: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 on 01 June 2017 - 06:51 PM
Dog #15
Posted 01 June 2017 - 09: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