Jump to content


OrangeC7's Content

There have been 9 items by OrangeC7 (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#275528 What is "..." With Tables/Functions?

Posted by OrangeC7 on 27 February 2018 - 06:24 PM in Ask a Pro

View PostLuca_S, on 27 February 2018 - 05:55 PM, said:

The "..." operator is used to indicate Varargs

If you want a function that adds multiple values you could do it like that:
function add(...)
  local params={...} --This wraps the varargs in a table
  local res
  for i = 1,#params do
	res = res + params[i]
  end
  return res
end
print(add(1)) --1
print(add(1,2)) --3
print(add(5,1,3,1)) --10
I see... Thanks!



#275525 What is "..." With Tables/Functions?

Posted by OrangeC7 on 27 February 2018 - 05:47 PM in Ask a Pro

I've been trying to find information on exactly WHAT the "..." input does, and I couldn't find anything about it.
(I tried searching it on the forums, but "..." is counted as less than 4 chars. ¯\_(ツ)_/¯)
Anyways, the thing I know about this 'operator'(?) is that it is used for getting the user's input on arguments passed with a program through the shell, like the following:
local tArgs = {...}
local function allArgs()
  for i=1,#tArgs do
	local temp = ""
	if tArgs[i] ~= nil then
	  temp = temp..tostring(tArgs[i])
	end
  end
  return temp
end
print("You executed this program with the arguments "..allArgs())
but I don't know if it's just something as a part of computercraft or something useful I can actually use, because I noticed that the "..." thing was used in the local shell function "tokenize()":
function tokenise( ... )
  local sLine, tWords, bQuoted = table.concat( { ... }, " " ), {}, false
  for match in string.gmatch( sLine .. "\"", "(.-)\"" ) do
	if bQuoted then
	  table.insert( tWords, match )
	else
	  for m in string.gmatch( match, "[^ \t]+" ) do
		table.insert( tWords, m )
	  end
	end
	bQuoted = not bQuoted
  end
  return tWords
end
So, can someone explain this please?



#274996 lua crashed when making a 2d ripple

Posted by OrangeC7 on 05 February 2018 - 04:46 PM in Ask a Pro

View PostBomb Bloke, on 05 February 2018 - 09:56 AM, said:

How do you know that Lua crashed? If you received an error to that effect, then what did that error say?
It was a blue screen of death, "Lua thread crashed", kinda thing. It didn't say anything else, though.

View PostBomb Bloke, on 05 February 2018 - 09:56 AM, said:

This way, running your script with an argument of eg "red" will automatically set clr to colours.red - or if the tArgs[1] key isn't found in the colours table (because the user either supplied an incorrect key name or omitted the argument entirely), it'll fall back to light blue.
Thanks! I'll definitely change that.

View PostBomb Bloke, on 05 February 2018 - 09:56 AM, said:

You're "not"ing x1 and y1, as opposed to "x1 == ignore[l][1]" and "y1 == ignore[l][2]". You meant to do:

if x1 ~= ignore[l][1] and y1 ~= ignore[l][2] then
Okay, I usually do things like this
if not x1 == ignore[l][1] then
for no real reason, because I thought the two syntaxes(?) were interchangeable.

View PostBomb Bloke, on 05 February 2018 - 09:56 AM, said:

One other point is that sleep() relies on ComputerCraft's timer system, and ComputerCraft only checks timers every server tick - there are twenty of these per second, so your sleep(0.01) call is effectively rounded to sleep(0.05).
I know, I just set it to sleep(0.01) or os.startTimer(0.01) because I know it'll just go as fast as it can. =)



#274987 Computer Headset?

Posted by OrangeC7 on 05 February 2018 - 05:10 AM in Suggestions

I know this has been suggested before, but the last reply to that topic was in 2015 (which is like, a BILLION years ago), so I figured that it might be a better idea to make a new thread instead of replying to an old one. The link to the other thread is here if you're interested:
So, my idea for this is that the headset will have:
- Features
Spoiler
- Usefulness in-game
Spoiler
- Attainability
Spoiler

So, I think that's it. Those were all my ideas for a computer headset, and I hope this gets considered as something to be added!
--------------------------------------------------------------------
**Optional, not needed for the full craft.
***To allow sound to come out of the headset, you'll need to put the optional jukebox in the crafting recipe. The implant doesn't need it, because it connects directly to the auditory part of the player's brain,
*kill me.



#274986 lua crashed when making a 2d ripple

Posted by OrangeC7 on 05 February 2018 - 03:38 AM in Ask a Pro

View PostDog, on 05 February 2018 - 01:46 AM, said:

You're currently initializing it with whatever command line arguments are provided, but you're already using the first command line argument to specify color. I'm guessing you just want to initialize an empty table - to do that, do this...
local ignore = { }
Oh, so that's what that does. Thanks! (I thought it just initialised a blank table) Might explain some other errors I've been getting when using tables recently...



#274981 lua crashed when making a 2d ripple

Posted by OrangeC7 on 05 February 2018 - 12:51 AM in Ask a Pro

So, what the program is supposed to do is make a 2d "ripple" around wherever the user clicks. It was supposed to work this way:
- First for loop to track how many layers have been drawn
- Nested for loop to track which column is being drawn to
- Another nested for loop to track which row is being drawn to
- an if statement to check if the current position has been added to the 'ignore' list, which is supposed to track which points have been drawn to in order to not draw to them again. (I want a ripple, not a square that keeps getting bigger)
When I try to run it, though, I click an area on the screen (besides the "close" button in the bottom right), and suddenly lua crashes. (Edit: I tried again and lua didn't crash. But it still doesn't do what I expect ¯\_(ツ)_/¯) =(
So, my questions are
- WHY did it crash not do what I expect?
- How can I prevent it if I can?
- And if I can't (or if there's a simpler way to do this), how else can I do what I'm trying to do?
Here's the code (I put it in a spoiler tag 'cus it's kinda long):
Spoiler
Here's the relevant code for mrtutils (a custom API used in the code above):
-- Writes at a specific location
function writeAt(str, x, y)
term.setCursorPos(x,y)
term.write(str)
end
Note: I'm using CraftOS 1.7



#274433 Online ComputerCraft coding?

Posted by OrangeC7 on 16 January 2018 - 07:37 PM in Suggestions

The more I think about this the dumber it sounds, but I thought it was worth mentioning.
Would it be possible to have a ComputerCraft terminal online (perhaps on the website), so people can play around with it without having to go into Minecraft? I imagine this could be used for people to play around with coding in ComputerCraft before they download the mod, to see if they like it, or maybe if someone's computer broke and the longer they're away from coding on "OrangeC7PC" the more they experience withdrawal symptoms*? I know it's kinda dumb, like I said, but it's a kind of interesting idea nonetheless. =)

*Totally not related to any IRL problems I'm going through right now.



#274379 Trying to program an FTP

Posted by OrangeC7 on 15 January 2018 - 01:58 AM in Ask a Pro

View PostBomb Bloke, on 15 January 2018 - 12:59 AM, said:

Which script are you talking about? Which block of code within that script?


I have no idea what is going wrong, all I know is that both computers output the message that indicates they have done the "initialisation" step, and then never output anything again. I'll try to take your suggestion into consideration, though. The main reason I have all the confirmation messages is because of the slowPrint, both computers keep trying to establish contact, in case the other one missed something. If it means sacrificing good looks for functionality, I'll gladly remove the slowPrint feature and use a regular print. Thank you for replying, though! I appreciate it. =)



#274370 Trying to program an FTP

Posted by OrangeC7 on 14 January 2018 - 07:27 PM in Ask a Pro

(I'm reposting this because I didn't know about the "code" and "spoiler" tags, sorry. I'll be more careful next time.)
I've been troubleshooting my FTP_RECEIVER and FTP_SENDER programs for a while, but I'm stuck on a bug that keeps freezing the computer on the initialisation stage. Any help is appreciated, whether it's just to say I have the wrong approach, or if it's a solution to my problem. I'm kind of a beginner to this, although I have some coding experience in other languages including this one.
I start FTP_RECEIVER first, because then it will continue waiting for the next computer, FTP_SENDER to respond. The code is below

FTP_RECEIVER:
Spoiler

FTP_SENDER:
Spoiler

Thank you for reading, and for your patience.