Wikipedia:Reference desk/Archives/Computing/2017 April 22

= April 22 =

need help with assignment in Unity/C#
My daughter is having a problem with an assignment in Unity/C#. This is a two-player game. The arrow keys control the first player and the W-A-S-F keys control the second player. She had this working but she added to the program and the W-A-S-F keys quit working for the second player. I think it must be something simple, but I don't know this language. Can someone help a little?

Thank you. Bubba73 You talkin' to me? 02:24, 22 April 2017 (UTC)


 * Without looking at the code, I suggest she goes back to the previous working version of the code, then adds in as little as possible at a time, until it breaks again. This should help to isolate the problem.  You could also list the previous, working version here, so we can do the same. StuRat (talk) 02:53, 22 April 2017 (UTC)


 * She sent me the code in a Word file, with the changes she had made highlighted. I've commented out those lines.  Bubba73 You talkin' to me? 03:13, 22 April 2017 (UTC)

Two obvious first things to check : ApLundell (talk) 03:29, 22 April 2017 (UTC)
 * Make sure the player object is still tagged "Player1". That would be easy to accidentally change in the editor, and would cause this code to assume the player was player two. (And thus not affected by WASD.) Oh. I misread the question. I thought player 1 was the stuck one.
 * Make sure the script is actually running. Unity scripts can fail surprisingly gracefully with just an error in the log window. Perhaps there's a null reference somewhere and you're not noticing the error because you're staring at the character who stubbornly refuses to move.
 * It looks like "speed"(really acceleration) is set in the editor. Make sure it's been correctly set for both players.
 * There's also a bit of a logical oddity here. This script looks like it will be attached to each player individually, but it contains as member values both player's scores. At best this is redundant, at worst it could cause the scoring to be inconsistent. ApLundell (talk) 03:40, 22 April 2017 (UTC)


 * In her note to me, she says that the players share the script:
 * "Horizontal2 and Vertical2 are keyed to wasd (for Player2).


 * Changes are highlighted including. I commented out a line from the original code so I highlighted just the slashes. Before the changes Player2 responded to wasd, and the code worked properly. Now Player2 is unresponsive. Player1 has always responded.


 * Two different objects (Player1 and Player2) share the following script." Bubba73 You talkin' to me? 03:51, 22 April 2017 (UTC)


 * They don't exactly share a script. They each have their own instance of it. I'm not sure she understands that.
 * In general there's a lot of confusion here trying to use local variables as globals. Typically you'll want to create a singleton "game manager" or "game controller" that has score and stuff, and then the player code can interact with that.
 * Here's a simple example from one of the official Unity video tutorials. A "game controller" script is attached to an empty object in the scene. (Notice how the DestroyByObject script in that example does a FindByTag call, then it has a reference to the game controller and can then access its public members.)
 * https://unity3d.com/learn/tutorials/projects/space-shooter-tutorial/counting-points-and-displaying-score
 * All that said, I can't identify the specific bug that would cause the exact problem described. Hope something I said helps with her assignment. ApLundell (talk) 04:03, 22 April 2017 (UTC)

Oh. I think I have an idea. pOS and pTS are references, but there's no check if they're null. These are variables you've indicated are newly added. Because of the way she's got her scripts set up, she would have to manually set these variables in the editor twice. If she didn't set both of them for each player, it would hit a Null Reference Exception, and bail out of the FixedUpdate function for that player. I'll bet that's it. ApLundell (talk) 04:12, 22 April 2017 (UTC)
 * Thanks - I sent her a link to all of this but she went to bed about 2 hours ago. She'll see it tomorrow. Bubba73 You talkin' to me? 04:26, 22 April 2017 (UTC)
 * Hello Bubba73's daughter! I hope something in my above rambling is helpful! ApLundell (talk) 04:33, 22 April 2017 (UTC)

She has player 2 working now. She thinks it was because the text displaying the scores was in FixedUpdate instead of Update. Bubba73 You talkin' to me? 15:41, 22 April 2017 (UTC)
 * That's good... But I hope she's also sorted out how she's doing the scoring. In object oriented programming, two instances of an object don't share member variables.They each have their own. ApLundell (talk) 17:34, 22 April 2017 (UTC)


 * , this is just a quick infodump, but you can use to produce better looking code in posts like these. I had actually changed it last night and was going to make a note, but I hit an edit conflict and then had to deal with my kids, and then forgot all about it (I just went ahead for the hell of it and so you can see what it looks like with this edit). I'm glad to see the problem got resolved.  ᛗᛁᛟᛚᚾᛁᚱPants   Tell me all about it.  17:40, 22 April 2017 (UTC)


 * Programmers have gotten so soft. Back in my day, we punched Fortran on cards.  No syntax highlighting - everything was upper case.  No indentation or blank lines either.  And rarely a blank space that wasn't required.  :-)  Bubba73 You talkin' to me? 21:00, 22 April 2017 (UTC)
 * (be sure to turn annotations on). ᛗᛁᛟᛚᚾᛁᚱPants   Tell me all about it.  23:31, 22 April 2017 (UTC)

Public key signatures
I have recently been introduced to public key cryptography. I came across this problem and I'm not sure how to approach it. If I send someone an encrypted message signed with my signature key, what's to prevent them from encrypting it again and sending it to other people pretending the message is directly from me?

Perhaps I haven't gotten my head around how public key signatures work. If my friend sends me a message signed by him, and I forward it to other people, they will think it's from him right? I'm assuming there is something I'm missing to prevent this situation.--Testing questions (talk) 15:05, 22 April 2017 (UTC)


 * If A writes a letter to B which begins "Dear B" and signs it with his (A's) private key, then B can't send it to C and convince C that A sent it directly to C, because of the salutation. Similarly, if it's an email message, it will have a To field in the header which identifies whom A sent it to.  Of course B can't change the salutation or To header without invalidating the signature.  On the other hand, if it's not a message but some other type of document which isn't specifically addressed to B, then B can indeed forward it to C via some unauthenticated channel and convince him that it came directly from A.  It's up to C to recognize that the channel is insecure even though the message is signed.  But in most cases this would be of limited value to B since A did indeed write the document, and the only thing B is spoofing is whom A sent it to. CodeTalker (talk) 15:42, 22 April 2017 (UTC)
 * So should you always try to directly address the recipient? What about certificates? Can they prevent recipients encrypting the message again and sending it to someone else?--Testing questions (talk) 15:50, 22 April 2017 (UTC)
 * The signature should verify that the exact text of the message was encrypted by the original author. You couldn't alter it and preserve that signature.
 * You could copy/paste the text into a new email, and add your own signature, taking credit for the other person's work. Or you could send the whole thing, signature and all, to a third party, but you couldn't alter it and then reapply the original person's signature. ApLundell (talk) 17:40, 22 April 2017 (UTC)
 * There's, of course, an article at Digital signature that is pretty good. ApLundell (talk) 17:43, 22 April 2017 (UTC)
 * The case where you "send the whole thing, signature and all, to a third party" is what I am interested in. That third party would believe it was sent directly to them from the signer with no intermediary. The signer may not have wanted them to see it. CodeTalker helpfully mentioned including salutations that the third party would notice. However, are there any technical means to prevent this happening? Is the only solution for the third parties be expected to do proper authentication so they know who the actual sender is? Is the anything the original signer do to prevent this situation?--Testing questions (talk) 19:02, 22 April 2017 (UTC)
 * Public key cryptography, by itself, has no concept of sending, receiving, or anything like that. All you get is blocks of data that are encrypted and/or signed. Public key crypto doesn't say anything about how those blocks are moved around, only where they come from and what can be done to them. If you wanted a cryptosystem that did verify *who* transmitted data, and what means it took to get to someone, you would have to build a more sophisticated system which included that information, and protected it appropriately with the relevant checks. In this case, as in most other applications of cryptography for data security, the actual crypto is the easy bit - building a worthwhile, workable system that solves real-world problems (using those basic cryptographic building blocks) is difficult, and quite apt leaving weaknesses which arise not from the crypto itself, but from the difficulties of using it safely. -- Finlay McWalter··–·Talk 19:46, 22 April 2017 (UTC)


 * Correct, what you're asking about is essentially an authenticated email system. Public key cryptography might be a component of such a system (as it is for DKIM for instance), but PKC by itself doesn't address such issues as authenticating the sender of a message, preventing spoofed resends, etc.  CodeTalker (talk) 19:18, 23 April 2017 (UTC)


 * This is a real risk (it has been used to steal real money, in 10k+ amounts). Crypto is still so unfamiliar that almost all end-users have no real appreciation for what's happening or what they've received. This makes them prone to being deceived. A simple attack is to take something that is provably (and genuinely) from a trusted source, add some fraud, then wrap it up further with a technically valid signature from the overall fraudster. Every part of this is cryptographically valid (and so the tools don't highlight it as suspicious). The deception is to mislead the recipient as to who is vouching for what parts of it. Yet again, we're back to simple social engineering, which most software still doesn't watch out for.
 * As a learning tool, I'd suggest the command line version of OpenPGP and working with it to do a large number of tasks (many web guides) to become familiar with it long before you need to use such tools in any real-world situation. Then follow Bruce Schneier's blog. Andy Dingley (talk) 12:12, 24 April 2017 (UTC)
 * That's an interesting suggesting I will check out, thank you.--Testing questions (talk) 15:28, 25 April 2017 (UTC)