Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea Chat Room

edited August 2013 in Code Sharing Posts: 1,976

Briarfox and I have been working on a project for a little while... a chat room for Codea! I finally said it was polished enough to share with the world, and here it is. When you start, you'll be asked to enter your name. Enter your Codea Forums username in the "Username" text box, then press "Submit." Now you can press the bar at the bottom of the screen and type in a message. The chat is synced every second, so you're up to date.

Installer: Link.

«1

Comments

  • BriarfoxBriarfox Mod
    Posts: 1,542

    Nice proof of concept :)

  • Posts: 226

    Brilliant!

  • dave1707dave1707 Mod
    Posts: 8,554

    Here comes the bugs. When selecting Forum in the upper right corner then selecting Done to return back to the chat room, the screen goes black. Codea has to be closed to get back into the Chat Room. Also, can the font size be changed to keep more lines on the screen.

  • Posts: 1,976

    @dave1707 The first is a known bug, it crashes the first time you use the forums button, but after that it works fine. As for the second, try dragging your finger on the screen to scroll. ;)

  • edited August 2013 Posts: 226

    ... and please add a weapon for dropping a flying cat ;)

  • dave1707dave1707 Mod
    edited August 2013 Posts: 8,554

    I tried the Forums button 4 times and all 4 times it goes to a black screen when I exit the forum. Is there a way around the black screen or is closing Codea the only way back to the Chat Room. Never mind about the fontsize, I can change that in draw to whatever size I want.

    EDIT: I had to change the code so there wasn't so much space between the lines after I lowered the fontsize. I also removed the supportedOrientation so it worked in portrait mode.

  • Posts: 1,976

    @dave1707 That's odd about the forums button, it crashed randomly for me, too, once. And the font size does not need to be changed, you can just scroll by dragging.

  • dave1707dave1707 Mod
    Posts: 8,554

    I changed the fontsize, the space between the lines, and removed the supportedOrientation. So far so good, except for the black forum screen.

  • Posts: 1,976

    The supported orientations call is because it glitches in portrait mode.

  • Posts: 2,043

    The forums button works for me, it's how i just got here

  • BriarfoxBriarfox Mod
    Posts: 1,542

    I'm wondering if there is a bug in openURL() I have this issue in another project. Sometimes closing the url will not continue with the draw loop. That is why the screen is blank. The only fix is to completly clear codea from memory. The draw loop is fired one time after openURL is called. Then it pauses until closed. Sometimes it does not come back.

    Anyone know of a fix?

  • Posts: 2,043

    Is there any way to get more to show up? What I mean is, when I go on, I can't go back and see previous conversation.

  • edited August 2013 Posts: 1,595

    I just tried this out and got this error:

    error: [string "Server = class()..."]:99: attempt to concatenate field 'user' (a nil value)
    
  • IgnatzIgnatz Mod
    Posts: 5,396

    Yep, I got that too

  • dave1707dave1707 Mod
    Posts: 8,554

    Did you enter a user name. If not try adding this to the beginning of setup.


    saveLocalData("Chat_User", "your Codea user name")
  • Posts: 2,043

    I got that error too, I just opened up the side window, changed my user name in the text box, and hit the button below, then un paused it and it worked

  • Posts: 1,976

    Odd... I'll look into it.

    @JakAttak You can scroll by dragging on the chat text.

  • Posts: 2,043

    But I can't go up past when I logged in

  • Posts: 1,976

    I'm uploading a fix right now.

  • Posts: 1,976

    @JakAttak You can't see before you logged on because the server clips everything to a maximum of five messages. It doesn't store the previous chat cache because then it would look funny, seeing what you saw maybe a few hours ago right before the new text.

  • Posts: 437

    Hey, try to use a NoSQL database like MongoDB, it will be faster and cheaper in space ;)

  • edited August 2013 Posts: 4

    @juaxix, @SkyTheCoder

    Or throw away the PHP/MySQL and roll your own little server in Lua using sockets for the network-y bits and tables for state.

    PHP is a nightmare - one of the worst things to happen to coders since the dawn of dynamic content. MySQL is its counterpart. They're both very popular, but, as far as I can work out, only because they're free.

    Given the relative simplicity of what you're doing, it'd probably be cleaner, easier (once you've grokked a couple additional APIs), and, most of all, much more fun.

    You guys already know Lua, so you're already on your way. And everything you'd have to do server-side would only teach you more.

    You could design your own simple protocol, which would save you from yet another evil (HTTP). You'd still have to deal with HTTP headers, but you could use that to your advantage.

    And, I guarantee, if you do a good job of the protocol, you will have learned everything you need to learn in order to write a snazzy client-side command parser (right now you're using gsub's scattered throughout your code - all of that can be consolidated into a clean, centralized block of awesomeness).

    What you've already done is harder than what you would have to do. Your project is a really impressive collection of square pegs fit into round holes (the nature of a chat application goes against everything that PHP and HTTP are about).

    Also, it probably isn't clear from my tone, but I'm complimenting you. You really have done something cool. Taking a collection of technologies that were meant to do something completely different from what you're doing is the definition of "hack" (which is good).

  • Posts: 157

    If you want to get technical about it, the proper way to do it would be a compiled, typesafe language and an enterprise class database.

    Personally, I'm fond of using CGI, rather than interpreted scripts. Yes, it's an old model, but it's perfect for what it's designed for. I think they should entirely throw out the runtime interpreted script code and write the whole thing in C++. They should also buy an Enterprise license of Oracle or SQL Server to make sure that they get the performance and stability that they need.

    :-))

    Obviously there's nothing wrong with using PHP, as long as you're not a noob. No, PHP is not typsafe. Yes, you can do horrible, horrible things that would make any software engineer scream with pain and make the good folks over at thedailywtf.com shout with glee.

    You can do the same with Lua. Self-modifying code? No problem. Pass a string into a method expecting an integer? Who needs all that pesky type checking anyway?

    There are days I wish we could go back to MS BASIC running on 8-bit computers...

  • edited August 2013 Posts: 4

    @tomxp411

    C++ for a simple, fun chat server is going in the wrong direction. So is tying it all to a heavy database.

    Yes, you get type safety with C, but the number of disasters awaiting you down that route make it a bad choice.

    And, yes, Lua also has a few gotchas that can lead to problems, but, again, this is about making a simple chat server for fun.

    You can do a good job with either language and you can do a bad job with either language, but it's fair to say you're going to do a better job if you can focus on the meat of your app rather than trying to understand pointers and manual memory management (which is messy even when you have an implementation of C that helps you out, as is the case with Objective-C).

    If you're worried about injection in Lua, there are plenty of ways to safeguard your code. One is to fiddle with environments. Another is to round up the potential offenders (load*) and assign nil to them all. If you still need them for your own app, you can come up with identifiers of your own choosing ("loadrenamedhahnobodywillfindmehere", for example) and then assign nil to the originals. Take your pick.

    Even old school BASIC is more trouble in some ways. DEF SEG and VARPTR come to mind.

    If, in the end, you still want C (for some reason), you can always code whatever bits you like in your preferred flavor of the language and then use Lua as it was originally intended: a library. That's what the Lua interpreter does, and it's also one of the reasons Lua is a good choice for coding directly on your iWhatever.

    But the most important point really is: Fun. And that's something Lua does very well.

  • edited August 2013 Posts: 157

    You missed the <sarcasm>. :) everyone is bagging on Sky and Briarfox's choice of scripting languages, when the truth of the matter is that these guys are turning out some excellent work, considering the limitations they are working under.

    People saying stuff like "use a nosql database" or "use sockets, not http" are missing the point. These guys have a fairly limited set of tools to work with and are still doing good work. They should be cheered, not criticized because they didn't use someone's favorite database or language.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Agreed. They're just having fun, and trying out stuff, not building the next Skype.

  • Posts: 2,161

    Now if they'd written it in TeX, I would have been impressed.

  • Posts: 1,976

    @Ignatz Funny, I was literally thinking about making a video chat program a few days ago...

    This chat room will hopefully have some more features in the future including clickable links, pictures, emoticons, etc.

    @Andrew_Stacey TeX?

  • edited August 2013 Posts: 157

    2 things I've noticed with a Bluetooth keyboard:

    1. I still have to tap the text area to send a message. It would be nice if that's always active when the keyboard is connected.
    2. Even with the BT keyboard, the text area still gets pushed halfway up the screen.

    I'm guessing that #2 is caused by the fact that the runtime don't have the API necessary to determine whether a BT keyboard is connected...

    Also, is there a user list? It would be nice to know who's logged in. =)

  • edited August 2013 Posts: 226

    Wow! I still can't believe that this nice piece of work was programmed by a 12 years old boy! :-O

    Edit: I'm 3.7 times that age and still strugglig with table.insert!

  • Posts: 1,976

    @tomxp411 I'm going to add a "Bluetooth mode" switch that toggles the text field being pushed up when you are typing. Without it pushing up, using the soft keyboard, you can't see what you're typing. Sadly, there's no way to automatically detect a BT keyboard. If I could, I would make it not be pushed up.

    And I've chatted with people about a user list, but I've decided there's too many problems with the idea. It could tell when someone logs on or off by the joining/leaving messages, but if say, someone crashes, it doesn't send the message they left and still thinks they're online.

  • Posts: 1,976

    @quezadav Summon the Nyan Cat and say "Bang!"

  • edited August 2013 Posts: 226

    It would be interesting also to know at what time the people would chat, I mean, like a coffee break hour or something like that, hehe: socializing Codea.

  • Posts: 157

    Hmm... do the refresh requests include a user ID?

    You could keep a "last updated" value for your users, and in the list function, silently drop users who haven't refreshed the page for more than 1 minute.

    Either way, I think you're doing a great job. Keep it up. =)

  • Posts: 1,976

    @tomxp411 I could do that, but currently Briarfox is working on CC, and I don't want to bug him.

  • Posts: 2,161

    @SkyTheCoder TeX is a programming language that is used primarily for typesetting documents. It was invented by Don Knuth (who you really ought to read about if you're seriously interested in programming). It is wonderfully crafted for making it easy to type documents (particularly with mathematics) and therefore supremely ill-fitted for anything else. Therefore it would be a particularly impressive feat to program anything "normal" in TeX. Anyone who did something, say like a Mars rover, would be considered both barmy and amazing simultaneously.

    So when anyone goes on about how something should be programmed in one language or another, I tend to drop in "How about TeX?" which soon makes everyone shut up.

  • edited August 2013 Posts: 157

    @SkyTheCoder no problem. It is just something I noticed. =) Actually, if you aren't against sharing the PHP code, I could take a crack at it. I haven't had a chance to exercise my MAMP stack since I got my Mac.

    Or if not, that's no problem. I've certainly got enough to keep me busy... I just bought a book on iOS coding, so I'm going to be having some fun on this holiday weekend.

  • Posts: 2,043

    Nice work with the new scrolling! Although now it lets you pull past the bottom and top

  • Posts: 1,976

    @JakAttak I noticed that and I have no idea why it does that. I didn't change anything there. Anyways, it just snaps back to place, so it's no big deal.

    I like to have my programs do exactly what I want without me having to explain in-depth, and to have it feel natural. Something that was bugging me was scrolling a tiny bit, letting go, and it moving. Now it doesn't. But only when I don't want it to. And I don't have to say anything. It just knows.

  • edited August 2013 Posts: 226

    @Andrew_Stacey, Better: How about Brainf**k? (I'm a fan of esoteric programmig languages, especially FALSE). =:)

  • Posts: 2,043

    @SkyTheCoder, how about showing the time each message was sent next to them. Right now, it's hard to tell if I just missed somebody, or if they left a few hours ago

  • Posts: 2,161

    @quezadav Well, but TeX is a programming language that people do use for specific tasks, and it is well suited to those tasks. Isn't Brain!@#% one of these invented languages purely to prove a point?

    (As a mathematician, I ought to really be saying that everyone should program is Haskell.)

  • edited August 2013 Posts: 226

    Yes, it is a Turing tarpit, made for amusement of hard core programmers :D

  • edited August 2013 Posts: 2,043

    Here's what I think the user list should look like:

    Image and video hosting by TinyPic

    P.S. This is just a few extra lines in the code, as long as you have a table of users

  • Posts: 1,976

    I'll ask Briarfox about player lists with this method later. And I will add a time stamp.

  • Posts: 29

    Whenever I get on no one is on :(

  • I tried to make something similar, but raged and gave up, nice to see someone did it. But i tried it and it said an error

  • Posts: 2,820

    Agree with @Mason.

  • The user and all related content has been deleted.
  • Posts: 1,976

    @NatTheCoder iChat is already an app made by Apple it was basically an old version of iMessages.

    Again, this is from 2013. Please do not bump up old discussions (check the last post date), and ESPECIALLY do not bump them with useless information.

This discussion has been closed.