• What are you working on? v15
    5,001 replies, posted
[QUOTE=Richy19;27278755]if else if else if else[/QUOTE] [QUOTE=CommanderPT;27278687]...So that I don't have to write multiple if statements.[/QUOTE] [editline]8th January 2011[/editline] Don't know any other way than (username.equals(u1) && username.equals(u2) && username.equals(u3))
[QUOTE=Xeon06;27274439]Took a break from my main project to try out an idea I had: JavaScript multiplayer game. It worked out... kinda. You can try it (using Chrome preferably): [url]http://www.alexturpin.net/ajaxtest/[/url] Arrow keys to move. You're the blue guy. Of course there's a lot of latency seeing as this is HTTP, and you have to go check if there are any updates for you seeing as you can't directly "receive" stuff. I think it could work for a slow-paced game, maybe turn-based like chess or such.[/QUOTE] Have a look at HTML5 Websockets.
[QUOTE=CommanderPT;27278687]I know that there is a help thread but I never got any help there. Can somebody just help me real quick with this: [code] if(username.equals(u1)){ do stuff else do other stuff } [/code] A very basic IF statment. The thing is, can I make it so that it checks if username.equals several different things? I got three usernames and I want to check them all, so it is basically like if username.equals(u1, u2, u3); Is this possible? So that I don't have to write multiple if statements.[/QUOTE] if (username == u1 || username == u2 || username == u3)
[QUOTE=iNova;27278791][editline]8th January 2011[/editline] Don't know any other way than (username.equals(u1) && username.equals(u2) && username.equals(u3))[/QUOTE] It would need OR statements (username.equals(u1) || username.equals(u2) || username.equals(u3)) But that is the same as an if, else if except it doesnt allow to do different things when diferent people log in
[QUOTE=PiXeN;27278928]if (username == u1 || username == u2 || username == u3)[/QUOTE] But of course. So simple! Thank you and to rest who posted as well.
[QUOTE=PiXeN;27278928]if (username == u1 || username == u2 || username == u3)[/QUOTE] Wouldn't and be more appropriate in this case? Seeing as he wants to check if it's equal to them all.
[QUOTE=iNova;27278956]Wouldn't and be more appropriate in this case? Seeing as he wants to check if it's equal to them all.[/QUOTE] And would be if username equals all three u1, u2 & u3 But technically thats imposible
Usually a value only equals to exactly one other value.
[QUOTE=ZeekyHBomb;27279011]Usually a value only equals to exactly one other value.[/QUOTE] Not if all the other values are the same? I'm guessing u1 u2 u3 are variables here, not strings so it's very possible.
[QUOTE=iNova;27279031]Not if all the other values are the same? I'm guessing u1 u2 u3 are variables here, not strings so it's very possible.[/QUOTE] Um, they are strings. Names to be exact, I want it to check if what the user enters matches any of them. Edit: It appears to work when I use the method Richy19 posted.
[QUOTE=CommanderPT;27279052]Um, they are strings. Names to be exact, I want it to check if what the user enters matches any of them. Edit: It appears to work when I use the method Richy19 posted.[/QUOTE] Ahh, I see. You didn't specify if any or all :buddy: Mine works if you want to check if it's equal to all of them.
[QUOTE=iNova;27279172]Ahh, I see. You didn't specify if any or all :buddy: Mine works if you want to check if it's equal to all of them.[/QUOTE] The problem is that if I enter u1's username and u2's password it still works. [editline]8th January 2011[/editline] [code] [b]loginbutton.addActionListener(new loginaction());[/b] //Possible to add anything here that makes for example, a JFrame appear or dissappear? } } class loginaction implements ActionListener{ public void actionPerformed (ActionEvent e){ String u1 = "Peyman Torabi"; String p1 = "doodle"; String u2 = "Gordon Freeman"; String p2 = "crowbars4life"; String u3 = "Duke Nukem"; String p3 = "boombaby"; String username = JOptionPane.showInputDialog(null,"Enter username"); String password = JOptionPane.showInputDialog(null,"Enter password"); if(username.equals(u1) || username.equals(u2) || username.equals(u3)){ if(password.equals(p1) || password.equals(p2) || password.equals(p3)){ JOptionPane.showMessageDialog(null, "Access granted!"); }else{ JOptionPane.showMessageDialog(null, "Access denied. Username and/or password incorrect!"); } }else{ JOptionPane.showMessageDialog(null, "InCorrect"); } } } [/code] This is a larger chunk of the program that I am working on. It is very simple, I am not very good at programming yet. I am just wondering, is it possible to make for example, a window disappear when the action listener is triggered? A window that is in the main class.
[QUOTE=CommanderPT;27279200]The problem is that if I enter u1's username and u2's password it still works.[/QUOTE] Because you're checking if it matches any of the usernames and any of the passwords. Check passwords by the specified username.
[QUOTE=iNova;27279237]Because you're checking if it matches any of the usernames and any of the passwords. Check passwords by the specified username.[/QUOTE] Guess I'll have to have several if statements then instead of just one. So that if it finds a username it will check the respective password.
Wouldn't a user list indexed by username containing password work? Assuming you have the library to do it: [code] if(Users.ContainsKey(uX)) { if(Users[uX] == GivenPassword) { // Valid user } else { // Invalid password } } else { // Not a valid user } [/code] Though it may be a sledgehammer to crack a nut. In C# this would be a Dictionary<string, string>.
[QUOTE=CommanderPT;27279267]Guess I'll have to have several if statements then instead of just one. So that if it finds a username it will check the respective password.[/QUOTE] If, else if would probably be easier but i think you could also do [code]( (username.equals(u1) && password.equals(p1)) || (username.equals(u2) && password.equals(p2)) || (username.equals(u3) && password.equals(p3))[/code] But as i say the only way to make it like an OS where each user has his own settings and such would be to use if, else if
Ok I got a working system now. It is rather messy but it works for this since it will only contain three users. [cpp] if(username.equals(u1)) { if(password.equals(p1)){ JOptionPane.showMessageDialog(null, "Correct"); }else{ JOptionPane.showMessageDialog(null, "InCorrect"); } } else if(username.equals(u2)) { if(password.equals(p2)){ JOptionPane.showMessageDialog(null, "Correct"); }else{ JOptionPane.showMessageDialog(null, "InCorrect"); } } else if (username.equals(u3)) { if(password.equals(p3)){ JOptionPane.showMessageDialog(null, "Correct"); }else{ JOptionPane.showMessageDialog(null, "InCorrect"); } } else { JOptionPane.showMessageDialog(null, "Wrong"); } [/cpp] The dialog boxes will later be replaced with some actual useful stuff. [editline]8th January 2011[/editline] [QUOTE=Richy19;27279380]If, else if would probably be easier but i think you could also do [code]( (username.equals(u1) && password.equals(p1)) || (username.equals(u2) && password.equals(p2)) || (username.equals(u3) && password.equals(p3))[/code] But as i say the only way to make it like an OS where each user has his own settings and such would be to use if, else if[/QUOTE] Oh, that seems a lot easier and less typing. Using that it will only check if there is a set? as in u1 has p1. Meaning if u2 types in p3 it won't work?
[QUOTE=Overv;27278107]Finished a little mockup of my Facepunch for Android app. With the current design, you will be able to reply and rate by holding down your finger on a post and using a popup menu. [img_thumb]http://www.imgdumper.nl/uploads3/4d27f4e23d9ad/4d27f4e233982-Facepunch_android_mockup_device_small.png[/img_thumb][/QUOTE] Do want, would make it look so much better on Android.
[QUOTE=CommanderPT;27279382]Oh, that seems a lot easier and less typing. Using that it will only check if there is a set? as in u1 has p1. Meaning if u2 types in p3 it won't work?[/QUOTE] Well i havent actually tried it so dont take my word but it should only do the code if say: U1 && P1 are correct, so if you enter U2 and P3 then it shouldnt work
[QUOTE=Richy19;27279448]Well i havent actually tried it so dont take my word but it should only do the code if say: U1 && P1 are correct, so if you enter U2 and P3 then it shouldnt work[/QUOTE] I can try it and if it works I'll get you a virtual cookie. [editline]8th January 2011[/editline] Holy Batman, it works! And it looks a whole lot better too. Mine was just a mess. Thank you. [img]http://2.bp.blogspot.com/_53oMB4-fxXM/SVZZdJntnPI/AAAAAAAAAAM/vXEtrdBFtqI/s1600-R/cookie.gif[/img] You deserved it!
[QUOTE=Tezzanator92;27279279]Wouldn't a user list indexed by username containing password work? Assuming you have the library to do it: [code] if(Users.ContainsKey(uX)) { if(Users[uX] == GivenPassword) { // Valid user } else { // Invalid password } } else { // Not a valid user } [/code] Though it may be a sledgehammer to crack a nut. In C# this would be a Dictionary<string, string>.[/QUOTE] In my opinion his current approach is overcomplicated, but of course easier to understand. In Java this could be done with HashMap<String, String> for example: [code] // Untested code below written straight into reply box. HashMap<String,String> users = new HashMap<String,String>(); public boolean CredCheck (String username, String password) { boolean success = false; if (users.containsKey(username)) { String correctpass = (String) users.get(username); if (password.equals(correctpass)) { success = true; } } return success; } [/code] And voila, you have support for as many users as you want. Use the [URL=http://download.oracle.com/javase/1.4.2/docs/api/java/util/HashMap.html#put(java.lang.Object, java.lang.Object)]put[/URL] method to put your users in the map.
Where did the thread for GWEN go? I tried searching for it but it won't come up. Oh well, I guess I'll rewrite that old SFML2 renderer from scratch then.
[QUOTE=Spoco;27279961]In my opinion his current approach is overcomplicated, but of course easier to understand. In Java this could be done with HashMap<String, String> for example: [code] // Untested code below written straight into reply box. HashMap<String,String> users = new HashMap<String,String>(); public boolean CredCheck (String username, String password) { boolean success = false; if (users.containsKey(username)) { String correctpass = (String) users.get(username); if (password.equals(correctpass)) { // Do whatever success = true; } } if (!success) { // Wrong username or password } return success; } [/code] And voila, you have support for as many users as you want. Use the [URL=http://download.oracle.com/javase/1.4.2/docs/api/java/util/HashMap.html#put(java.lang.Object, java.lang.Object)]put[/URL] method to put your users in the map.[/QUOTE] You can make such systems much more secure if you don't return which was incorrect: the username or the password. EDIT: Aww shit, I was looking at the code in the quote you made. Silly me.
[QUOTE=sim642;27280049]You can make such systems much more secure if you don't return which was incorrect: the username or the password.[/QUOTE] I didn't?
So a friend of mine told me he can draw pretty good and he wanted to make some games, so he bought a cheap tablet, got photoshop and I code. We first decided to make a doodle-jump-thing to get into it or whatever, and: [img]http://filesmelt.com/dl/jump.png[/img] I mean, the background is kind of okay I guess, but what the hell is wrong with the player? [img]http://filesmelt.com/dl/player123.png[/img] :geno: The top version is the image he gave me, no it's not scaled. He also drew tim from braid: [img_thumb]http://filesmelt.com/dl/braid.jpg[/img_thumb] Plus he has weird design ideas. He made me program it so that you can wait on platforms and use space to jump. What am I gonna do? I can't just tell him it sucks. I hope he doesn't browse FP and finds this here. He'd be mightily pissed. [editline].[/editline] I have now spent 20 minutes trying to explain why I need the grass seperately (Because it's only on the ground) and why the background should be vertically tileable (It scrolls). He doesn't get it. Behold; his interpretation of a tileable sky (I told him "They have to seamlessly connect top to bottom"): [img]http://filesmelt.com/dl/notsotileable.png[/img] I feel so bad for making fun of him.
[QUOTE=Maurice;27280793]So a friend of mine told me he can draw pretty good and he wanted to make some games, so he bought a cheap tablet, got photoshop and I code. We first decided to make a doodle-jump-thing to get into it or whatever, and: [img_thumb]http://filesmelt.com/dl/jump.png[/img_thumb] I mean, the background is kind of okay I guess, but what the hell is wrong with the player? [img_thumb]http://filesmelt.com/dl/player123.png[/img_thumb] :geno: He also drew tim from braid: [img_thumb]http://filesmelt.com/dl/braid.jpg[/img_thumb] What am I gonna do? I can't just tell him it sucks. I hope he doesn't browse FP and finds this here.[/QUOTE] [img]http://img.photobucket.com/albums/v290/Eteponge/Frequent%20Use%20Icons/HA_HA_HA_OH_WOW.jpg[/img] [highlight](User was banned for this post ("Image macro" - SteveUK))[/highlight]
[QUOTE=iRzilla;27278900]Probably some shitty unoptimized format not built for maps at all. Like XML or JSON. [editline]lol[/editline] Lol @ Notch fans rating me dumb.[/QUOTE] I don't care about Notch, you're just being a prick. With both those statements.
[QUOTE=Maurice;27280793]So a friend of mine told me he can draw pretty good and he wanted to make some games, so he bought a cheap tablet, got photoshop and I code. We first decided to make a doodle-jump-thing to get into it or whatever, and: [img_thumb]http://filesmelt.com/dl/jump.png[/img_thumb] I mean, the background is kind of okay I guess, but what the hell is wrong with the player? [img_thumb]http://filesmelt.com/dl/player123.png[/img_thumb] :geno: The top version is the image he gave me, no it's not scaled. He also drew tim from braid: [img_thumb]http://filesmelt.com/dl/braid.jpg[/img_thumb] Plus he has weird design ideas. He made me program it so that you can wait on platforms and use space to jump. What am I gonna do? I can't just tell him it sucks. I hope he doesn't browse FP and finds this here. He'd be mightily pissed.[/QUOTE] Of all the things wrong about it, this might be a weird thing to pick up on, but why is his left thumb huge compared to his right?
[QUOTE=Maurice;27280793]So a friend of mine told me he can draw pretty good and he wanted to make some games, so he bought a cheap tablet, got photoshop and I code. We first decided to make a doodle-jump-thing to get into it or whatever, and: [img_thumb]http://filesmelt.com/dl/jump.png[/img_thumb] I mean, the background is kind of okay I guess, but what the hell is wrong with the player? [img_thumb]http://filesmelt.com/dl/player123.png[/img_thumb] :geno: The top version is the image he gave me, no it's not scaled. He also drew tim from braid: [img_thumb]http://filesmelt.com/dl/braid.jpg[/img_thumb] Plus he has weird design ideas. He made me program it so that you can wait on platforms and use space to jump. What am I gonna do? I can't just tell him it sucks. I hope he doesn't browse FP and finds this here. He'd be mightily pissed. [editline].[/editline] I have now spent 20 minutes trying to explain why I need the grass seperately (Because it's only on the ground) and why the background should be vertically tileable (It scrolls). He doesn't get it.[/QUOTE] This is what happens when you work with friends.
:D [img_thumb]http://img831.imageshack.us/img831/5994/untitlebd.png[/img_thumb]
Sorry, you need to Log In to post a reply to this thread.