This thread is intended for folks who don't know how to program but really want to learn.
It comes as follow up to my other thread:
http://warlight.net/Forum/Thread?ThreadID=5471
Some folks have been asking me how they can get started coding in general and help out with CLOT development in particular. So i decided to create this thread about it to serve as a guide and answer any questions.
Feel free to ask any seemingly stupid questions, no one is born knowing everything and it's likely answering your question publically will help others reading this thread later on.
A little about me: i'm MSc informatics engineer, i'm not a genius coder, no one ever is really. Been coding since i was 5. After i got my masters i did some academic research work, got tired of it so i worked 9 to 19 on a company, got tired of it. And nowdays i'm doing freelance and working on my own projects.
On about CLOT: i didn't like Fizzer's platform which unknownsoldier had been working on, my main points against it was that i am rusty in python, never touched django and dislike google's app engine limitations. That doesn't mean you can't do great things with this combo. I was just lazy to learn new frameworks at this point and prefered to try my own version more objective oriented. Which turned out to be this:
http://warlight.net/Forum/Thread?ThreadID=5595
So if you want to learn how to program to use CLOT you have two choices at this point: learn python + django + app engine or learn php+javascript on this thread.
I'm assuming you know absolutely nothing about programming. If you do my explanations might sound somewhat simplistic or not really following the best practices. That's fine. Feel free to comment anyways or fork my code on github and fix it up.
I'm a big supporter of KISS guidelines (keep it simple stupid) and making it work first and turning it into a framework later. That means i code to achieve something on a working state which id minimally documented to be useful for later repurposing, if when it might be needed.
Lesson number 1: Code fright
If you're ever going to learn how to code you must not be afraid of getting your hands dirty.
Reading a book or some tutorials labelled 'for dummies' is quite useful to learn the basics but you are only going to make real progress when you run into problems and interiorize problem solving by actually writing, running and rewriting code.
That means several things:
1) get used to googling for your own answers before asking questions
2) get used to search documentation fast
3) get used to asking yourself why something doesn't work
4) get used to testing your hypotheses
If something doesn't work you need to ask yourself: Why? And if you don't know the answer immediatly you need to figure out a set of smaller questions on why it might not be working and test those hypotheses. Don't sit around and wait for the answer, think of the most likely reason, test it and repeat the process. For example if a lightbulb isn't lightning when you flick the switch it could be due to several things: the filament might have wore itself up, the lamp could be disconnect from the electricity, the electricity socket may be broken, or maybe the whole electricity board is down. It doesn't so much matter as to why that certain thing might have happened that caused the problem, your main concearn should be discovering why it doesn't work now. Once you figure that part out then you can think on how to prevent it from happening again. In this example you can check if other appliances have electricity, if other lightbulbs work on this lamp, if the lamp works in another electricity socket, etc. And then eventually you will realize it's the lamp itself that is broken and conclude it might be very likely that a couple days ago your visiting cousin broke the lamp and placed it back without telling anyone.
This is the most critical skill for becoming a decent programmer. There are other things important, but this one is critical: if you don't have initiative on critical thinking towards problem solving you will just be staring at a problem and give up.
Luckily for you, if you're reading this it means you probably play warlight somewhat regularly, so you clearly already know the basics of dealing with frustration, critical thinking and problem solving. Hooray for that! So just keep in your mind that when coding you need to be doing that constantly for every step you take.
Lesson number 2: Getting your environment setup. \o/
PHP is a server side scripting language. It's embbeded as a module into the Apache server.
Quickly explain server-client logic now:
You have two programs who want to talk with each other, the server is the one sitting sad and alone in a corner waiting for a client to poke him with a request.
In our case the server will be a service running on a machine (the apache thing i was mentioning before) and the client will be your web-browser. When you enter an address on your browser it looks up the server with that name and asks him for it's contents. In warlight's case it gives you back this amazing game.
If you write
http://localhost in the browser window it will try to communicate with your own machine. So if you have a web server running (like apache) you will get a page back. And if you don't it will just tell you the page doesn't exist!
So what you need is to install Apache with PHP support. If you're on mac it comes installed by default, you just need to enable it on the System Preferences / Sharing options. If you're on windows you need to install a package like WAMP:
http://www.wampserver.com/en/
You can find some tutorials, tests and troubleshooting pages on getting server with php working on the internets.
So homework #1: get that server installed!
Once you do you'll have a folder somewhere on your harddrive called /www/ or /Sites/ and if your webserver service is running and your firewall isn't blocking anything you can type on your browser for your localhost and access the pages listed there.
If you now write a helloword.php textfile with
<?php echo 'Hello World!'; ?>
And place it on the webserver folder, you should be able to call
http://localhost/helloworld.php and get your message served in the browser
Next lesson: variables and loops