Bitcoin Forum

Other => Off-topic => Topic started by: Lethn on May 12, 2013, 05:31:33 AM



Title: The Coding Thread
Post by: Lethn on May 12, 2013, 05:31:33 AM
Considering there are clearly tons of programmers/learning programmers here I think we should make a thread where we can talk about different programming languages and help each other out, I'm currently messing around in OpenGL though I suspect if I want to make anything functional like a game I'm going to have to properly get into C++ too, feel free to post code here of stuff you're working on and need help with etc.


Quote


            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glLoadIdentity();
            glPushMatrix();
            glTranslatef(-0.5f, -0.5f, 0.0f);
            glPushMatrix();
            glRotatef (90.0f, -180.0f, 0.0f, 0.0f);
            glPopMatrix();

                                            glBegin(GL_TRIANGLES);




                                            glVertex3f(0.5f, 0.5f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.5f, 0.5f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(0.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);

                                            glVertex3f(0.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.5f, 0.5f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);

                                            glVertex3f(0.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.0f, 1.5f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);



            glEnd();

            glPopMatrix();


I made a pink pentagon, WEEEEEEEEE! :D Can't figure out how to get GLRotatef working though.


Title: Re: The Coding Thread
Post by: Este Nuno on May 12, 2013, 01:28:27 PM
Nothing to add atm, but I support this idea for a thread.


Title: Re: The Coding Thread
Post by: CIYAM on May 12, 2013, 01:34:30 PM
Purely from a C++ coding style perspective I see no reason to be "indenting" the function calls you have (indenting is normally done for code *blocks* that are surrounded by braces or for conditional expressions).

You might consider using an "empty code block" to make it more express the indenting you are after though:

Code:
...
glPopMatrix();
{
   glBegin(GL_TRIANGLES);
   ...
   glEnd();
}



Title: Re: The Coding Thread
Post by: jackjack on May 12, 2013, 01:52:28 PM
I support a coding (sub-)FORUM


Title: Re: The Coding Thread
Post by: BitshireHashaway on May 12, 2013, 07:20:32 PM
I am interested in learning C++ mainly because that seems to be the most widely used language out there. I am already familiar with HTML because I've learned it some in school and have used it in creating my websites, and next year, I will be learning some Java as part of a course and will probably continue to mastery the following year. However, C++ I will need to learn by myself, so do you guys have any recommendations for me learning it by myself. My parents may help me as they both know C++ and multiple other coding languages.


Title: Re: The Coding Thread
Post by: CIYAM on May 13, 2013, 02:09:21 AM
I would recommend reading Scott Meyers and Herb Sutter and keeping your focus on Standard C++ always (i.e. not extensions for specific compilers such as MSVC).

BTW - https://bitcointalk.org/index.php?topic=203104.0.


Title: Re: The Coding Thread
Post by: adamstgBit on May 13, 2013, 02:38:35 AM
i can do the job 2 of 3 ways;

Cheap, Fast, Good

if you want it:
Cheap & Fast,  fine, but it won't be very good.. (Dirty Code! lol )
Good & Cheap, ok, ill do my best!
Good & Fast,    sure, but thats not going to be cheap.  50,000BTC  ;)

 :P


Title: Re: The Coding Thread
Post by: Lethn on May 14, 2013, 06:44:16 PM
Have to admit, I think I'm starting to really enjoy messing around in OpenGL :D I just need to figure out how to make it interactive.

Quote
             glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glLoadIdentity();
            glPushMatrix();
            glTranslatef(-1.0f, -1.0f, 0.0f);
            glPushMatrix();
            glRotatef (90.0f, -180.0f, 0.0f, 0.0f);
            glPopMatrix();

                                            glBegin(GL_TRIANGLES);




                                            glVertex3f(0.5f, 0.5f, 0.0f);   glColor3f(2.0f, 0.5f, -1.0f);
                                            glVertex3f(1.5f, 0.5f, 0.0f);   glColor3f(1.0f, 0.5f, -1.0f);
                                            glVertex3f(0.5f, 1.0f, 0.0f);   glColor3f(6.0f, 0.5f, -1.0f);

                                            glVertex3f(0.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, -1.0f);
                                            glVertex3f(1.5f, 0.5f, 0.0f);   glColor3f(2.0f, 0.5f, 1.0f);
                                            glVertex3f(1.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);

                                            glVertex3f(0.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.5f, 1.0f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);
                                            glVertex3f(1.0f, 1.5f, 0.0f);   glColor3f(1.0f, 0.5f, 1.0f);



            glEnd();

            glPopMatrix();


Coding spam woopeee! :D


Title: Re: The Coding Thread
Post by: raze on May 15, 2013, 03:52:17 AM
Just remember it's not the language that matters (okay, maybe it matters a little), it's the practices and techniques you learn from using that language. If you master the correct techniques, you'll pick up future languages faster, and produce better code and documentation.


Title: Re: The Coding Thread
Post by: Elwar on May 15, 2013, 04:32:05 AM
Have to admit, I think I'm starting to really enjoy messing around in OpenGL :D I just need to figure out how to make it interactive.

I did some coding in OpenGL, it is pretty fun. I had to open up some of my old math books from college that I figured I would never need again.

For interaction, you should first start with using a key listener. Making stuff happen based upon various keyboard keys is fairly easy.


Title: Re: The Coding Thread
Post by: Lethn on May 15, 2013, 09:21:56 AM
I dunno about that, I don't think I want to use anything particularly pre-made I think the only thing I've done that's pre-made so far is use the Codeblocks OpenGL sample to get all the window setup that I need because the tutorials I've looked at are outdated with some of the stuff they have. I did notice some VK commands for all the keyboard stuff in the compiler so I'll have to have a look at the syntax involved with that so I can make stuff move.

Edit: AHA! Nehe seems to be very good with this stuff and it's just what I need, IF commands ftw! :D


Title: Re: The Coding Thread
Post by: Lethn on May 15, 2013, 09:40:05 PM
Hmm, does anyone know of any good examples or tutorials for Codeblocks that show you how to code interaction with the shapes you make?

I may have just found what I needed :D just needed to look for a bit longer.

http://www.codeproject.com/Articles/27219/TetroGL-An-OpenGL-Game-Tutorial-in-C-for-Win32-Pla


Title: Re: The Coding Thread
Post by: Welsh on May 15, 2013, 09:56:41 PM
It would be really great if this got added as a sub-forum. I know it can be related to services etc.
But, this just seems like a great way to break it up from the other things located in other sections, however I don't have anything to add at this moment as i'm mainly a python programmer, and learning java now.


Title: Re: The Coding Thread
Post by: Lethn on May 15, 2013, 09:58:48 PM
Lets spam code all over this thread so the mods know there's demand for a category lolollool :D


Title: Re: The Coding Thread
Post by: Illimensky on May 15, 2013, 10:53:29 PM
Nobody here's programming in LOLcode?  Seriously?  You should all try it.

Wikipedia: http://en.wikipedia.org/wiki/LOLCODE (http://en.wikipedia.org/wiki/LOLCODE)

The Hello World program:

HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE


As you can see, its insane efficiency at any task combined with its extreme brevity makes it a must for any real coding project.


Title: Re: The Coding Thread
Post by: Lethn on May 16, 2013, 03:24:46 PM
Bah, does anyone know some good tutorials that show you how to combine OpenGL and C++ while I'm searching for them myself? The OpenGL tutorials are great and I have an easy time drawing basic stuff on it now but I need to look up how to properly combine everything so I can interact with the shapes I make :D


Title: Re: The Coding Thread
Post by: Lethn on May 16, 2013, 03:34:08 PM
Can't believe I forgot about this tutorial.

http://www.cprogramming.com/tutorial/opengl_first_opengl_program.html


Title: Re: The Coding Thread
Post by: Lethn on May 17, 2013, 01:48:06 AM
Quote
           
            glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
            glTranslatef (-0.2f, 0.0f, 0.0f);
            glRotatef(theta, 0.0f, 1.0f, 0.0f);
            glBegin (GL_QUADS);
  
                              
                              glVertex3f (0.0f, -0.1f, 0.0f);
                              glVertex3f (-0.1f, 0.0f, 0.0f);
                              glVertex3f (0.0f, 0.1f, 0.0f);
                              glVertex3f (0.1f, 0.0f, 0.0f);
            glEnd ();
            glPopMatrix ();
            
            glPushMatrix ();
            glTranslatef (0.1f, 0.0f, 0.0f);
            glRotatef(theta, 0.0f, 1.0f, 0.0f);
            
            glBegin (GL_QUADS);

                              
                              glVertex3f (0.0f, -0.1f, 0.0f);
                              glVertex3f (-0.1f, 0.0f, 0.0f);
                              glVertex3f (0.0f, 0.1f, 0.0f);
                              glVertex3f (0.1f, 0.0f, 0.0f);
                              
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);
        }
    }


Must make it so I can click and drag these spinning squares :D


Title: Re: The Coding Thread
Post by: Lethn on May 17, 2013, 05:00:39 PM
Does anyone know of any up to date syntax for GLFW keyboard and mouse input? Or would you recommend something else? I'm searching around but I think I could use some help on this one.


Title: Re: The Coding Thread
Post by: Welsh on May 17, 2013, 05:50:09 PM
print("We want a sub-forum")
user_input = input("What do you say staff?")


Title: Re: The Coding Thread
Post by: Lethn on May 17, 2013, 10:33:03 PM
LOL After all that raging I found that the problem was that I had downloaded 64 bit GLFW binaries instead of 32 bit, I feel like a noob even after all that coding :D

Now I can begin work on my keyboard and mouse interaction :D


Title: Re: The Coding Thread
Post by: Lethn on May 18, 2013, 10:28:41 AM
I found a very nice tutorial on naming objects in OpenGL so you can start interacting with the OpenGL graphics you make, wish all tutorials were as detailed as this.

http://www.lighthouse3d.com/opengl/picking/


Title: Re: The Coding Thread
Post by: Lethn on May 18, 2013, 07:19:58 PM
Quote

#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL/SDL.h>

int main ( int argc, char*, args[] )
{


SDL_Surface* test = NULL;
SDL Init ( SDL_INIT_EVERYTHING );
screen = SDL_SetVideoMode ( 640, 480, 32, SDL_SWSURFACE );
test = SDL_LoadBMP ("Test.bmp");
SDL_BlitSurface (test, NULL, screen, NULL)
SDL_Flip ( screen );
SDL_Delay ( 2000 );
SDL_FreeSurface( test );
SDL_Quit();

return 0;

 }


From various posts and word on the internet I've found that SDL is apparently the library to use, I can see it combines it's code really well and you don't have to worry about downloading extensions for keyboard input like with GLFW so that's already a plus but, I've come across a problem. I'm following the tutorials here: http://lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/index.php but the code won't compile! It's strange because the commands were registered by Codeblocks ( IDE I'm using ) and when I started up the SDL sample the code works absolutely fine.

Anyone got any advice? I'm going to get on this properly because I think SDL is a pretty nice library but I suspect I'll have to do some digging around like when I was just compiling basic OpenGL, I'm wondering if the code for this tutorial is out of date because the version of the library it said to download was much earlier, it's happened before with previous coding.

Quote

error: 'args' has not been declared
In function 'int SDL_main(int, char*, int*)'
error: 'SDL' was not declared in this scope
error: expected ';' before 'Init'
error: 'screen' was not declared in this scope

||=== Build finished: 4 errors, 0 warnings (0 minutes, 0 seconds) ===|


I think I'm just going to have to do what I did before and work with the sample and learn the code that way so Codeblocks doesn't break.


Title: Re: The Coding Thread
Post by: Foxpup on May 19, 2013, 05:24:12 AM
error: 'args' has not been declared
There must be no comma between char* and args[], as they're part of the same declaration (that you have a array of pointers called "args" of type "char"). With the comma, it thinks you have an anonymous pointer of type "char", and something completely separate called "args", though it doesn't know what this thing called "args" is supposed to be, hence the error.

error: 'SDL' was not declared in this scope
error: expected ';' before 'Init'
You need an underscore between SDL and Init, with no spaces. "SDL_Init" is one function. With a space, it thinks they are two separate functions called "SDL" and "Init" (which don't even exist, causing the first error), and expects a semicolon between them (you always need a semicolon between statements), which is the second error.

error: 'screen' was not declared in this scope
You forgot to declare it (or you declared it in the wrong place). You should have "SDL_Surface* screen = NULL;" immediately after (or immediately before) "SDL_Surface* test = NULL;".


Title: Re: The Coding Thread
Post by: Lethn on May 19, 2013, 08:49:22 AM
wow thanks a lot Foxpup, that's really interesting, he didn't seem to mention any of this in the troubleshooting for it and so on >_< and this is supposed to be a beginners tutorial lol! :P I copied it exactly just to see whether I was forgetting or something, but it looks like there are bits wrong with his code, I'll double check again and it looks like there are.

Do you know of any up to date tutorials that won't bugger up on the latest version of SDL? I particularly like this library because it means I have to go and make some art assets right away which is nice, anime characters time woot! :D


Title: Re: The Coding Thread
Post by: Foxpup on May 19, 2013, 09:39:47 AM
wow thanks a lot Foxpup, that's really interesting, he didn't seem to mention any of this in the troubleshooting for it and so on >_< and this is supposed to be a beginners tutorial lol! :P I copied it exactly just to see whether I was forgetting or something, looks like there are bits wrong with his code but I'll double check again and it looks like there are.
It's for beginning game programmers, ie, programmers who are experienced at writing other applications and wish to move on to the more specialised field of game programming. This tutorial assumes basic knowledge of C++. If you have never done much programming in C++ before, you should probably start with the basics before continuing.

Quote from: Lazy Foo' Productions
Q: How much C++ do I have know to start game programming?
A: For my SDL tutorials, you must have a decent handle on the following concepts:
Operators (+, -, *, /, ++, --, +=, -=, etc)
Controls (if, else, switch)
Loops (while, for)
Functions
Structs
Arrays
References
Pointers
Classes and Objects
How to use a template.
Bitwise and/or.

The articles might require you to know more, but they'll mention it beforehand. Of course the more C++ you know, the better. To make anything complex you'll need to know inheritance, polymorphism, templates, and STL. Eventually you'll need to know exceptions, operator overloading and the whole language.

Make sure you know these concepts well. Don't just skim over them in a C++ reference book. It doesn't matter how much Java/Python/C#/Visual Basic/ASM/HTML/whatever you know. You have to know C++ to be able to learn from the tutorials/articles.

Do you know of any up to date tutorials that won't bugger up on the latest version of SDL? I particularly like this library because it means I have to go and make some art assets right away which is nice, anime characters time woot! :D
I'm pretty sure this tutorial is up to date with SDL 1.2 (the latest stable version). SDL 2 has a lot of changes, but I think it's mostly the addition of OpenGL and haptic support, I'm not sure how much (if any) of the 2D graphics stuff is being changed. Anyway, SDL 2 hasn't been officially released yet, so it's a moot point.


Title: Re: The Coding Thread
Post by: Lethn on May 19, 2013, 09:41:53 AM
Alright, thanks for the help, I'll steamroll through this like I've been doing with OpenGL :P just need to put the time in.


Title: Re: The Coding Thread
Post by: Lethn on May 19, 2013, 09:53:37 AM
Finally! Got it sorted! Image came out a bit weird but I think that's more to do with the resolution I used, thanks for the help again, here's the now updated and working code.

Quote

#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL/SDL.h>

int main( int argc, char* args[] )

{

SDL_Init; ( SDL_INIT_EVERYTHING );
SDL_Surface* screen = NULL;
SDL_Surface* test = NULL;

screen = SDL_SetVideoMode( 500, 500, 32, SDL_SWSURFACE );


test = SDL_LoadBMP( "test.bmp" );

SDL_BlitSurface( test, NULL, screen, NULL );

SDL_Flip( screen );
SDL_Delay( 2000 );

SDL_FreeSurface( test );

SDL_Quit();

   return 0;
}


For future reference I think the biggest problem was  SDL_Init( SDL_INIT_EVERYTHING ); because on the tutorial he put that after the SDL_surface commands rather than before.


Title: Re: The Coding Thread
Post by: Lethn on May 27, 2013, 09:20:35 AM
I've been through some changes, because SDL just seems to be filled with outdated tutorials and such, I really can't be bothered combing through the code and fixing problem after problem that's completely unncessary. So I went and looked at SFML which seems to be much better supported and low and behold the commands provided in most tutorials work properly, I've been able to even get some basic interaction going with it. I'll have to have a think now on what I'm going to make and I have a basic platformer in mind, next up to learn will be sprites and collision I guess.

Quote


#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Lethn 2D Engine");
    sf::CircleShape circle1 ( 20 );
    circle1.setPosition( 30, 30 );
    sf::CircleShape circle2 ( 20);
    circle1.setPosition( 200, 260 );
    circle2.setPosition( 600, 260 );
    circle1.setFillColor( sf::Color::Red );
    circle1.setOutlineColor( sf::Color::Magenta );
    circle1.setOutlineThickness( 3 );
    circle2.setFillColor( sf::Color::Blue );
    circle2.setOutlineColor( sf::Color::Cyan );
    circle2.setOutlineThickness( 3 );

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))


            if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: W  ) )


            {
                circle1.move ( 0, -5 );
            }

            else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: A  ) )

            {
                circle1.move ( -5, 0 );
            }

            else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: D  ) )

            {
                circle1.move ( 5, 0 );
            }

            else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: S  ) )

            {
                circle1.move ( 0, 5 );
            }
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }


        window.clear();
        window.draw(circle1);
        window.draw(circle2);
        window.display();
    }

    return 0;
}




Title: Re: The Coding Thread
Post by: jackjack on May 27, 2013, 11:54:34 AM
Same happened for me
I never managed to get SDL working even for small tasks whereas SFML is a pleasure to use


Title: Re: The Coding Thread
Post by: Lethn on June 01, 2013, 12:03:00 PM
I'm working through some simple point and click mouse events and stuff but does anyone have any tips for how I could get the move command to work or if that's what is necessary at all? What I'm trying to do is to get my sprite to move to the position of where I left click like an RTS or point and click RPG, I haven't had problems with keyboard commands so far but this is causing problems for me.

Quote


    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

    if ( event.type == sf::Event::MouseButtonPressed )

    {

    if ( event.mouseButton.button == sf::Mouse::Left )

        {

            sf::Event.mouseButton.x << std::end1;
            sf::Event.mouseButton.y << std::end1;
            spriteplayerstanding1.move ( MouseButtonPressed );
        }

        {
            if (event.type == sf::Event::Closed)
                window.close();
            }



Title: Re: The Coding Thread
Post by: Lethn on June 02, 2013, 04:31:50 PM
I found out in an old post finally how to do it

Correct snytax is:

Quote

    sf::Event event;
    while (window.pollEvent(event))

        if (sf::Mouse::isButtonPressed ( sf::Mouse::Left ) )


        {
            spritename1.move ( sf::Mouse::getPosition( window ).x, sf::Mouse::getPosition( window ).y );
        }

        {
            if (event.type == sf::Event::Closed)
                window.close();
            }



I was using the command separately and not in the right order, my only problem now is the warping.


Title: Re: The Coding Thread
Post by: Lethn on June 03, 2013, 08:06:09 AM
Okay I have partially got things working, my only problem now is that I'm only able to specifically drag my sprite to the x and y coordinates of the cursor rather than all around.

Quote

    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

        if (sf::Mouse::isButtonPressed ( sf::Mouse::Left ) )


        {
            spritename1.move ( sf::Mouse::getPosition( window ).x >50, sf::Mouse::getPosition( window ).y >50 );
        }



Title: Re: The Coding Thread
Post by: r3wt on June 03, 2013, 08:16:42 AM
any php'ers in the house? i'm making a mess of this form

this form does everything i basically need it to do, but i'm having problems adding anymore logic to it. i need for it to check the
Code:
$email
and
Code:
$url
for common elements of emails and urls for example "@" and "http://" .also wierdly it displays the
Code:
$accept
div when i load the page, when it should display either the
Code:
$error
or nothing. i wrote this tonight but i've been having the rewrititis for the last couple of hours. decided it might be wise for me to ask an experience php programmer(s) for advice.


Code:
session_start();  

$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$title = $_POST['title'];
$message = $_POST['message'];
$code- $_POST['code'];

$data = "$name | $email
         $url | $title  
-
$message


";
  
 

if(strtolower($_POST['code']) == $_SESSION['rand_code']) {
          
        $accept = "Your Entry is being processed";

        $fh = fopen("redacted.txt", "a");
        //write and close
        fwrite($fh, $data);  

          
        } else {  
          
        $error = "All Fields Are Required.";  
  
      
    
      
    }  

The original version was more complex with multiple error messages. the one shown and one for the captcha. couldn't get it to work though.


Title: Re: The Coding Thread
Post by: jackjack on June 03, 2013, 08:22:36 AM
  • email+url: look at regex
  • you don't fclose
  • I don't see any echo so how can you display error or accept?


Title: Re: The Coding Thread
Post by: Lethn on June 03, 2013, 08:27:04 AM
yey! more people posting their code other than me! :D


Title: Re: The Coding Thread
Post by: Mike Christ on June 03, 2013, 08:29:50 AM
Code:
print "Hello, world!"

Phew, I need to take a break.


Title: Re: The Coding Thread
Post by: r3wt on June 03, 2013, 08:30:23 AM
  • email+url: look at regex
regex? what is that exactly? i'm afraid i don't know much about it. i'm self taught so my knowledge is *extremely limited*

  • you don't fclose

the script works fine without it.. is it really necessary?

  • I don't see any echo so how can you display error or accept?

i call the echo down below in the form:

Code:
<div id="result">
<? if(!empty($error)) echo '<div class="error"><img src="fail.png" /> '.$error.'</div>'; ?>  
<? if(!empty($accept)) echo '<div class="accept"> <img src="ok.png" />'.$accept.'</div>'; ?>
</div>



Title: Re: The Coding Thread
Post by: jackjack on June 03, 2013, 08:39:56 AM
  • email+url: look at regex
regex? what is that exactly? i'm afraid i don't know much about it. i'm self taught so my knowledge is *extremely limited*

  • you don't fclose

the script works fine without it.. is it really necessary?

  • I don't see any echo so how can you display error or accept?

i call the echo down below in the form:

Code:
<div id="result">
<? if(!empty($error)) echo '<div class="error"><img src="fail.png" /> '.$error.'</div>'; ?> 
<? if(!empty($accept)) echo '<div class="accept"> <img src="ok.png" />'.$accept.'</div>'; ?>
</div>


Regex are something specifically designed to validate patterns. Warning: that's pretty annoying.
Sure it works without fclose but you're using RAM for nothing and you're locking the file for every other process until the PHP script ends. Oh, and PHP gurus will kill you.
Looks ok, so I'd put many echo's in your big 'if' to see what happens: check all your variables at many times.


Title: Re: The Coding Thread
Post by: r3wt on June 03, 2013, 08:55:47 AM
  • email+url: look at regex
regex? what is that exactly? i'm afraid i don't know much about it. i'm self taught so my knowledge is *extremely limited*

  • you don't fclose

the script works fine without it.. is it really necessary?

  • I don't see any echo so how can you display error or accept?

i call the echo down below in the form:

Code:
<div id="result">
<? if(!empty($error)) echo '<div class="error"><img src="fail.png" /> '.$error.'</div>'; ?>  
<? if(!empty($accept)) echo '<div class="accept"> <img src="ok.png" />'.$accept.'</div>'; ?>
</div>


Regex are something specifically designed to validate patterns. Warning: that's pretty annoying.
Sure it works without fclose but you're using RAM for nothing and you're locking the file for every other process until the PHP script ends. Oh, and PHP gurus will kill you.
Looks ok, so I'd put many echo's in your big 'if' to see what happens: check all your variables at many times.
ahh, so thats why i couldn't get the form to save when i was accessing the file from the "admin console i built" to edit/read it. i know that flat databases are out of style but i find it useful for my manual review process. i don't wanna give people access to the database directly. trying to prevent spam sites and links.
so what would the fclose command be for this particular setup? i tried it several diffent was and keep getting the error message: php expects parameter 1 to be resource, boolean given in "...../submit.php" on line ...


Title: Re: The Coding Thread
Post by: Lethn on June 03, 2013, 08:56:35 AM
Code:
print "Hello, world!"

Phew, I need to take a break.

Pussy! :P


Title: Re: The Coding Thread
Post by: Mike Christ on June 03, 2013, 09:02:12 AM
Pussy! :P

Okay okay.  I'll keep trying.

Code:
def conjunctionJunction():
    print "What's your function?"

conjunctionJunction()


Title: Re: The Coding Thread
Post by: r3wt on June 03, 2013, 09:19:21 AM
Pussy! :P

Okay okay.  I'll keep trying.

Code:
def conjunctionJunction():
    print "What's your function?"

conjunctionJunction()

uAWR s0 l33t


Title: Re: The Coding Thread
Post by: Lethn on June 03, 2013, 10:37:19 AM
Quote


#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "test");

sf::CircleShape shape ( 50 );
shape.setFillColor( sf::Color::White );

    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

        {
           if (sf::Mouse::isButtonPressed ( sf::Mouse::Left ) )

           shape.setPosition ( sf::Mouse::getPosition( window ).x , sf::Mouse::getPosition( window ).y  );

        }



{
 if (event.type == sf::Event::Closed)
 window.close();
}

        window.clear();
        window.draw ( shape );
        window.display();

    }

    return 0;


I managed to partially fix my code yet again to make it almost functional, turns out, keeping mouse events outside of the brackets where you're having your objects interact with the mouse/keyboard royally fucks things up if you're not careful, now I just need to figure out why my shape is terrified of my mouse cursor and get this code working with the move command.

Oh and never forget, x and y always, never y and x :D


Title: Re: The Coding Thread
Post by: r3wt on June 03, 2013, 10:50:43 AM
Quote


#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "test");

sf::CircleShape shape ( 50 );
shape.setFillColor( sf::Color::White );

    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

        {
           if (sf::Mouse::isButtonPressed ( sf::Mouse::Left ) )

           shape.setPosition ( sf::Mouse::getPosition( window ).x , sf::Mouse::getPosition( window ).y  );

        }



{
 if (event.type == sf::Event::Closed)
 window.close();
}

        window.clear();
        window.draw ( shape );
        window.display();

    }

    return 0;


I managed to partially fix my code yet again to make it almost functional, turns out, keeping mouse events outside of the brackets where you're having your objects interact with the mouse/keyboard royally fucks things up if you're not careful, now I just need to figure out why my shape is terrified of my mouse cursor and get this code working with the move command.

Oh and never forget, x and y always, never y and x :D

Hell yeah bro! i fixed my php script to. turned out i did need to fclose the file like jackjack said. for some strange reason notepad++ doesn't highlight the syntax of fclose so i thought i was doing something wrong. showing zero errors on E_ALL i can sleep soundly now.


Title: Re: The Coding Thread
Post by: Mike Christ on June 04, 2013, 04:24:22 AM
uAWR s0 l33t

People, please, hold your applause.

Code:
def myNewFunction(x):
    if x > 1:
        return x + 1
    else:
        return 0

print myNewFunction(int(raw_input()))

It took me three weeks to figure out how many parenthesis should go on the end of the last statement, but due to my unwavering perseverance, I've made a program that...probably cures computer cancer or something.  But anyway, I think I'm ready to make the next World of Warcraft clone.


Title: Re: The Coding Thread
Post by: Lethn on June 11, 2013, 12:07:20 PM
You guys who are into game programming may like this, did some digging around and found this website http://code.google.com/p/gqe/, a lot of the sites are completely outdated but it looks this one at least has some 2.0 code, I downloaded pong to get me going! :)


Title: Re: The Coding Thread
Post by: r3wt on June 12, 2013, 01:25:15 PM
You guys who are into game programming may like this, did some digging around and found this website http://code.google.com/p/gqe/, a lot of the sites are completely outdated but it looks this one at least has some 2.0 code, I downloaded pong to get me going! :)

someone should make a bit arcade. instead of depositing 50 cents per play, you deposit .005 bitcoins or something


Title: Re: The Coding Thread
Post by: Lethn on June 12, 2013, 02:28:57 PM
lolz well I'll be selling my games for Bitcoin but I don't really approve of arcades, it's basically like purchasing a game with a hard coded time limit and that sucks :(

Quote


    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

if ( event.type == sf::Event::MouseMoved );

{
    spritebutton.delete ( MouseMoved.x, MouseMoved.y );
}


{
 if (event.type == sf::Event::Closed)
 window.close();
}


I WILL CODE A WORKING BUTTON OR DIE TRYING!


Title: Re: The Coding Thread
Post by: Lethn on November 27, 2013, 07:53:40 AM
I'm bumping the coding thread :P I want to post up some more code here soon :D


Title: Re: The Coding Thread
Post by: r3wt on November 27, 2013, 09:31:35 AM
I'm bumping the coding thread :P I want to post up some more code here soon :D

can you debug an sql query? i can't get my form to work for some odd strange reason.

Code:
<b>Ban A user</b>
<form action="" method="POST">
<input type="hidden" name="banby" value="<?php  echo $account?>" />
<input type="text" name="to_ban" class="shadowfield" />
<input type="submit" value="ban" class="blues" />
</form>
<?php

if (isset($_POST["to_ban"]))
{
$banby mysql_real_escape_string(strip_tags($_POST["banby"]));
$to_ban mysql_real_escape_string(strip_tags($_POST["to_ban"]));
$sqly mysql_query("UPDATE userCake_Users SET `Banned`='1' WHERE `Username`='$to_ban'");
$sqlz mysql_query("UPDATE userCake_Users SET `BannedBy`='$banby' WHERE `Username`='$to_ban'");
}




Title: Re: The Coding Thread
Post by: Lethn on November 27, 2013, 09:37:58 AM
Fuck no lol :D but if we keep bumping this thread maybe someone else will take a look, I'm learning C++ and SFML currently.


Title: Re: The Coding Thread
Post by: r3wt on December 08, 2013, 08:58:10 AM
Fuck no lol :D but if we keep bumping this thread maybe someone else will take a look, I'm learning C++ and SFML currently.

SFML? SAD FUCK MY LIFE LANGUAGE ? lol