Jump to content


Bossman201's Content

There have been 92 items by Bossman201 (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#17033 Need help with running songs on my computer!

Posted by Bossman201 on 28 June 2012 - 03:20 AM in Ask a Pro

View Postschrolock, on 27 June 2012 - 09:53 PM, said:

so you are searching for an rtu program where you only have to press play and it works. but the problem is that you need to find out the melody of a song and find the frequency and the right tone.and then you have to set up an program with this information in its code to play the music. lots of work

Lots of work, sure, but if you know a bit about music it shouldn't be too hard. I'll be writing a Song Writer and Music Player after the final release of BossChat, maybe before (BC is kind of my pet-project, might never be fully completed).



#17032 bios:206: [string "startup"]:13: '=' expected

Posted by Bossman201 on 28 June 2012 - 03:06 AM in Ask a Pro

After formatting your code, your error wasn't hard to track down:
function start()
 print("password required to open")
 a = read()
 if a == "password" then
  print ("Access Granted") --Minor spelling error
  rs.setOutput("right", true) --Corrected code, unfinished string, nil function call: rs.setOutput("right", true). I did not even notice this until posting it in the forum, as the rest of the program became green. right.true is not a function, you put a period instead of a comma. Lastly, forgot to close the string, "right", by adding a quotation mark at the end.
 else
  print ("Access Denied") -- Capitalized words
  rs.setOutput("left", true)
  sleep(3)
  os.shutdown
 end --Forgot to close 'if' statement, or function. In short, you left out one 'end'.
end

Also, since you defined this as a function, you'll need to add:
start()
At the end of all the code to call the function or else after the computer starts up, it'll just go to the shell and not do anything.



#16987 [1.31] ccNet - Network Peripheral

Posted by Bossman201 on 27 June 2012 - 06:55 PM in Peripherals and Turtle Upgrades

View PostVandie, on 27 March 2012 - 07:51 PM, said:

nice but couldn't it cause a few security threats

From who? I think this only works in SSP



#16886 Love music but not too good with code...

Posted by Bossman201 on 26 June 2012 - 07:49 PM in Ask a Pro

I haven't used the Redstone API at all in lua before, but looking at the methods posted here, it looks like this code should be sufficient for redstone wiring or single red alloy wiring.

local note = "whatever note you want to play" --ex. E F G A B C D including sharps and flats.
while true do --Loop runs forever.
id, message = os.pullEvent("rednet_message") --os.pullEvent "pulls" every event that happens during program execution; with the filter "rednet_message", only rednet message events will be pulled.
 if message == note then --Checks to see if the broadcasted note is the note this computer is responsible for.
  rs.setOutput("back", true) --Turns on redstone.
  sleep(0.1) --Might be necessary, might not.
  rs.setOutput("back", false) --Turns off redstone.
 end
end

Test the programs without sleep() but they might be necessary.



#16829 Love music but not too good with code...

Posted by Bossman201 on 26 June 2012 - 01:48 AM in Ask a Pro

Yes, that code will only play one note at a time.

If you wanted to play multiple notes, you should use this code:
paralell.waitForAll(rednet.broadcast(note1), rednet.broadcast(note2))
You must change your code so that the server broadcasts the note you want played instead of just changing state on some redstone. The client can then manage changing redstone states itself. No reason to add overhead.

Also, your current client code doesn't turn off any redstone states. Meaning you can only play each note once unless the system is reset.



#16800 Turtle Control Help

Posted by Bossman201 on 25 June 2012 - 06:50 PM in Ask a Pro

I think we should explain to him why code doesn't work, rather than just fixing it for him.

while true do
  term.setCursorPos(1, 3)
  write "F, L, R, B, M, U, D?"
  local input = read() --If you do not capitalize your letters, all 'if statement' conditions will be false and skipped over, resulting in the 'else' code being run.
  --use 'local input = string.upper(read())' instead
  if input == string.upper(f) then --Unrelated: Forgot quotation marks around the letter f here.
	rednet.send(58,"f")
	print "Turtle Forward"

  elseif input == string.upper("b") then --Never write a condition like this.
   --It is the same as 'elseif input == "B" then'
   --I think the code you really wanted was 'elseif string.upper(input) == "B" then'
   --But again, using 'local input = string.upper(read())' above will make all input capitalized after pressing enter.
	rednet.send(58,"b")
	print "Turtle Backward"
  --code
  --code
  --code
  --code
  else --Always good to have else statements, helps a lot with debugging.
   print "No command Exists"
  end
end



#16723 Turtle Control Help

Posted by Bossman201 on 25 June 2012 - 03:11 AM in Ask a Pro

Turtles can only go forward...What is your problem? Does the turtle not turn?

Turtle code:
local id, msg = rednet.receive()
msg = string.upper(msg)
Add the second line right under the first line in your code.

Computer code:
local input = read()
input = string.upper(input)
Take out all of the string.lower() in your 'if' statements.

Both codes:
else
print("No command exists.")
end
Put this right after the last 'elseif'.

This code will remove all 'wildcards' from user input. If you added the else statement without making the other changes, sometimes user input will not match the conditions and the 'else' message will be shown, even if the user input the correct letter. Using string.upper() will always make the user input capital letters, which is how you're checking them.



#16714 fs read and write at same time

Posted by Bossman201 on 25 June 2012 - 12:59 AM in Ask a Pro

Why would you need to re-store data you already have in memory or store data that you're about to overwrite?



#16712 Love music but not too good with code...

Posted by Bossman201 on 25 June 2012 - 12:55 AM in Ask a Pro

View PostMysticT, on 25 June 2012 - 12:44 AM, said:

View PostBossman201, on 25 June 2012 - 12:28 AM, said:

if tSong[1] ~= "nil" then --Yes, this is a string because leaving a nil key in a table is poor programming etiquette, if you ask me.
???
Seting a value to nil in a table is like removing it, so it's better to do it, since it would free the space.
The guess the one coding it poorly was me lol. Anyway that is just a block of example code I wrote, in a real music editor there would always be a BPM or else the song could not play.

EDIT: To all, if you plan on using that code I posted for the love of god message me first so I can spend some actual time writing functional code. I'm pretty sure there are plenty of logic errors in that code, as I rushed writing it because I get excited.



#16704 Love music but not too good with code...

Posted by Bossman201 on 25 June 2012 - 12:28 AM in Ask a Pro

Not sure why you would have him broadcast a 'note on' and 'note off' message. I would use this for the computers behind the noteblocks:
local note = "whatever note you want to play" --ex. E F G A B C D including sharps and flats
while true do
 id, message = os.pullEvent("rednet_message")
 if message == note then
  --handle redstone turn-on state
  --turn off redstone state
 end
end
Make the clients turn off redstone themselves, no reason to add extra network overhead. Note: This loop will run forever, that was intended.

As for the server, I would create a program that loads a table from a file into memory and then will broadcast each value in the table, using a timer to regulate your time BPM.
local iBPM = nil
if tSong[1] ~= "nil" then --Yes, this is a string because leaving a nil key in a table is poor programming etiquette, if you ask me.
 iBPM = 60 / tSong[1]
else
 print("Enter BPM: ")
 iBPM = 60 / tonumber(io.read())
end
tTimer = os.startTimer(iBPM)
A value could be added in the beginning of the table(example above) to indicate the BPM(beats per minute) of a song. My example breaks down BPM into BPS as timers use seconds, not minutes; Which is how I'd keep track of BPM.

Ideally you would want your timer to cycle at least 64(must be base 2, as that's how music works) times per measure, but that could cause too much overhead/exponential increases in memory required by the table as most entries will be 0 or "nil". Then I'd use a code like this to read/broadcast:
local terminate = false
local iBPM --previously declared, just here so you do not forget
local i = 3
local iEnd = tSong[2] --need some internal way to tell the end of the song, table length stored in entry 2. Just thought of a better way using #tSong but I'm not going to change the code a third time.
while terminate == false do
 evt, p1 = os.pullEvent("timer")
 if p1 == "tTimer" then
  tTimer = os.startTimer(iBPM)
 end
 rednet.broadcast(tSong[i])
 i = i + 1
 if i == iEnd + 1 then
  terminate = true
end
end

One problem with this is that your song can only play one note at a time so your solution is to use matrices or do some fancy parallel API shit. Which I don't know.

I planned to create a music editor, music player, and a turtle program to set up your player, based on what I've described above. But I couldn't find a good spot for it, so the project was scrapped (biggest reason why my projects fail is that they're never even started).

Sources: I know a bit about music too

EDIT: After editing for the 10999th time, and reformatting my code each time, I decided that someone needs to fix that about the forums. EDIT OF EDIT: There was something important I wanted to add to this post code-wise, but I can't remember what it was... Oh I remember now.

Since there are multiple instruments, it would be wise to add that into the entry before what actual note is played, here's an example table.
local tSong = {1 C, 2 E, 5 F, 2 G, 3 A, 4 B}
You won't have to change the client code that I posted in the beginning of the post, you must merely change the contents of variable 'note' to include which instrument it is.



#16696 term.exit() : Attempt to call nil

Posted by Bossman201 on 24 June 2012 - 11:20 PM in Ask a Pro

View PostGravityScore, on 24 June 2012 - 01:26 PM, said:

Thanks for the reply, but unfortunately, this does the same thing as term.exit(), it quits the program, but still displays the error "attempt to call nil"
Neither function exists.


View Postkazagistar, on 24 June 2012 - 02:21 PM, said:

os.exit() does not exist, and mad was wrong. There is no actually "exit" command because it does not make sense in the lua context. Whenever you run a file, you are running the contents "as if it was a function". How do you exit a function? You either let it reach the end, or you use a return statement. You can just use an empty return statement, but just remember that it has to be at the end of a block: in other words, you have to have an "end" or the end of the file right afterwards.
It is important to note that you can have multiple return calls in a function. It's useful to put them in 'if' statements and run a variable through the function to get different outputs.



#16694 fs.open("filename", "a") Question

Posted by Bossman201 on 24 June 2012 - 11:14 PM in Ask a Pro

Try:
file.writeLine(message)


View PostMysticT, on 24 June 2012 - 03:55 PM, said:

It writes to the end of the file, so if there was a newline character at the end it will start in the next line, otherwise it keeps writing in the same line.
Also, the newline character is "n".



#16691 Bossman's Programs

Posted by Bossman201 on 24 June 2012 - 10:27 PM in Programs

>looks at code to see which version is posted.

Okay, all you have to do is attach the modem before the program is run.
Oops that was for the unreleased update.

EDIT: The only setup a modem requires is rednet being opened on the side the modem is attached to, which should always be handled by the program and not the user (which is not the case in this version of Bosschat because I was testing arguments passed to programs during runtime). The first thing you need to do is create a modem with 8 stone and 1 redstone torch, (the recipe can be found here) and then attach it to a computer by sneak-right-clicking.

All you need to do is type 'bosschat' and then the side that the modem is on.
bosschat <side>
All sides: left, right, front, back, top, bottom

I don't think you need to add quotation marks (didn't really alpha test this update as much as I should have). If it doesn't work, let me know and I'll rush to push out the next update which is able to:
  • Determine routers dynamically, and
  • Open the correct side for rednet.
  • Alerts you when your modem is removed or a modem is placed, and
  • Opens rednet on the correct side when it's placed (just had an idea for a pre-release, program will dynamically close rednet if modem is destroyed/removed)



#16690 Wiki turtorial mistake?

Posted by Bossman201 on 24 June 2012 - 10:17 PM in Ask a Pro

View PostPinkishu, on 24 June 2012 - 07:49 PM, said:

Uhm, using a variable doesn't make much sense then
input == password
should work fine, if it doesn't theres something else wrong

if input == "password" then
No reason to use a variable in such a short program other than to add overhead. Just do a string check and take out variable declaration. Not sure why variable was enclosed with parentheses either, just increases program size.



#16555 encrypting

Posted by Bossman201 on 23 June 2012 - 03:33 AM in Ask a Pro

Of course, we don't have to really deal with rednet at all. You could possibly use bundled cables or regular redstone, then transmit that data in bytes/bits(if using bundles), which would be plenty secure from coders that don't format their code. Actually, bundled cables are really nice because you can have computers send/receive at the same time, simulating how real-world internet works. (an Ethernet cable is, essentially, a bundled cable) I learned a fair bit of networking in high school.

EDIT: Although, we learned about encryption, not how to encrypt. So I don't really know how to code it. All I know is obfuscation.
EDIT2: Just remembered something from when I was looking at the Lua Math Library. You could always set a random seed using
local iSeed = math.random()
local tTemp = {}
local tMessage = {}
function encrypt(t)
write your own function
return t
end
math.randomseed( iSeed )
tMessage = encrypt(tTemp)
rednet.send/broadcast([id,] tMessage)
Then you just need to obfuscate and jumble the characters, and send the seed hidden somewhere in the message. I never played with seeds much but from what I understand an identical seed will always produce identical results. Therefore the seed is your cipher.



#16552 encrypting

Posted by Bossman201 on 23 June 2012 - 03:15 AM in Ask a Pro

View PostOmegaVest, on 22 June 2012 - 07:08 PM, said:

TFoote, use Bossman201's code.
Hell yeah.

But I found a better solution than encryption. Surround routers with blocks, remove privileges to destroy blocks from players. For extra security, add another layer around the router.



#16465 encrypting

Posted by Bossman201 on 22 June 2012 - 08:20 AM in Ask a Pro

No, that is just a basic way to prepare a message for encryption. I've left plenty for OP to code on his own. He asked how to break up words which would be
local tWords = {}
for match in string.gmatch(sMessage, "[^ t]+") do
 table.insert( tWords, match .. "b" )
end
Technically, it is still encryption because...I can't read it, can you?

Quote

In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called a cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.
-Taken from wikipedia, this is exactly what my code does. The special knowledge or 'key' would be being able to tell that it's just character codes, which a lot of us can tell. So no, you're right, it's not secure. But it is encryption.



#16454 encrypting

Posted by Bossman201 on 22 June 2012 - 04:00 AM in Ask a Pro

Should be relatively secure, of course if anyone figures out how you're encrypting it, there's a very easy way to decode this.
term.clear()
term.setCursorPos(1, 1)
local iEncrypt = nil
local sMessage = nil
local tWords = {}

function NULLencrypt(tWords)  --tried to encrypt as a whole before I realized I could do it during table.insert
for i = 1, #tWords do --function NULLencrypt is not necessary in program code as it is not used
  local sTemp = nil
  for i = 1, string.len(tWords[i]) do
   if i == 1 then
	sTemp = tWords[i]:byte(i)
   else
	sTemp = sTemp .. " " .. tWords[i]:byte(i)
   end
   tWords[i] = sTemp
  end
end
return true
end

function encrypt(string)
local sTemp = nil
for i = 1, string.len(string) do
  if i == 1 then
   sTemp = string:byte(i)
  else
   sTemp = sTemp .. " " .. string:byte(i)
  end
end
return sTemp
end

term.write("Enter message: ")
sMessage = tostring(io.read())

for match in string.gmatch(sMessage, "[^ t]+") do
table.insert( tWords, encrypt(match) .. "b" )
end

for i = 1, #tWords do
print(tWords[i])
end

The way I would encrypt this would be to add another function that breaks down each "line" of output and multiplies each char code by a user-defined number. This number would then be sent at the very beginning of any rednet message so that the receiving computer can decode the message. Any computers spying will only get a string of huge numbers that won't mean anything. I probably will add this and a decoder to bosschat since I've done the legwork already.

To further screw with spy's, reverse each word before encryption, then reverse the entire table. Then laugh as they flip their tables trying to code a way around your encryption.
(╯°□°)╯︵ ┻━┻

Sample output:
Spoiler



#16437 [1.3] How To Use Modems (Rednet)

Posted by Bossman201 on 21 June 2012 - 10:10 PM in Tutorials

If you wanted to support a dynamic number of turtles without having to store all their id's you could always keep the rednet.broadcast(message/command) add encryption to the message beforehand. The turtle could read the first few values when they receive a command to decide if the message was encrypted for them. Just thinking outside the CPU- I mean box.



#16436 Bossman's Programs

Posted by Bossman201 on 21 June 2012 - 10:04 PM in Programs

View PostA2Creativity, on 16 June 2012 - 05:06 PM, said:

I can't understand... what does it do ??
Bosschat is a fully-functional chat program (with the exception of displaying whether 'caps lock' is on or off). It's got most of the features that every basic chat program has.



#16434 [Lua][Red Net][Programming] Red Net Question

Posted by Bossman201 on 21 June 2012 - 09:59 PM in Ask a Pro

Not sure why your readADV function is so long. Here's how Bosschat handles multitasking and writing characters.
function writeChar(char)  --Future update will be able to make longer messages
 term.setCursorPos(charNum + string.len(username) + 3, cursorY) --right now limit is 48 minus username length and 2 extra characters
 if charNum <= 48 - (string.len(username) + 2) then --so it all fits on-screen
  term.write(char)
  message[charNum] = char
  charNum = charNum + 1
 end
end
function handleEvent() 
 local evt, p1, p2 = os.pullEvent()
 if evt == "char" then
  writeChar(p1)
 elseif evt == "key" then
  handleKey(p1)
 elseif evt == "rednet_message" then
  messageReceive(p1, p2)
 elseif evt == "timer" then
  handleTimers(p1)
 elseif evt == "peripheral" then
  handleModem(p1)
  updatePast("Modem detected on " .. p1) --custom function that will display messages, pass message as parameter.
  updatePast("Network restored.")
 elseif evt == "peripheral_detach" then
  updatePast("Modem detached on " .. p1)
  updatePast("No network connectivity.")
 end
end
Also, small preview for next update.



#16433 coding error

Posted by Bossman201 on 21 June 2012 - 09:44 PM in Ask a Pro

If you're trying to increment a for loop by one, then you don't need the third parameter as it increments by one by default.

EDIT: Also you left 'for' out of your code on line 6, which is probably why you got 'then' expected error.



#15959 [Question]How does the shell handle arguments?

Posted by Bossman201 on 16 June 2012 - 07:24 PM in Ask a Pro

Mystic I'm glad you used 'in pairs' in your example, I've seen it in the default programs and I'm wondering what it does and how to use it?

Thanks guys, I think I understand it now.

EDIT: (I haven't looked at the manual or lua library yet)For unpack, I'm thinking it returns all of the values in a table. Which, by your code, would be given to a program as arguments. Not sure what the second argument is though. Is that right?



#15920 [Question]How does the shell handle arguments?

Posted by Bossman201 on 16 June 2012 - 01:54 AM in Ask a Pro

I'm sure I understand this bit of code, will comment on what I think each line does/mean.
local tArgs = { ... } --Array containing all arguments
if #tArgs > 0 then --'#' returns index of an array, line checks tArgs to make sure there is at least one value.
print( "" ) --Prints program usage or coder-defined action.
print( "" )
return  --good practice to return all functions, I do not do it but I may have to start.
end

My question is basically how can I emulate this inside a program? I want to decode a message from rednet into "arguments" and then pass these to a function.

Bonus question (for bonus points): What does the ellipse in lua mean? (ex. '...')



#15918 Door Lock.

Posted by Bossman201 on 16 June 2012 - 01:18 AM in Ask a Pro

Code works fine when I run it. Couple things I've noticed, though.

1. Use some kind of formatting.
2.
sleep(5) -- should be sleep(openTime)
3.
rs.setOutput(side, true)
rs.setOutput(side, false) --no sense in creating and keeping track of a variable you do not need, rs.setOutput("left", true) will do just fine.